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

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

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

Synced Dec 3, 18:15 UTC

test: complete C8 workflow graph validation cases

davoodmehraban89 committed Oct 1, 2026 at 21:03 UTC 75f0f8f7ba80ea363667ac9c80919ee883713ed7
1 file changed +40
supabase/tests/office_c8_workflow.sql
+40
@@ -9,8 +9,12 @@ 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 + -- Persian labels and the minimal valid graph must pass.
13 perform private.office_workflow_validate_definition(valid);
14
15 + begin perform private.office_workflow_validate_definition(null); raise exception 'expected null rejection';
16 + exception when sqlstate '22023' then null; end;
17 +
18 bad := '{"stages":[{"id":"only","label":"تنها","start":true,"terminal":true}],"edges":[]}'::jsonb;
19 begin perform private.office_workflow_validate_definition(bad); raise exception 'expected one-stage rejection';
20 exception when sqlstate '22023' then null; end;
@@ -19,6 +23,10 @@ begin
23 begin perform private.office_workflow_validate_definition(bad); raise exception 'expected 21-stage rejection';
24 exception when sqlstate '22023' then null; end;
25
26 + bad := jsonb_build_object('stages',valid->'stages','edges',(select jsonb_agg(jsonb_build_object('id','e'||g,'from','start','to','done','label','عبور','capability','edit')) from generate_series(1,61) g));
27 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected 61-edge rejection';
28 + exception when sqlstate '22023' then null; end;
29 +
30 bad := jsonb_set(valid,'{edges,0,capability}','"delete"'::jsonb);
31 begin perform private.office_workflow_validate_definition(bad); raise exception 'expected capability rejection';
32 exception when sqlstate '22023' then null; end;
@@ -39,13 +47,45 @@ begin
47 begin perform private.office_workflow_validate_definition(bad); raise exception 'expected unknown-root-key rejection';
48 exception when sqlstate '22023' then null; end;
49
50 + bad := jsonb_set(valid,'{stages,0}',(valid->'stages'->0)||'{"unknown":true}'::jsonb);
51 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected unknown-stage-key rejection';
52 + exception when sqlstate '22023' then null; end;
53 +
54 + bad := jsonb_set(valid,'{edges,0}',(valid->'edges'->0)||'{"unknown":true}'::jsonb);
55 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected unknown-edge-key rejection';
56 + exception when sqlstate '22023' then null; end;
57 +
58 bad := jsonb_set(valid,'{stages,0,start}','"true"'::jsonb);
59 begin perform private.office_workflow_validate_definition(bad); raise exception 'expected non-boolean flag rejection';
60 exception when sqlstate '22023' then null; end;
61
62 + bad := jsonb_set(valid,'{stages,1,id}','"start"'::jsonb);
63 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected duplicate-stage-id rejection';
64 + exception when sqlstate '22023' then null; end;
65 +
66 + bad := jsonb_set(valid,'{edges}',(valid->'edges')||jsonb_build_array((valid->'edges'->0)||'{"label":"دوباره"}'::jsonb));
67 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected duplicate-edge-id rejection';
68 + exception when sqlstate '22023' then null; end;
69 +
70 + bad := jsonb_set(valid,'{edges}',(valid->'edges')||jsonb_build_array((valid->'edges'->0)||'{"id":"again"}'::jsonb));
71 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected duplicate-edge-pair rejection';
72 + exception when sqlstate '22023' then null; end;
73 +
74 + bad := jsonb_set(valid,'{edges}',jsonb_build_array((valid->'edges'->0),jsonb_build_object('id','back','from','done','to','start','label','بازگشت','capability','edit')));
75 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected terminal-outgoing rejection';
76 + exception when sqlstate '22023' then null; end;
77 +
78 bad := jsonb_set(valid,'{stages,1}',jsonb_build_object('id','orphan','label','یتیم','start',false,'terminal',true));
79 begin perform private.office_workflow_validate_definition(bad); raise exception 'expected unreachable-stage rejection';
80 exception when sqlstate '22023' then null; end;
81 +
82 + bad := '{"stages":[{"id":"start","label":"شروع","start":true,"terminal":false},{"id":"done","label":"پایان","start":false,"terminal":true},{"id":"loop1","label":"حلقه ۱","start":false,"terminal":false},{"id":"loop2","label":"حلقه ۲","start":false,"terminal":false}],"edges":[{"id":"finish","from":"start","to":"done","label":"پایان","capability":"approve"},{"id":"branch","from":"start","to":"loop1","label":"شاخه","capability":"edit"},{"id":"l12","from":"loop1","to":"loop2","label":"بعدی","capability":"edit"},{"id":"l21","from":"loop2","to":"loop1","label":"برگشت","capability":"edit"}]}'::jsonb;
83 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected no-exit-cycle rejection';
84 + exception when sqlstate '22023' then null; end;
85 +
86 + bad := jsonb_build_object('stages',valid->'stages','edges',valid->'edges','padding',repeat('x',70000));
87 + begin perform private.office_workflow_validate_definition(bad); raise exception 'expected size rejection';
88 + exception when sqlstate '22023' then null; end;
89 end $$;
90
91 rollback;