test(supabase): pgTAP 022 sheet-newer case on its own fixture

WK sequence restored (flag, dated, save, now). New SR fixture proves a sheet
row newer than its versions. Plan 73 to 74.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
bchanotandClaude committed 2026-11-16 14:32:01 +01:00
1 parent a76a54dbb7
commit f3712b2baa
1 file changed
+13 -8
+13 -8
View File
@@ -4,7 +4,7 @@
-- unknown, deleted, personal or forbidden sheet gets one answer. Fixtures are
-- scoped to the ids created here.
begin;
select plan(73);
select plan(74);
-- Accounts. O owner, A admin, E admin + editor, V reviewer, P admin +
-- publisher, R reader, N no right. Every one has a verified factor and a live
@@ -190,10 +190,12 @@ select set_config('request.jwt.claims', '{"sub":"22000000-0000-0000-0000-0000000
insert into pg_temp.k values
('SL', '22200000-0000-0000-0000-000000000007'), ('SL.v1', '22300000-0000-0000-0000-000000000071'),
('SN', '22200000-0000-0000-0000-000000000008'),
('WK', '22200000-0000-0000-0000-000000000009'), ('WK.v1', '22300000-0000-0000-0000-000000000091');
('WK', '22200000-0000-0000-0000-000000000009'), ('WK.v1', '22300000-0000-0000-0000-000000000091'),
('SR', '22200000-0000-0000-0000-00000000000a'), ('SR.v1', '22300000-0000-0000-0000-0000000000a1');
insert into public.anatomical_sheets (id, species_id, name, slug, is_official, visibility, status,
created_at, updated_at, working_copy_source_version_id) values
(pg_temp.id('SL'), 'equine', 'SL', 'm22-sl', true, 'private', 'active', '2026-01-01T10:00:00Z', '2026-01-01T10:00:00Z', null),
(pg_temp.id('SR'), 'equine', 'SR', 'm22-sr', true, 'private', 'active', '2026-01-01T10:00:00Z', '2026-01-01T10:00:00Z', null),
(pg_temp.id('SN'), 'equine', 'SN', 'm22-sn', true, 'private', 'active', '2026-01-03T10:00:00Z', '2026-01-03T10:00:00Z', null),
-- A second, dated working copy of the historical sheet: the single slot is a
-- rule of create_sheet_working_copy, not a constraint, and WC holds it already.
@@ -202,7 +204,8 @@ insert into public.anatomical_sheets (id, species_id, name, slug, is_official, v
insert into public.anatomical_sheet_versions (id, sheet_id, version_number, status, document_schema_version, content,
created_at, updated_at) values
(pg_temp.id('SL.v1'), pg_temp.id('SL'), 1, 'draft', 2, pg_temp.doc('Datée'), '2026-01-02T10:00:00Z', '2026-01-02T10:00:00Z'),
(pg_temp.id('WK.v1'), pg_temp.id('WK'), 1, 'draft', 2, pg_temp.doc('Copie datée'), '2026-01-04T10:00:00Z', '2026-01-04T10:00:00Z');
(pg_temp.id('WK.v1'), pg_temp.id('WK'), 1, 'draft', 2, pg_temp.doc('Copie datée'), '2026-01-04T10:00:00Z', '2026-01-04T10:00:00Z'),
(pg_temp.id('SR.v1'), pg_temp.id('SR'), 1, 'draft', 2, pg_temp.doc('Jamais sauvée'), '2026-01-02T10:00:00Z', '2026-01-02T10:00:00Z');
-- One date of a sheet's admin answer.
create function pg_temp.at(p_key text, p_field text) returns timestamptz language sql as $$
select (public.get_official_sheet_admin(pg_temp.id(p_key)) ->> p_field)::timestamptz
@@ -227,14 +230,16 @@ select is((public.get_official_sheet_admin(pg_temp.id('WK')) ->> 'working_copy')
'the dated fixture is a working copy');
select is(pg_temp.at('WK', 'last_modified_at'), '2026-01-04T10:00:00Z'::timestamptz,
'a working copy is dated by its own draft');
reset role;
update public.anatomical_sheets set name = 'WK 2' where id = pg_temp.id('WK');
select pg_temp.as_user('E', 'aal2');
select is(pg_temp.at('WK', 'last_modified_at'), now(),
'a sheet change newer than its versions gives the sheet''s date');
select is(pg_temp.val($$ select public.save_sheet_draft(pg_temp.id('WK.v1'), 0, pg_temp.doc('Copie datée 2'), 'r3') ->> 'revision' $$),
'1', 'E saves the working copy''s draft');
select is(pg_temp.at('WK', 'last_modified_at'), now(), 'a working copy''s draft save moves its last_modified_at');
select is(pg_temp.at('SR', 'last_modified_at'), '2026-01-02T10:00:00Z'::timestamptz,
'a never-saved draft dates its sheet while the sheet row is older');
reset role;
update public.anatomical_sheets set name = 'SR 2' where id = pg_temp.id('SR');
select pg_temp.as_user('E', 'aal2');
select is(pg_temp.at('SR', 'last_modified_at'), now(),
'a sheet change newer than its versions gives the sheet''s date');
select is(pg_temp.val($$ select count(*)::text from jsonb_array_elements(public.list_official_sheets_admin()) e
where e ->> 'last_modified_at' is null $$), '0', 'every listed sheet carries last_modified_at');