سامانه صدور فاکتور و حسابداری
test(db): reject null source type and missing sale kind
davoodmehraban89 committed
Nov 17, 2026 at 21:40 UTC
146f20a77404b3ca5881a8dc3aa15c5e1e7dd027
1 file changed
+19
-1
supabase/tests/wp1_phase1a_stage1_sale_purchase_negatives.sql
+19
-1
@@ -54,6 +54,10 @@ AND m.organization_id=current_setting('finora_test.org_a')::uuid AND r.role_key=
54
INSERT INTO public.records(organization_id,owner_id,collection,id,data)
55
VALUES(current_setting('finora_test.org_a')::uuid,'cccc3333-3333-4333-8333-333333333333',
56
'invoices','SOURCE_C_1','{"companyId":"COMP_STAGE_1","kind":"formal","date":"1405/07/24","paymentMethod":"cash","vatMode":"none","vatType":"percent","vatRate":0,"items":[{"qty":1,"price":100,"lineTotal":100}],"subtotal":100,"discount":0,"discountType":"fixed","discountInput":0,"vat":0,"grandTotal":100,"accountingVersion":1,"accountingPostingPending":true,"accountingPostingPendingAt":"2026-11-17T10:00:00Z"}'::jsonb);
57
+-- A missing source kind must not pass SQL three-valued NOT IN checks.
58
+INSERT INTO public.records(organization_id,owner_id,collection,id,data)
59
+VALUES(current_setting('finora_test.org_a')::uuid,'cccc3333-3333-4333-8333-333333333333',
60
+'invoices','SOURCE_C_NO_KIND','{"companyId":"COMP_STAGE_1","date":"1405/07/24","paymentMethod":"cash","items":[{"qty":1,"price":100,"lineTotal":100}],"grandTotal":100,"accountingVersion":1}'::jsonb);
61
-- A pro-forma document must never post as a sale.
62
INSERT INTO public.records(organization_id,owner_id,collection,id,data)
63
VALUES(current_setting('finora_test.org_a')::uuid,
@@ -128,6 +132,20 @@ DECLARE org uuid:=current_setting('finora_test.org_a')::uuid;
132
hdr_p jsonb:='{"companyId":"COMP_STAGE_1","fiscalYearId":"FY_STAGE_1","date":"1405/07/24","voucherType":"purchase","sourceType":"purchase","sourceId":"PUR_NEG_1","sourceVersion":"1"}';
133
r jsonb;v bigint;
134
BEGIN
135
+ BEGIN
136
+ PERFORM public.finora_journal_autopost(org,'BAD_NULL_SOURCE_TYPE','purchases','PUR_NEG_1',
137
+ jsonb_set(hdr_p,'{sourceType}','null'::jsonb),'[]'::jsonb);
138
+ RAISE EXCEPTION 'FINORA_NULL_SOURCE_TYPE_ACCEPTED';
139
+ EXCEPTION WHEN check_violation THEN
140
+ IF SQLERRM NOT LIKE '%FINORA_AUTOPOST_CONTRACT_UNSUPPORTED%' THEN RAISE;END IF;
141
+ END;
142
+ BEGIN
143
+ PERFORM public.finora_journal_autopost(org,'BAD_NULL_SALE_KIND','invoices','SOURCE_C_NO_KIND',
144
+ jsonb_set(hdr_s,'{sourceId}','"SOURCE_C_NO_KIND"'),'[]'::jsonb);
145
+ RAISE EXCEPTION 'FINORA_NULL_SALE_KIND_ACCEPTED';
146
+ EXCEPTION WHEN check_violation THEN
147
+ IF SQLERRM NOT LIKE '%FINORA_SOURCE_TYPE_OR_VERSION_MISMATCH%' THEN RAISE;END IF;
148
+ END;
149
BEGIN
150
PERFORM public.finora_journal_autopost(org,'BAD_SALE_DATE','invoices','SOURCE_C_1',
151
jsonb_set(hdr_s,'{date}','"1405/08/01"'),'[]'::jsonb);
@@ -198,7 +216,7 @@ BEGIN
216
RAISE EXCEPTION 'FINORA_REVERSED_SOURCE_REPLAY_STATUS_NOT_RECONCILED';END IF;
217
IF EXISTS(SELECT 1 FROM public.records WHERE organization_id=org
218
AND collection='journalVouchers' AND id IN('BAD_SALE_ACCOUNTS','BAD_PURCHASE_ACCOUNTS',
201
- 'UNSUPPORTED_KIND','WRONG_TENANT_SOURCE','BAD_SALE_DATE','BAD_SALE_VOUCHER_TYPE','S_POST_AGAIN')) THEN
219
+ 'UNSUPPORTED_KIND','WRONG_TENANT_SOURCE','BAD_NULL_SOURCE_TYPE','BAD_NULL_SALE_KIND','BAD_SALE_DATE','BAD_SALE_VOUCHER_TYPE','S_POST_AGAIN')) THEN
220
RAISE EXCEPTION 'FINORA_NEGATIVE_OR_RETRY_LEFT_VOUCHER';END IF;
221
RAISE NOTICE 'FINORA_SALE_PURCHASE_NEGATIVES_AND_REVERSED_IDEMPOTENCY_PASS';
222
END $t$;