From 40c84f86e9d7326bb0020c9210e0689179b1102c Mon Sep 17 00:00:00 2001
From: Masaya Tojo <masaya@tojo.tokyo>
Date: Sun, 12 Mar 2023 16:45:59 +0900
Subject: Add function to add new item.

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

(limited to 'verify/insert_item.sql')

diff --git a/verify/insert_item.sql b/verify/insert_item.sql
new file mode 100644
index 0000000..f1ce212
--- /dev/null
+++ b/verify/insert_item.sql
@@ -0,0 +1,31 @@
+-- Verify kakeibo:insert_item on pg
+
+BEGIN;
+
+SELECT has_function_privilege('kakeibo.insert_item(INTEGER, TEXT, TEXT, INTEGER, TEXT)', 'EXECUTE');
+
+SET search_path = kakeibo;
+
+DO $$
+  DECLARE
+    v_transaction_id INTEGER;
+    v_item_id INTEGER;
+  BEGIN
+    SELECT insert_transaction(0, '2023-03-15', 'テスト') INTO v_transaction_id;
+    SELECT insert_item(v_transaction_id, 'カテ', 'サブカテ', 298, 'メモ') INTO v_item_id;
+
+    PERFORM *
+      FROM items
+      WHERE id = v_item_id
+      AND transaction_id = v_transaction_id
+      AND category = 'カテ'
+      AND subcategory = 'サブカテ'
+      AND amount = 298
+      AND note = 'メモ';
+    IF NOT FOUND THEN
+      RAISE EXCEPTION 'Inserted data is not found.';
+    END IF;
+  END
+$$;
+
+ROLLBACK;
-- 
cgit v1.2.3

