-- Professional columns on profiles: own-row update, format checks, denied paths. begin; select plan(13); insert into auth.users (id, email) values ('00000000-0000-0000-0000-00000000000a', 'alice@test.local'), ('00000000-0000-0000-0000-00000000000b', 'bob@test.local'); select has_column('public', 'profiles', 'practice_name', 'practice_name exists'); select has_column('public', 'profiles', 'professional_title', 'professional_title exists'); select has_column('public', 'profiles', 'siret', 'siret exists'); select is( (select count(*)::int from information_schema.column_privileges where table_schema = 'public' and table_name = 'profiles' and grantee = 'authenticated' and privilege_type = 'UPDATE' and column_name in ('practice_name', 'professional_title', 'siret')), 3, 'authenticated may update the three professional columns' ); set local role authenticated; select set_config('request.jwt.claims', '{"sub":"00000000-0000-0000-0000-00000000000a","role":"authenticated"}', true); select lives_ok( $$ update public.profiles set practice_name = 'Cabinet Équilibre', professional_title = 'Ostéopathe animalier', siret = '12345678901234' where id = '00000000-0000-0000-0000-00000000000a' $$, 'alice fills her professional information' ); select is( (select siret from public.profiles where id = '00000000-0000-0000-0000-00000000000a'), '12345678901234', 'siret stored as declared' ); select throws_ok( $$ update public.profiles set siret = '1234' where id = '00000000-0000-0000-0000-00000000000a' $$, '23514', null, 'siret must be 14 digits' ); select throws_ok( $$ update public.profiles set siret = '1234567890123a' where id = '00000000-0000-0000-0000-00000000000a' $$, '23514', null, 'siret refuses letters' ); select throws_ok( $$ update public.profiles set practice_name = '' where id = '00000000-0000-0000-0000-00000000000a' $$, '23514', null, 'empty practice_name refused (null clears it)' ); select lives_ok( $$ update public.profiles set siret = null, practice_name = null where id = '00000000-0000-0000-0000-00000000000a' $$, 'alice clears her professional information' ); -- Bob's row is invisible to alice: the update touches zero rows. select is( (select count(*)::int from public.profiles where id = '00000000-0000-0000-0000-00000000000b'), 0, 'alice does not see bob' ); select lives_ok( $$ update public.profiles set practice_name = 'Hijack' where id = '00000000-0000-0000-0000-00000000000b' $$, 'writing an invisible row raises nothing' ); reset role; select is( (select practice_name from public.profiles where id = '00000000-0000-0000-0000-00000000000b'), null, 'bob untouched' ); select * from finish(); rollback;