سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 00:30 UTC
test(db): reject malformed source dates in auto-post
davoodmehraban89 committed
Nov 17, 2026 at 21:41 UTC
f0a343dcfa6c01d2e266d48767f896a16ceb0a7d
1 file changed
+12
-1
supabase/tests/wp1_phase1a_stage1_sale_purchase_negatives.sql
+12
-1
@@ -58,6 +58,10 @@ VALUES(current_setting('finora_test.org_a')::uuid,'cccc3333-3333-4333-8333-33333
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
+-- Malformed dates are not accepted as an accounting source date.
62
+INSERT INTO public.records(organization_id,owner_id,collection,id,data)
63
+VALUES(current_setting('finora_test.org_a')::uuid,'cccc3333-3333-4333-8333-333333333333',
64
+'invoices','SOURCE_C_BAD_DATE','{"companyId":"COMP_STAGE_1","kind":"formal","date":"1405/13/40","paymentMethod":"cash","items":[{"qty":1,"price":100,"lineTotal":100}],"grandTotal":100,"accountingVersion":1}'::jsonb);
65
-- A pro-forma document must never post as a sale.
66
INSERT INTO public.records(organization_id,owner_id,collection,id,data)
67
VALUES(current_setting('finora_test.org_a')::uuid,
@@ -146,6 +150,13 @@ BEGIN
150
EXCEPTION WHEN check_violation THEN
151
IF SQLERRM NOT LIKE '%FINORA_SOURCE_TYPE_OR_VERSION_MISMATCH%' THEN RAISE;END IF;
152
END;
153
+ BEGIN
154
+ PERFORM public.finora_journal_autopost(org,'BAD_SALE_INVALID_DATE','invoices','SOURCE_C_BAD_DATE',
155
+ jsonb_set(jsonb_set(hdr_s,'{sourceId}','"SOURCE_C_BAD_DATE"'),'{date}','"1405/13/40"'),'[]'::jsonb);
156
+ RAISE EXCEPTION 'FINORA_INVALID_SOURCE_DATE_ACCEPTED';
157
+ EXCEPTION WHEN check_violation THEN
158
+ IF SQLERRM NOT LIKE '%FINORA_SOURCE_HEADER_MISMATCH%' THEN RAISE;END IF;
159
+ END;
160
BEGIN
161
PERFORM public.finora_journal_autopost(org,'BAD_SALE_DATE','invoices','SOURCE_C_1',
162
jsonb_set(hdr_s,'{date}','"1405/08/01"'),'[]'::jsonb);
@@ -216,7 +227,7 @@ BEGIN
227
RAISE EXCEPTION 'FINORA_REVERSED_SOURCE_REPLAY_STATUS_NOT_RECONCILED';END IF;
228
IF EXISTS(SELECT 1 FROM public.records WHERE organization_id=org
229
AND collection='journalVouchers' AND id IN('BAD_SALE_ACCOUNTS','BAD_PURCHASE_ACCOUNTS',
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
230
+ 'UNSUPPORTED_KIND','WRONG_TENANT_SOURCE','BAD_NULL_SOURCE_TYPE','BAD_NULL_SALE_KIND','BAD_SALE_INVALID_DATE','BAD_SALE_DATE','BAD_SALE_VOUCHER_TYPE','S_POST_AGAIN')) THEN
231
RAISE EXCEPTION 'FINORA_NEGATIVE_OR_RETRY_LEFT_VOUCHER';END IF;
232
RAISE NOTICE 'FINORA_SALE_PURCHASE_NEGATIVES_AND_REVERSED_IDEMPOTENCY_PASS';
233
END $t$;