From 1a838c115140bdf0f35054351153fb21f2a228da Mon Sep 17 00:00:00 2001
From: Masaya Tojo <masaya@tojo.tokyo>
Date: Sun, 12 Mar 2023 16:23:41 +0900
Subject: Add function to create new transaction.

---
 verify/insert_transaction.sql | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 verify/insert_transaction.sql

(limited to 'verify/insert_transaction.sql')

diff --git a/verify/insert_transaction.sql b/verify/insert_transaction.sql
new file mode 100644
index 0000000..7f6893c
--- /dev/null
+++ b/verify/insert_transaction.sql
@@ -0,0 +1,26 @@
+-- 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;
-- 
cgit v1.2.3

