fix(app): grant expiry ends the chosen day in Paris; species order 0..9999 (V1-2.5 L2)

Owner checkpoint 2026-11-02: expiry 23:59:59.999 Europe/Paris (picker, validation, display), tests under non-Paris zones and DST days; M7 redefines create_species and update_inactive_species with the range check; pgTAP 015 and 022; « Relecteur ou relectrice »; object_conflict EN; setup key selectable, no Copy.
This commit is contained in:
bchanot committed 2026-11-02 21:29:33 +01:00
1 parent 4111efa1d1
commit 51225cacf6
17 files changed
+437 -61

No files matched your search

+52 -1
View File
@@ -5,7 +5,7 @@
-- proven in packages/supabase/tests/sandbox/sheets.sandbox.ts, the seed owner's
-- factors on an upgraded stack in seed-owner-mfa.sandbox.ts.
begin;
select plan(37);
select plan(44);
insert into auth.users (id, email, email_confirmed_at) values
('d0000000-0000-0000-0000-000000000001', 'own@t.local', now()), -- owner
@@ -190,6 +190,57 @@ select ok(not private.grant_active('d0000000-0000-0000-0000-00000000000c','catal
set local role authenticated;
select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2');
-- Expiry instants (owner 2026-11-02, Europe/Paris end of day): the stored
-- instant is the same whatever the session TimeZone; the DST days are future
-- ones the RPC accepts. One fresh account per grant (one active row per kind).
reset role;
insert into auth.users (id, email, email_confirmed_at) values
('d0000000-0000-0000-0000-0000000000b1', 'tz1@t.local', now()),
('d0000000-0000-0000-0000-0000000000b2', 'tz2@t.local', now()),
('d0000000-0000-0000-0000-0000000000b3', 'tz3@t.local', now()),
('d0000000-0000-0000-0000-0000000000b4', 'tz4@t.local', now()),
('d0000000-0000-0000-0000-0000000000b5', 'st1@t.local', now()),
('d0000000-0000-0000-0000-0000000000b6', 'st2@t.local', now()),
('d0000000-0000-0000-0000-0000000000b7', 'st3@t.local', now());
set local role authenticated;
select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2');
set local timezone to 'UTC';
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b1', 'catalog_reader', 'tz', null, '2027-03-28T23:59:59.999+02:00');
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b2', 'catalog_reader', 'tz', null, '2027-10-31T23:59:59.999+01:00');
set local timezone to 'America/New_York';
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b3', 'catalog_reader', 'tz', null, '2027-03-28T23:59:59.999+02:00');
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b4', 'catalog_reader', 'tz', null, '2027-10-31T23:59:59.999+01:00');
reset role;
select is((select string_agg(to_char(expires_at at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS'), ',' order by user_id)
from public.anatomical_catalog_grants where user_id in (
'd0000000-0000-0000-0000-0000000000b1', 'd0000000-0000-0000-0000-0000000000b2')),
'2027-03-28T21:59:59.999,2027-10-31T22:59:59.999', 'the 2027 DST days store the same instants under UTC');
select is((select string_agg(to_char(expires_at at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS'), ',' order by user_id)
from public.anatomical_catalog_grants where user_id in (
'd0000000-0000-0000-0000-0000000000b3', 'd0000000-0000-0000-0000-0000000000b4')),
'2027-03-28T21:59:59.999,2027-10-31T22:59:59.999', 'the 2027 DST days store the same instants under America/New_York');
select is((select count(*)::int from public.anatomical_catalog_grants where user_id in (
'd0000000-0000-0000-0000-0000000000b1', 'd0000000-0000-0000-0000-0000000000b2')
and expires_at in ('2027-03-28T21:59:59.999Z'::timestamptz, '2027-10-31T22:59:59.999Z'::timestamptz)), 2,
'the stored instants equal the Paris end of day (summer +02:00, winter +01:00)');
set local timezone to 'UTC';
-- The list state at each boundary (direct inserts with an earlier granted_at).
insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, granted_by, granted_at, expires_at) values
('d0000000-0000-0000-0000-0000000000b5', 'catalog_reader', 'x', 'd0000000-0000-0000-0000-000000000001', now() - interval '2 days', now() - interval '1 minute'),
('d0000000-0000-0000-0000-0000000000b6', 'catalog_reader', 'x', 'd0000000-0000-0000-0000-000000000001', now() - interval '2 days', now() + interval '1 minute'),
('d0000000-0000-0000-0000-0000000000b7', 'catalog_reader', 'x', 'd0000000-0000-0000-0000-000000000001', now() - interval '2 days', now() + interval '30 days 1 minute');
set local role authenticated;
select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2');
create function pg_temp.grant_state(p_user uuid) returns text language sql stable as $$
select (e ->> 'state') || '/' || (e ->> 'effective')
from jsonb_array_elements(public.list_catalog_grants()) e where (e ->> 'user_id')::uuid = p_user;
$$;
grant execute on function pg_temp.grant_state(uuid) to authenticated;
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b5'), 'expired/false', 'expiry 1 minute ago: expired, not effective');
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b6'), 'expiring/true', 'expiry in 1 minute: expiring, effective');
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b7'), 'active/true', 'expiry in 30 days and 1 minute: active, effective');
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b3') like 'expiring/%' or pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b3') like 'active/%', true, 'a future DST-day grant is listed live');
-- only the owner (aal2) lists grants
select ok((select jsonb_typeof(public.list_catalog_grants()) = 'array'), 'owner lists grants');
select pg_temp.act('d0000000-0000-0000-0000-00000000000a', 'd1000000-0000-0000-0000-00000000000a', 'aal2');