سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 3, 15:45 UTC
D4a: isolate queue assertions from prior workflow fixtures
davoodmehraban89 committed
Oct 2, 2026 at 06:59 UTC
81ca79ab67c68f0708f774ee3dfd64eb8e8f6b67
1 file changed
+5
-7
supabase/tests/request_d4a_work_queue.sql
+5
-7
@@ -17,13 +17,12 @@ insert into d4a_ids values('direct',public.request_create_instance(
17
18
do $$ declare q jsonb; begin
19
q:=public.request_work_queue('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
20
- if jsonb_array_length(q)<>1 then raise exception 'direct approver queue expected one item, got %',jsonb_array_length(q); end if;
21
- if q->0->>'stepKey'<>'manager' or q->0->>'requestTypeTitle'<>'کارتابل اقدام' then raise exception 'work queue projection mismatch'; end if;
22
- if q->0->>'delegatedFromUserId' is not null then raise exception 'direct capability incorrectly marked delegated'; end if;
20
+ if not exists(select 1 from jsonb_array_elements(q) x where x->>'requestInstanceId'=(select v::text from d4a_ids where k='direct')) then raise exception 'direct approver item missing from queue'; end if;
21
+ if not exists(select 1 from jsonb_array_elements(q) x where x->>'requestInstanceId'=(select v::text from d4a_ids where k='direct') and x->>'stepKey'='manager' and x->>'requestTypeTitle'='کارتابل اقدام' and x->>'delegatedFromUserId' is null) then raise exception 'direct work queue projection mismatch'; end if;
22
end $$;
23
24
select * from public.request_step_decide((select v from d4a_ids where k='direct'),'approve',1,'d4a-direct-vote-0001','ok');
26
-do $$ declare q jsonb; begin q:=public.request_work_queue('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');if jsonb_array_length(q)<>0 then raise exception 'completed request remained actionable';end if;end $$;
25
+do $ declare q jsonb; begin q:=public.request_work_queue('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');if exists(select 1 from jsonb_array_elements(q) x where x->>'requestInstanceId'=(select v::text from d4a_ids where k='direct')) then raise exception 'completed request remained actionable';end if;end $;
26
27
reset role;
28
insert into public.profiles(id) values ('55555555-5555-5555-5555-555555555555') on conflict do nothing;
@@ -46,11 +45,10 @@ select set_config('request.jwt.claim.sub','55555555-5555-5555-5555-555555555555'
45
select set_config('request.jwt.claim.capabilities','read',false);
46
do $$ declare q jsonb; begin
47
q:=public.request_work_queue('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
49
- if jsonb_array_length(q)<>1 then raise exception 'delegate queue expected one item, got %',jsonb_array_length(q); end if;
50
- if q->0->>'delegatedFromUserId'<>'11111111-1111-1111-1111-111111111111' then raise exception 'delegation provenance missing from queue'; end if;
48
+ if not exists(select 1 from jsonb_array_elements(q) x where x->>'requestInstanceId'=(select v::text from d4a_ids where k='delegated') and x->>'delegatedFromUserId'='11111111-1111-1111-1111-111111111111') then raise exception 'delegated item or provenance missing from queue'; end if;
49
end $$;
50
select * from public.request_step_decide((select v from d4a_ids where k='delegated'),'approve',1,'d4a-delegate-vote-01','delegated');
53
-do $$ declare q jsonb; begin q:=public.request_work_queue('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');if jsonb_array_length(q)<>0 then raise exception 'delegate completed item remained actionable';end if;end $$;
51
+do $ declare q jsonb; begin q:=public.request_work_queue('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');if exists(select 1 from jsonb_array_elements(q) x where x->>'requestInstanceId'=(select v::text from d4a_ids where k='delegated')) then raise exception 'delegate completed item remained actionable';end if;end $;
52
53
select set_config('request.jwt.claim.sub','22222222-2222-2222-2222-222222222222',false);
54
select set_config('request.jwt.claim.capabilities','read',false);