@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / a162481
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 19:30 UTC

test: add failing C8 workflow policy contract

davoodmehraban89 committed Oct 1, 2026 at 21:01 UTC a16248168a06981a2454975a7589aac22ef23a5b
1 file changed +51
supabase/tests/office_c8_workflow.sql new
+51
@@ -0,0 +1,51 @@
1 +-- Office Slice C8 policy validation behavioral contract.
2 +-- Run against a disposable/nonproduction database after applying the C8 migration.
3 +-- This file is intentionally transaction-safe and creates no persistent fixtures.
4 +
5 +begin;
6 +
7 +do $$
8 +declare
9 + valid jsonb := '{"stages":[{"id":"start","label":"شروع","start":true,"terminal":false},{"id":"done","label":"پایان","start":false,"terminal":true}],"edges":[{"id":"approve","from":"start","to":"done","label":"تأیید","capability":"approve"}]}'::jsonb;
10 + bad jsonb;
11 +begin
12 + perform private.office_workflow_validate_definition(valid);
13 +
14 + bad := '{"stages":[{"id":"only","label":"تنها","start":true,"terminal":true}],"edges":[]}'::jsonb;
15 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected one-stage rejection';
16 + exception when sqlstate '22023' then null; end;
17 +
18 + bad := jsonb_build_object('stages',(select jsonb_agg(jsonb_build_object('id','s'||g,'label','مرحله','start',g=1,'terminal',g=21)) from generate_series(1,21) g),'edges','[]'::jsonb);
19 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected 21-stage rejection';
20 + exception when sqlstate '22023' then null; end;
21 +
22 + bad := jsonb_set(valid,'{edges,0,capability}','"delete"'::jsonb);
23 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected capability rejection';
24 + exception when sqlstate '22023' then null; end;
25 +
26 + bad := jsonb_set(valid,'{edges,0,to}','"missing"'::jsonb);
27 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected unknown-target rejection';
28 + exception when sqlstate '22023' then null; end;
29 +
30 + bad := jsonb_set(valid,'{edges,0,to}','"start"'::jsonb);
31 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected self-edge rejection';
32 + exception when sqlstate '22023' then null; end;
33 +
34 + bad := jsonb_set(valid,'{stages,1,terminal}','false'::jsonb);
35 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected no-terminal rejection';
36 + exception when sqlstate '22023' then null; end;
37 +
38 + bad := valid || '{"unknown":true}'::jsonb;
39 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected unknown-root-key rejection';
40 + exception when sqlstate '22023' then null; end;
41 +
42 + bad := jsonb_set(valid,'{stages,0,start}','"true"'::jsonb);
43 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected non-boolean flag rejection';
44 + exception when sqlstate '22023' then null; end;
45 +
46 + bad := jsonb_set(valid,'{stages,1}',jsonb_build_object('id','orphan','label','یتیم','start',false,'terminal',true));
47 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected unreachable-stage rejection';
48 + exception when sqlstate '22023' then null; end;
49 +end $$;
50 +
51 +rollback;