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

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

test: define D2 legacy cutover assertions

davoodmehraban89 committed Oct 1, 2026 at 22:39 UTC c63647c5dc2afa92370313b7addaa6e9d6085292
1 file changed +29
supabase/tests/request_d2_legacy_behavior.sql new
+29
@@ -0,0 +1,29 @@
1 +do $$
2 +declare c integer;
3 +begin
4 + select count(*) into c from public.request_type_definitions where legacy_record_id in ('RT_LEGACY_A','RT_LEGACY_B');
5 + if c<>2 then raise exception 'expected 2 migrated request definitions, got %',c; end if;
6 + select count(*) into c from public.request_type_versions v join public.request_type_definitions d on d.id=v.request_type_id where d.legacy_record_id in ('RT_LEGACY_A','RT_LEGACY_B') and v.version_no=1;
7 + if c<>2 then raise exception 'expected immutable version 1 for both legacy request types'; end if;
8 + select count(*) into c from public.request_workflow_versions w join public.request_type_versions v on v.id=w.request_type_version_id join public.request_type_definitions d on d.id=v.request_type_id where d.legacy_record_id in ('RT_LEGACY_A','RT_LEGACY_B');
9 + if c<>2 then raise exception 'expected workflow snapshots for both legacy request types'; end if;
10 + select count(*) into c from public.request_instances where legacy_record_id in ('REQ_LEGACY_A','REQ_LEGACY_B') and status='submitted';
11 + if c<>2 then raise exception 'expected 2 migrated submitted request instances'; end if;
12 + select count(*) into c from public.request_instance_events e join public.request_instances r on r.id=e.request_instance_id where r.legacy_record_id in ('REQ_LEGACY_A','REQ_LEGACY_B') and e.action='legacy_import' and e.revision=1;
13 + if c<>2 then raise exception 'expected immutable legacy import evidence'; end if;
14 + select count(*) into c from public.records where collection in ('requestTypes','requests');
15 + if c<>4 then raise exception 'legacy records must remain preserved after cutover'; end if;
16 + if (select legacy_number from public.request_instances where legacy_record_id='REQ_LEGACY_A')<>'REQ-2026-00001' then raise exception 'legacy request number not preserved'; end if;
17 + if (select values_json->>'f1' from public.request_instances where legacy_record_id='REQ_LEGACY_A')<>'لپ‌تاپ' then raise exception 'legacy request values not preserved'; end if;
18 +end $$;
19 +
20 +-- Re-running the migration must be idempotent: no duplicate definitions/versions/instances/events.
21 +\ir ../migrations/20261001223500_request_workflow_d2_legacy_cutover.sql
22 +
23 +do $$
24 +declare c integer;
25 +begin
26 + select count(*) into c from public.request_type_definitions where legacy_record_id in ('RT_LEGACY_A','RT_LEGACY_B'); if c<>2 then raise exception 'legacy definition import is not idempotent'; end if;
27 + select count(*) into c from public.request_instances where legacy_record_id in ('REQ_LEGACY_A','REQ_LEGACY_B'); if c<>2 then raise exception 'legacy instance import is not idempotent'; end if;
28 + select count(*) into c from public.request_instance_events e join public.request_instances r on r.id=e.request_instance_id where r.legacy_record_id in ('REQ_LEGACY_A','REQ_LEGACY_B') and e.action='legacy_import'; if c<>2 then raise exception 'legacy event import is not idempotent'; end if;
29 +end $$;