82 lines
5.2 KiB
PL/PgSQL
82 lines
5.2 KiB
PL/PgSQL
-- Sammlung, Lieblingsspiele, BGG-Verknüpfung: alles privat je Nutzer.
|
|
begin;
|
|
select plan(18);
|
|
|
|
insert into auth.users (id, email, raw_user_meta_data) values
|
|
('11111111-1111-1111-1111-111111111111', 'anna@example.com', '{"age_confirmed":"true","terms_accepted":"true"}'),
|
|
('22222222-2222-2222-2222-222222222222', 'ben@example.com', '{"age_confirmed":"true","terms_accepted":"true"}');
|
|
|
|
insert into public.games (id, title, visibility) values
|
|
('a0000000-0000-0000-0000-000000000001', 'Catan', 'catalog'),
|
|
('a0000000-0000-0000-0000-000000000003', 'Azul', 'catalog');
|
|
insert into public.games (id, title, visibility, owner_id) values
|
|
('a0000000-0000-0000-0000-000000000002', 'Bens Prototyp', 'private', '22222222-2222-2222-2222-222222222222');
|
|
insert into public.game_variants (id, game_id, name) values
|
|
('c0000000-0000-0000-0000-000000000001', 'a0000000-0000-0000-0000-000000000001', 'Catan Jubiläum'),
|
|
('c0000000-0000-0000-0000-000000000002', 'a0000000-0000-0000-0000-000000000003', 'Azul Sommerpavillon');
|
|
|
|
-- Anna
|
|
select set_config('request.jwt.claims', '{"sub":"11111111-1111-1111-1111-111111111111","role":"authenticated"}', true);
|
|
set local role authenticated;
|
|
|
|
select lives_ok(
|
|
$$insert into public.collection_items (owner_id, game_id, variant_id, list)
|
|
values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000001', 'c0000000-0000-0000-0000-000000000001', 'owned')$$,
|
|
'Anna darf ein Spiel mit passender Variante in die Sammlung legen');
|
|
select throws_ok(
|
|
$$insert into public.collection_items (owner_id, game_id) values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000001')$$,
|
|
'23505', null, 'Je Nutzer und Spiel gibt es nur einen Eintrag');
|
|
select throws_ok(
|
|
$$insert into public.collection_items (owner_id, game_id, variant_id)
|
|
values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000003', 'c0000000-0000-0000-0000-000000000001')$$,
|
|
'23503', null, 'Eine Variante muss zum Spiel gehören');
|
|
select throws_ok(
|
|
$$insert into public.collection_items (owner_id, game_id, list) values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000003', 'verkauft')$$,
|
|
'23514', null, 'Unbekannte Liste wird abgelehnt');
|
|
select throws_ok(
|
|
$$insert into public.collection_items (owner_id, game_id, note) values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000003', repeat('x', 1001))$$,
|
|
'23514', null, 'Notiz ist auf 1000 Zeichen begrenzt');
|
|
select throws_ok(
|
|
$$insert into public.collection_items (owner_id, game_id) values ('22222222-2222-2222-2222-222222222222', 'a0000000-0000-0000-0000-000000000003')$$,
|
|
'42501', null, 'Anna kann nichts in fremde Sammlungen legen');
|
|
select throws_ok(
|
|
$$insert into public.collection_items (owner_id, game_id) values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000002')$$,
|
|
'42501', null, 'Anna kann kein fremdes privates Spiel in ihre Sammlung legen');
|
|
select lives_ok(
|
|
$$insert into public.favorite_games (profile_id, game_id, position) values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000001', 1)$$,
|
|
'Anna darf ein Lieblingsspiel setzen');
|
|
select throws_ok(
|
|
$$insert into public.favorite_games (profile_id, game_id, position) values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000003', 6)$$,
|
|
'23514', null, 'Es gibt höchstens 5 Lieblingsspiele');
|
|
select throws_ok(
|
|
$$insert into public.favorite_games (profile_id, game_id, position) values ('11111111-1111-1111-1111-111111111111', 'a0000000-0000-0000-0000-000000000003', 1)$$,
|
|
'23505', null, 'Eine Position ist nur einmal vergeben');
|
|
select lives_ok(
|
|
$$insert into public.bgg_links (profile_id, bgg_username) values ('11111111-1111-1111-1111-111111111111', 'anna_bgg')$$,
|
|
'Anna darf ihren BGG-Namen hinterlegen');
|
|
reset role;
|
|
|
|
-- Ben
|
|
select set_config('request.jwt.claims', '{"sub":"22222222-2222-2222-2222-222222222222","role":"authenticated"}', true);
|
|
set local role authenticated;
|
|
select is((select count(*) from public.collection_items), 0::bigint, 'Ben sieht Annas Sammlung nicht');
|
|
select is((select count(*) from public.favorite_games), 0::bigint, 'Ben sieht Annas Lieblingsspiele nicht');
|
|
select is((select count(*) from public.bgg_links), 0::bigint, 'Ben sieht Annas BGG-Namen nicht');
|
|
select is_empty($$update public.collection_items set note = 'Fremd' returning 1$$, 'Ben kann Annas Einträge nicht ändern');
|
|
select is_empty($$delete from public.collection_items returning 1$$, 'Ben kann Annas Einträge nicht löschen');
|
|
reset role;
|
|
|
|
-- Zeitstempel
|
|
set session_replication_role = replica;
|
|
update public.collection_items set created_at = '2020-01-01', updated_at = '2020-01-01';
|
|
set session_replication_role = origin;
|
|
update public.collection_items set note = 'neu';
|
|
select ok((select updated_at > '2020-01-01'::timestamptz and created_at = '2020-01-01'::timestamptz from public.collection_items),
|
|
'updated_at wird gesetzt, created_at bleibt');
|
|
|
|
-- Konto löschen entfernt die Sammlung
|
|
delete from auth.users where id = '11111111-1111-1111-1111-111111111111';
|
|
select is((select count(*) from public.collection_items), 0::bigint, 'Beim Löschen des Kontos verschwindet die Sammlung');
|
|
|
|
select * from finish();
|
|
rollback;
|