feat(points): staff auto-connect never scores; event feedback pays +5
- Migration 20261020120000: staff (type staff / Admin / @appe.at) are auto-connected to every participant of the event via connections.auto rows inserted directly as accepted - never through accept_connection, so zero points by construction; backfill + idempotent helper + trigger. - Migration 20261020130000: submit_event_feedback awards +5 on the first submission per participant x event (edits earn 0), gated by _points_eligible; response gains earned column; ACL restored. - Admin: points move from Contacts to Registrations (active-event rows only, in-place save); Dashboard Top points drops emails; Dashboard and Activity hide auto connections. - Attendee: leaderboard masks surnames (Max M.); EventFeedback toast shows +5 pts on paid submissions. - Tests: staff_auto_connections_tests.sql (14 assertions), rpc_tests section 11 (4 assertions). Docs + release record 2026-10-20. - README: document the git-ignored .env provisioning step (missing key = white screen).
This commit is contained in:
1 parent
b7c2abb73b
commit
35b88d50ca
22 files changed
+809
-166
No files matched your search
@@ -441,6 +441,74 @@ exception when others then
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- =============================================================================
|
||||
-- 11. submit_event_feedback: first submission +5, re-submit idempotent,
|
||||
-- ineligible contacts earn nothing.
|
||||
-- Self-contained fixtures (seed-independent) — everything rolls back.
|
||||
-- =============================================================================
|
||||
do $$
|
||||
declare
|
||||
v_event uuid;
|
||||
v_before integer;
|
||||
v_after integer;
|
||||
v_earned integer;
|
||||
v_count integer;
|
||||
v_ok boolean;
|
||||
v_msg text;
|
||||
begin
|
||||
v_event := (select id from public.events where is_active limit 1);
|
||||
if v_event is null then
|
||||
insert into test_results values ('event feedback (11)', false, 'no active event');
|
||||
return;
|
||||
end if;
|
||||
|
||||
insert into public.contacts (email, full_name) values
|
||||
('[email protected]', 'Effie Probe'),
|
||||
('[email protected]', 'Stella Probe');
|
||||
insert into public.registrations (event_id, contact_email, type) values
|
||||
(v_event, '[email protected]', 'attendee'),
|
||||
(v_event, '[email protected]', 'staff');
|
||||
|
||||
-- First submission (attendee) -> +5.
|
||||
perform set_user('[email protected]');
|
||||
select points into v_before from public.registrations
|
||||
where contact_email = '[email protected]' and event_id = v_event;
|
||||
select earned into v_earned from public.submit_event_feedback(4, 'Well organised');
|
||||
select points into v_after from public.registrations
|
||||
where contact_email = '[email protected]' and event_id = v_event;
|
||||
v_ok := (v_earned = 5 and v_after = v_before + 5);
|
||||
v_msg := format('expected earned=5/points=%s, got earned=%s points=%s', v_before + 5, v_earned, v_after);
|
||||
insert into test_results values ('event feedback first submit earns +5', v_ok, case when v_ok then null else v_msg end);
|
||||
|
||||
-- Edit the answer: row updates, no second award.
|
||||
select earned into v_earned from public.submit_event_feedback(5, 'Minor tweaks');
|
||||
select points into v_after from public.registrations
|
||||
where contact_email = '[email protected]' and event_id = v_event;
|
||||
v_ok := (v_earned = 0 and v_after = v_before + 5);
|
||||
v_msg := format('expected earned=0/points=%s, got earned=%s points=%s', v_before + 5, v_earned, v_after);
|
||||
insert into test_results values ('event feedback edit earns nothing', v_ok, case when v_ok then null else v_msg end);
|
||||
|
||||
-- Exactly one +5 'feedback' points_log row.
|
||||
select count(*) into v_count from public.points_log
|
||||
where event_id = v_event and contact_email = '[email protected]'
|
||||
and category = 'feedback' and delta = 5;
|
||||
v_ok := (v_count = 1);
|
||||
insert into test_results values ('event feedback logs one +5 row', v_ok,
|
||||
case when v_ok then null else 'expected 1 points_log row, got ' || v_count end);
|
||||
|
||||
-- Staff registration -> eligible check fails, earns nothing, no log row.
|
||||
perform set_user('[email protected]');
|
||||
select earned into v_earned from public.submit_event_feedback(5, 'Staff view');
|
||||
select count(*) into v_count from public.points_log
|
||||
where event_id = v_event and contact_email = '[email protected]';
|
||||
v_ok := (v_earned = 0 and v_count = 0);
|
||||
v_msg := format('expected earned=0/log=0, got earned=%s log=%s', v_earned, v_count);
|
||||
insert into test_results values ('event feedback staff earns nothing', v_ok, case when v_ok then null else v_msg end);
|
||||
exception when others then
|
||||
insert into test_results values ('event feedback (11)', false, 'error: ' || sqlerrm);
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- =============================================================================
|
||||
-- Summary (printed BEFORE the rollback, since the temp table is dropped by it)
|
||||
-- =============================================================================
|
||||
|
||||
Reference in new issue
Block a user