feat: finalize ticket merging and speaker-aware imports

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-10 13:28:18 +02:00
1 parent 7f340b4c08
commit fbc827c2b8
35 files changed
+1772 -348

No files matched your search

@@ -0,0 +1,95 @@
\set ON_ERROR_STOP on
create function pg_temp.assert_speaker_role(p_condition boolean, p_name text) returns void
language plpgsql as $$ begin
if p_condition is distinct from true then raise exception 'FAIL: %', p_name; end if;
raise notice 'PASS: %', p_name;
end; $$;
create temp table role_fixture as select
gen_random_uuid() event_a, gen_random_uuid() event_b,
gen_random_uuid() talk, gen_random_uuid() service,
gen_random_uuid() reverse_talk,
'role-ticket-' || gen_random_uuid() || '@example.invalid' ticket_email,
'role-first-' || gen_random_uuid() || '@example.invalid' first_email,
'role-normal-' || gen_random_uuid() || '@example.invalid' normal_email,
'role-staff-' || gen_random_uuid() || '@example.invalid' staff_email,
'role-sponsor-' || gen_random_uuid() || '@example.invalid' sponsor_email,
'role-service-' || gen_random_uuid() || '@example.invalid' service_email,
-5000000-floor(random()*1000000)::integer talk_slot,
-7000000-floor(random()*1000000)::integer service_slot;
insert into public.events(id,name,start_date,end_date)
select event_a,'Role A',date '2026-11-01',date '2026-11-01' from role_fixture
union all select event_b,'Role B',date '2026-11-01',date '2026-11-01' from role_fixture;
insert into public.contacts(email,full_name)
select ticket_email,'Ticket Speaker' from role_fixture
union all select first_email,'First Speaker' from role_fixture
union all select normal_email,'Normal Attendee' from role_fixture
union all select staff_email,'Staff' from role_fixture
union all select sponsor_email,'Sponsor' from role_fixture
union all select service_email,'Service Only' from role_fixture;
insert into public.slots(id,event_id,type,name,slot_date,start_time,end_time)
select talk_slot,event_a,'session'::public.slot_type,'Talk',date '2026-11-01',time '09:00',time '10:00' from role_fixture
union all select service_slot,event_a,'service_session','Break',date '2026-11-01',time '10:00',time '11:00' from role_fixture;
insert into public.sessions(id,event_id,slot_id,title,external_id)
select talk,event_a,talk_slot,'Role talk',talk::text from role_fixture
union all select reverse_talk,event_a,talk_slot,'Reverse talk',reverse_talk::text from role_fixture
union all select service,event_a,service_slot,'Role break',service::text from role_fixture;
insert into public.session_speakers(session_id,contact_email)
select reverse_talk,first_email from role_fixture
union all select service,service_email from role_fixture;
select set_config('request.jwt.claims','{"role":"service_role"}',true);
create temp table role_sync_result as
select public.sync_pretix_attendees(event_a,jsonb_build_array(
jsonb_build_object('email',ticket_email,'full_name','Ticket Speaker','ticket_type','attendee','qr_token','role-ticket-qr','external_id','pretix-role'),
jsonb_build_object('email',first_email,'full_name','First Speaker','ticket_type','attendee','qr_token','role-first-qr','external_id','pretix-first'),
jsonb_build_object('email',normal_email,'full_name','Normal Attendee','ticket_type','attendee','qr_token','role-normal-qr','external_id','pretix-normal'),
jsonb_build_object('email',service_email,'full_name','Service Only','ticket_type','attendee','qr_token','role-service-qr','external_id','pretix-service')
)) result from role_fixture;
select pg_temp.assert_speaker_role(jsonb_array_length(result->'errors')=0,'initial Pretix sync succeeds') from role_sync_result;
select pg_temp.assert_speaker_role((select type='attendee' from public.registrations where event_id=f.event_a and contact_email=f.ticket_email),'ordinary ticket starts as attendee') from role_fixture f;
select pg_temp.assert_speaker_role((select type='speaker' from public.registrations where event_id=f.event_a and contact_email=f.first_email),'existing assignment promotes new Pretix registration') from role_fixture f;
select pg_temp.assert_speaker_role((select type='attendee' from public.registrations where event_id=f.event_a and contact_email=f.service_email),'service-only assignment does not promote attendee') from role_fixture f;
update public.registrations set points=23,checked_in=true where contact_email=(select ticket_email from role_fixture);
insert into public.sponsors(event_id,type,name,contact_email)
select event_a,'community','Role Sponsor',sponsor_email from role_fixture;
insert into public.registrations(event_id,contact_email,type)
select event_a,staff_email,'staff'::public.registration_type from role_fixture
union all select event_a,sponsor_email,'sponsor' from role_fixture
union all select event_b,ticket_email,'attendee' from role_fixture;
insert into public.session_speakers(session_id,contact_email)
select talk,ticket_email from role_fixture
union all select talk,staff_email from role_fixture
union all select talk,sponsor_email from role_fixture;
select pg_temp.assert_speaker_role((select type='speaker' from public.registrations where event_id=f.event_a and contact_email=f.ticket_email),'assignment promotes purchased ticket') from role_fixture f;
select pg_temp.assert_speaker_role((select type='attendee' from public.registrations where event_id=f.event_b and contact_email=f.ticket_email),'other event remains attendee') from role_fixture f;
select pg_temp.assert_speaker_role((select type='staff' from public.registrations where contact_email=f.staff_email),'staff role preserved') from role_fixture f;
select pg_temp.assert_speaker_role((select type='sponsor' from public.registrations where contact_email=f.sponsor_email),'sponsor role preserved') from role_fixture f;
update role_sync_result set result=(select public.sync_pretix_attendees(event_a,jsonb_build_array(
jsonb_build_object('email',ticket_email,'full_name','Ticket Speaker','ticket_type','attendee','qr_token','role-ticket-qr','external_id','pretix-role')
)) from role_fixture);
select pg_temp.assert_speaker_role(jsonb_array_length(result->'errors')=0,'repeated Pretix sync succeeds') from role_sync_result;
select pg_temp.assert_speaker_role((select type='speaker' and qr_token='role-ticket-qr' and external_id='pretix-role' and checked_in and points=23
from public.registrations where event_id=f.event_a and contact_email=f.ticket_email),'Pretix cannot downgrade speaker; ticket and activity preserved') from role_fixture f;
update role_sync_result set result=(select public.sync_sessionize_excel(event_a,jsonb_build_object(
'speakers',jsonb_build_array(jsonb_build_object('email',ticket_email,'full_name','Ticket Speaker','external_id','sessionize-role')),
'sessions',jsonb_build_array(jsonb_build_object('external_id',talk::text,'title','Role talk','date','2026-11-01','start_time','09:00','end_time','10:00',
'speakers',jsonb_build_array(ticket_email,staff_email,sponsor_email)))
)) from role_fixture);
select pg_temp.assert_speaker_role(jsonb_array_length(result->'errors')=0,'Excel replay succeeds') from role_sync_result;
select pg_temp.assert_speaker_role((select type='speaker' and qr_token='role-ticket-qr' and external_id='pretix-role' and checked_in and points=23 and import_source='sessionize'
from public.registrations where event_id=f.event_a and contact_email=f.ticket_email),'Excel preserves purchased speaker ticket') from role_fixture f;
select pg_temp.assert_speaker_role(exists(select 1 from public.session_speakers where session_id=f.talk and contact_email=f.ticket_email),'Excel keeps correct session assignment') from role_fixture f;
update role_sync_result set result=(select public.sync_pretix_attendees(event_a,jsonb_build_array(
jsonb_build_object('email',ticket_email,'full_name','Ticket Speaker','ticket_type','attendee','qr_token','role-ticket-qr','external_id','pretix-role')
)) from role_fixture);
select pg_temp.assert_speaker_role(jsonb_array_length(result->'errors')=0,'Pretix after Excel succeeds') from role_sync_result;
select pg_temp.assert_speaker_role((select type='speaker' and qr_token='role-ticket-qr' and checked_in and points=23
from public.registrations where event_id=f.event_a and contact_email=f.ticket_email),'Excel then Pretix retains speaker role and ticket') from role_fixture f;
update public.session_speakers set contact_email=(select normal_email from role_fixture)
where session_id=(select reverse_talk from role_fixture) and contact_email=(select first_email from role_fixture);
select pg_temp.assert_speaker_role((select type='speaker' from public.registrations where event_id=f.event_a and contact_email=f.normal_email),'assignment update promotes new speaker') from role_fixture f;
update public.registrations set type='attendee' where event_id=(select event_a from role_fixture) and contact_email=(select ticket_email from role_fixture);
select pg_temp.assert_speaker_role((select type='speaker' from public.registrations where event_id=f.event_a and contact_email=f.ticket_email),'direct downgrade blocked while assigned') from role_fixture f;
select pg_temp.assert_speaker_role(not has_function_privilege('anon','public._preserve_assigned_speaker_role()','execute')
and not has_function_privilege('authenticated','public._preserve_assigned_speaker_role()','execute'),'internal role trigger not exposed') from role_fixture;
rollback;