سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 09:15 UTC
test(wp4): seed Auth-owned company/fiscal/accounts and fix SQL block delimiter
davoodmehraban89 committed
Nov 23, 2026 at 22:53 UTC
3855eb7b3cabd961c174fd16e86b12a5cbdfce2d
1 file changed
+21
-1
supabase/tests/wp4_journal_document_lifecycle.sql
+21
-1
@@ -8,7 +8,27 @@ ON CONFLICT (id) DO NOTHING;
8
SELECT set_config('request.jwt.claim.sub','b9000000-0000-4000-8000-000000000001',true);
9
SELECT set_config('request.jwt.claim.role','authenticated',true);
10
11
-DO $$
11
+-- Disposable fixture only: the Auth signup trigger creates owner/organization,
12
+-- license and member records, but does not create a company, fiscal year or
13
+-- posting accounts. Seed the minimum legal draft context in this transaction.
14
+DO $fixture$
15
+DECLARE v_org uuid;
16
+BEGIN
17
+ SELECT id INTO v_org FROM public.organizations
18
+ WHERE owner_user_id='b9000000-0000-4000-8000-000000000001' LIMIT 1;
19
+ IF v_org IS NULL THEN RAISE EXCEPTION 'WP4_ORG_NOT_BOOTSTRAPPED'; END IF;
20
+ INSERT INTO public.records(organization_id,owner_id,collection,id,data) VALUES
21
+ (v_org,'b9000000-0000-4000-8000-000000000001','companies','WP4_COMPANY',
22
+ '{"name":"WP4 local fixture company"}'::jsonb),
23
+ (v_org,'b9000000-0000-4000-8000-000000000001','fiscalYears','WP4_FY',
24
+ '{"companyId":"WP4_COMPANY","startDate":"1405/01/01","endDate":"1405/12/29","status":"open"}'::jsonb),
25
+ (v_org,'b9000000-0000-4000-8000-000000000001','accounts','WP4_ACCOUNT_DEBIT',
26
+ '{"companyId":"WP4_COMPANY","code":"WP4D","name":"Debit fixture","postingAllowed":true,"active":true}'::jsonb),
27
+ (v_org,'b9000000-0000-4000-8000-000000000001','accounts','WP4_ACCOUNT_CREDIT',
28
+ '{"companyId":"WP4_COMPANY","code":"WP4C","name":"Credit fixture","postingAllowed":true,"active":true}'::jsonb);
29
+END $fixture$;
30
+
31
+DO $
32
DECLARE
33
org uuid;
34
company text;