@davoodmehraban89 / Factor-easy / commits / c817abc
Fork 0

سامانه صدور فاکتور و حسابداری

test: assert attachment tombstone retention and immutable identity (#216)

davoodmehraban89 committed Nov 18, 2026 at 10:34 UTC c817abc1c1df45e6cfc0d30a0b6ec5805bce0731
1 file changed +22
supabase/tests/0216_attachment_candidate.sql
+22
@@ -28,5 +28,27 @@ BEGIN
28 OR pg_catalog.has_table_privilege('authenticated','private.finora_attachment_registry','DELETE') THEN
29 RAISE EXCEPTION 'allocator exposed';
30 END IF;
31 + PERFORM private.finora_tombstone_attachment(a,'C1','V2',a);
32 + PERFORM private.finora_tombstone_attachment(a,'C1','V2',b);
33 + IF NOT EXISTS(SELECT 1 FROM private.finora_attachment_registry WHERE organization_id=a AND voucher_id='V2' AND attachment_number=2 AND deleted_by=a AND deleted_at IS NOT NULL) THEN RAISE EXCEPTION 'tombstone changed'; END IF;
34 + BEGIN
35 + PERFORM private.finora_reserve_attachment(a,'C1','V2');
36 + RAISE EXCEPTION 'resurrection accepted';
37 + EXCEPTION WHEN check_violation THEN
38 + IF SQLERRM <> 'FINORA_ATTACHMENT_DELETED' THEN RAISE; END IF;
39 + END;
40 + IF private.finora_reserve_attachment(a,'C1','V5')<>4 THEN RAISE EXCEPTION 'number reused'; END IF;
41 + BEGIN
42 + DELETE FROM private.finora_attachment_registry WHERE organization_id=a AND voucher_id='V2';
43 + RAISE EXCEPTION 'physical deletion accepted';
44 + EXCEPTION WHEN check_violation THEN
45 + IF SQLERRM <> 'FINORA_ATTACHMENT_IMMUTABLE' THEN RAISE; END IF;
46 + END;
47 + BEGIN
48 + UPDATE private.finora_attachment_registry SET attachment_number=99 WHERE organization_id=a AND voucher_id='V1';
49 + RAISE EXCEPTION 'rewrite accepted';
50 + EXCEPTION WHEN check_violation THEN
51 + IF SQLERRM <> 'FINORA_ATTACHMENT_IMMUTABLE' THEN RAISE; END IF;
52 + END;
53 END $test$;
54 ROLLBACK;