test(supabase): close the gaps two M3 mutations went through

A client whose only link was voided while current must not count the animal;
B linking its own animal to a client of A must not wait on A's lock. Also a
relation create racing the archive of its animal, and a replay changing the
initial relation's role.
This commit is contained in:
bchanot committed 2026-10-26 00:57:38 +01:00
1 parent b54c8e5bd8
commit 533a1c497d
2 files changed
+37 -3

No files matched your search

+7 -1
View File
@@ -9,7 +9,7 @@
-- creating an animal; S a platform owner; E (per-animal caps, animal cap),
-- F (budget), H (workspace relation cap) and G (D9a) confirmed.
begin;
select plan(254);
select plan(258);
insert into auth.users (id, email, email_confirmed_at) values
('70000000-0000-0000-0000-00000000000a', 'alice-an@test.local', now()),
@@ -306,6 +306,9 @@ select is(
public.create_animal(pg_temp.wa(), '71000000-0000-0000-0000-000000000002', 'Tonnerre', 'equine', 'male',
client_id => pg_temp.id('marie'), relation_role => 'owner', started_on => '2020-01-01') ->> 'relation_id',
pg_temp.id('r_tonnerre')::text, 'a replay returns the same relation');
select is(pg_temp.err($$ select public.create_animal(pg_temp.wa(), '71000000-0000-0000-0000-000000000002', 'Tonnerre', 'equine', 'male',
client_id => pg_temp.id('marie'), relation_role => 'keeper', started_on => '2020-01-01') $$),
'P0001|request_conflict||', 'a replay with another relation role is refused');
select is(pg_temp.err($$ select public.create_animal(pg_temp.wa(), gen_random_uuid(), 'X', 'equine', 'male',
client_id => pg_temp.id('marie')) $$), 'P0001|invalid_input||', 'a client without a role is refused');
select is(pg_temp.err($$ select public.create_animal(pg_temp.wa(), gen_random_uuid(), 'X', 'equine', 'male',
@@ -376,6 +379,8 @@ select is(pg_temp.err($$ select public.update_animal_client_relation(pg_temp.id(
'P0001|invalid_input||', 'a voided relation cannot be corrected');
select lives_ok($$ select pg_temp.new_relation('r_rex_marie', 'rex', 'marie', 'owner') $$,
'a voided relation no longer holds the current-relation slot');
select lives_ok($$ select pg_temp.new_relation('r_sans_ana_wrong', 'sans', 'ana', 'keeper') $$, 'Ana entered as keeper by mistake');
select is(public.void_animal_client_relation(pg_temp.id('r_sans_ana_wrong'), 1) ->> 'revision', '2', 'voided while current');
select lives_ok($$ select pg_temp.new_relation('r_rex_lac_contact', 'rex', 'lac', 'contact') $$, 'a contact');
select is(public.end_animal_client_relation(pg_temp.id('r_rex_lac_contact'), 1, '2024-01-01') ->> 'revision', '2', 'the contact ends');
select is(public.void_animal_client_relation(pg_temp.id('r_rex_lac_contact'), 2) ->> 'revision', '3',
@@ -494,6 +499,7 @@ select is(pg_temp.client_count('marie'), 4, 'Marie: Éclair (two roles, counted
select is(pg_temp.client_count('paul'), 2, 'Paul: Éclair and Quatuor; Bijou archived is not counted');
select is(pg_temp.client_count('lac'), 3, 'the stable: Éclair, Luna, Quatuor; ended and voided relations left out');
select is(pg_temp.client_count('zoe'), 1, 'archived Zoé: Luna; her ended keeper relation left out');
select is(pg_temp.client_count('ana'), 1, 'Ana: Quatuor; her voided keeper relation to Sans Maître left out');
select is(pg_temp.client_animals('lac'), 'Éclair:keeper:current|Luna:owner:current|Quatuor:owner:current|Bijou:owner:former',
'a client''s animals: current first, then former, each by name; voided left out');