-- Verify kakeibo:insert_transaction on pg

BEGIN;

SELECT has_function_privilege('kakeibo.insert_transaction(INTEGER, DATE, TEXT)', 'EXECUTE');

SET search_path = kakeibo;

DO $$
  DECLARE
    v_id INTEGER;
  BEGIN
    SELECT insert_transaction(0, '2023-03-15', 'テスト') INTO v_id;
    PERFORM *
      FROM transactions
      WHERE id = v_id
      AND type_code = 0
      AND date = '2023-03-15'
      AND note = 'テスト';
    IF NOT FOUND THEN
      RAISE EXCEPTION 'Inserted data is not found.';
    END IF;
  END
$$;

ROLLBACK;
