feat(supabase): last_modified_at in the admin sheet summary (M9)

Admin sheet summary answers last_modified_at: newest of the sheet row and
its versions' updated_at. Read change only, body otherwise identical to M7.
pgTAP 022: plan 60 to 72, 12 assertions added, none changed.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
bchanotandClaude committed 2026-11-16 01:15:49 +01:00
1 parent 2277e41b09
commit e3495df088
2 files changed
+125 -1

No files matched your search

+53 -1
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(60);
select plan(72);
-- 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
@@ -181,6 +181,58 @@ select is(pg_temp.val($$ select public.get_sheet_version(pg_temp.id('SX.v2')) ->
select pg_temp.as_user('E', 'aal2');
select is(pg_temp.val($$ select public.get_sheet_version(pg_temp.id('SP.v2')) ->> 'fingerprint' $$), 'ok', 'editor: a draft has no fingerprint');
-- ============ Last modification date (R3, M9) ============
-- now() is the transaction's start for the whole file, so these rows are dated
-- in the past at insert (the trigger stamps updates only): a later write then
-- shows as a newer date.
reset role;
select set_config('request.jwt.claims', '{"sub":"22000000-0000-0000-0000-00000000000e"}', true);
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');
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('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.
(pg_temp.id('WK'), 'equine', 'WK', 'm22-wk', true, 'private', 'active', '2026-01-01T10:00:00Z', '2026-01-01T10:00:00Z',
pg_temp.id('h.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');
-- 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
$$;
grant execute on function pg_temp.at(text, text) to authenticated;
select pg_temp.as_user('E', 'aal2');
select is(pg_temp.at('SL', 'last_modified_at'), '2026-01-02T10:00:00Z'::timestamptz,
'a version newer than the sheet row gives the last modification');
select is(pg_temp.at('SN', 'last_modified_at'), '2026-01-03T10:00:00Z'::timestamptz,
'a sheet without a version answers its own date');
select is(pg_temp.val($$ select public.save_sheet_draft(pg_temp.id('SL.v1'), 0, pg_temp.doc('Datée 2'), 'r3') ->> 'revision' $$),
'1', 'E saves the dated draft');
select is(pg_temp.at('SL', 'last_modified_at'), now(), 'a draft save moves last_modified_at');
select is(pg_temp.at('SL', 'updated_at'), '2026-01-01T10:00:00Z'::timestamptz, 'a draft save leaves the sheet row''s date');
reset role;
update public.anatomical_sheets set name = 'SN 2' where id = pg_temp.id('SN');
select pg_temp.as_user('E', 'aal2');
select is(pg_temp.at('SN', 'last_modified_at'), now(), 'a sheet change moves last_modified_at');
select is(pg_temp.at('SN', 'updated_at'), now(), 'a sheet change moves updated_at too');
select is((public.get_official_sheet_admin(pg_temp.id('WK')) ->> 'working_copy')::boolean, true,
'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');
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.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');
-- ============ Privileges and nature ============
reset role;
select ok(not has_function_privilege('anon', 'public.list_official_sheets_admin()', 'execute')