fix(points): welcome check-in awards +10; add Sessions view, AI connection test, silent reload
The front-desk check-in set checked_in and printed badges but awarded nothing, so the +10 depended on which check-in a person happened to get. Every award path was reviewed: - welcome_checkin awards +10 (category checkin) on a genuine first check-in and returns points + points_awarded; checkin_attendee and preview_welcome_checkin return points_awarded too. - set_registration_checked_in(false) deleted all checkin points while keeping the checkins rows, and switching back on awarded nothing -- one mistaken toggle destroyed those points permanently. ON now recomputes from the rows that still exist and awards only the shortfall: reversible, still unfarmable. - The staff/Admin/@appe.at exclusion stays (product decision) but is no longer silent: three-way points sheets in the scanner, "no points" with a tooltip in Registrations, and the Contacts points modal refuses to apply rather than letting adjust_points (void) no-op quietly. Also in this change: - admin silent refresh (5s poll + 500ms after writes) across all data views; Registrations patches in place so rows never slide under the cursor - Settings "Validate AI connection" via a new sidecar POST /llm-test verdict endpoint (never leaks the key, distinguishes "no usage block" from "off") - new Sessions view between Schedule and Activity: speakers, attendance, ratings, attendee filter, and one button that summarises every session with feedback (one request each, concurrency 3, UI blocked until all settle) - provider requests disable thinking through one shared body builder sending both reasoning_effort:"none" and chat_template_kwargs.enable_thinking SQL: 113 / 57 / 24 assertions (set_registration_checked_in section 3 was rewritten, it asserted the bug). Sidecar 34 unit tests. Full e2e 202 passed, 0 failed. Migration applied locally only -- not deployed.
This commit is contained in:
1 parent
96e4e6a6ea
commit
fdb6045966
35 files changed
+2778
-154
No files matched your search
@@ -51,6 +51,7 @@ declare
|
||||
talk_two uuid := 'a0150000-0000-0000-0000-000000000012';
|
||||
excluded_email text;
|
||||
feedback_result record;
|
||||
welcome_result record;
|
||||
begin
|
||||
perform pg_temp.assert_board((select bool_and(points = 0) from public.registrations
|
||||
where contact_email in ('[email protected]','[email protected]','[email protected]')), 'excluded inserts force zero');
|
||||
@@ -82,6 +83,42 @@ begin
|
||||
perform pg_temp.assert_board(
|
||||
(select not exists (select 1 from public.checkins where contact_email = '[email protected]')),
|
||||
'front-desk gate blocks session check-in');
|
||||
-- The front-desk welcome check-in is a real check-in: it awards the same +10
|
||||
-- as a session scan, once per person, and says whether it paid out.
|
||||
select * into welcome_result from public.welcome_checkin('[email protected]');
|
||||
perform pg_temp.assert_board(
|
||||
welcome_result.already = false and welcome_result.points_awarded
|
||||
and welcome_result.points = 10,
|
||||
'welcome check-in awards ten');
|
||||
perform pg_temp.assert_board(
|
||||
(select points = 10 and checked_in from public.registrations where contact_email = '[email protected]'),
|
||||
'welcome check-in lands on the registration');
|
||||
select * into welcome_result from public.welcome_checkin('[email protected]');
|
||||
perform pg_temp.assert_board(
|
||||
welcome_result.already and welcome_result.points = 10,
|
||||
'welcome check-in is idempotent');
|
||||
-- The gate is open for that attendee now, and both awards stack.
|
||||
perform public.checkin_attendee(talk_one, '[email protected]');
|
||||
perform pg_temp.assert_board(
|
||||
(select points = 20 from public.registrations where contact_email = '[email protected]'),
|
||||
'session scan after welcome totals twenty');
|
||||
-- Staff and Admin-domain contacts are welcomed too, but earn nothing and the
|
||||
-- RPC must not claim otherwise (that silence is what made points look broken).
|
||||
-- Clear the flag first so this exercises the award branch, not the
|
||||
-- already-checked-in shortcut.
|
||||
update public.registrations set checked_in = false
|
||||
where contact_email in ('[email protected]','[email protected]','[email protected]');
|
||||
foreach excluded_email in array array['[email protected]','[email protected]','[email protected]'] loop
|
||||
select * into welcome_result from public.welcome_checkin('LB-' || excluded_email);
|
||||
perform pg_temp.assert_board(
|
||||
welcome_result.already = false and welcome_result.points_awarded = false
|
||||
and welcome_result.points = 0,
|
||||
excluded_email || ' welcome awards zero and reports it');
|
||||
perform pg_temp.assert_board(
|
||||
(select checked_in from public.registrations where contact_email = excluded_email),
|
||||
excluded_email || ' is still marked checked in');
|
||||
end loop;
|
||||
perform set_config('request.jwt.claims', '{"email":"[email protected]"}', true);
|
||||
foreach excluded_email in array array['[email protected]','[email protected]','[email protected]'] loop
|
||||
perform set_config('request.jwt.claims', json_build_object('email', excluded_email)::text, true);
|
||||
select * into feedback_result from public.submit_feedback(talk_one, 5, 'Review');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
-- set_registration_checked_in: admin flips checked_in; un-checking removes the
|
||||
-- attendee's check-in points (and only those). Run inside a transaction that
|
||||
-- is rolled back, like the other suites.
|
||||
-- set_registration_checked_in: admin flips checked_in. Un-checking removes the
|
||||
-- attendee's check-in points (and only those); re-checking restores the points
|
||||
-- that the surviving check-in rows justify, without letting repeated clicks
|
||||
-- farm points. Run inside a transaction that is rolled back, like other suites.
|
||||
\set ON_ERROR_STOP on
|
||||
begin;
|
||||
|
||||
@@ -95,17 +96,97 @@ select pg_temp.assert_scr(
|
||||
'other attendee keeps their points');
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 3. Re-checking does not re-award anything.
|
||||
-- 3. Re-checking RESTORES the points the surviving check-in rows justify.
|
||||
-- Section 1 deleted the audit rows but the attendance records remain, so the
|
||||
-- old behaviour (award nothing, permanently) left this person 30 points short
|
||||
-- with no way back. Toggling on now recomputes from the rows: 10 per session
|
||||
-- check-in + 10 for the front desk.
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- Real attendance for scr-user: two sessions. Negative slot ids keep these
|
||||
-- fixtures out of every real event's schedule.
|
||||
insert into public.slots (id, event_id, name, slot_date, start_time, end_time, type)
|
||||
values (-152001, 'c7e10000-0000-0000-0000-000000000001', 'SCR Talk A', current_date, '09:00', '10:00', 'session');
|
||||
insert into public.sessions (id, event_id, slot_id, title)
|
||||
values ('c7e10000-0000-0000-0000-0000000000a1', 'c7e10000-0000-0000-0000-000000000001', -152001, 'SCR Session one'),
|
||||
('c7e10000-0000-0000-0000-0000000000a2', 'c7e10000-0000-0000-0000-000000000001', -152001, 'SCR Session two');
|
||||
insert into public.checkins (event_id, contact_email, session_id, staff_email)
|
||||
values ('c7e10000-0000-0000-0000-000000000001', '[email protected]', 'c7e10000-0000-0000-0000-0000000000a1', '[email protected]'),
|
||||
('c7e10000-0000-0000-0000-000000000001', '[email protected]', 'c7e10000-0000-0000-0000-0000000000a2', '[email protected]');
|
||||
|
||||
create temporary table scr_on as
|
||||
select * from public.set_registration_checked_in(
|
||||
'c7e10000-0000-0000-0000-000000000011', true);
|
||||
select pg_temp.assert_scr(
|
||||
(select checked_in = true and points_removed = 0 from scr_on),
|
||||
're-check-in awards no points');
|
||||
(select checked_in = true and points_removed = 0 and points_added = 30 from scr_on),
|
||||
're-check-in restores 30 points (2 sessions + front desk)');
|
||||
select pg_temp.assert_scr(
|
||||
(select points = 10 from public.registrations where qr_token = 'SCRQR-1'),
|
||||
'points unchanged after re-check-in');
|
||||
(select points = 40 from public.registrations where qr_token = 'SCRQR-1'),
|
||||
'points back to the pre-uncheck total after re-check-in');
|
||||
select pg_temp.assert_scr(
|
||||
(select points = 40 from public.leaderboard
|
||||
where event_id = 'c7e10000-0000-0000-0000-000000000001' and contact_email = '[email protected]'),
|
||||
'leaderboard synced back up to 40');
|
||||
|
||||
-- Toggling on again is idempotent: the award already matches what the rows
|
||||
-- justify, so repeated clicks cannot farm points.
|
||||
create temporary table scr_on2 as
|
||||
select * from public.set_registration_checked_in(
|
||||
'c7e10000-0000-0000-0000-000000000011', true);
|
||||
select pg_temp.assert_scr(
|
||||
(select points_added = 0 from scr_on2),
|
||||
'second re-check-in awards nothing (not farmable)');
|
||||
select pg_temp.assert_scr(
|
||||
(select points = 40 from public.registrations where qr_token = 'SCRQR-1'),
|
||||
'points unchanged by a repeat toggle on');
|
||||
|
||||
-- Full round trip is symmetric: off removes exactly what on gives back.
|
||||
create temporary table scr_off3 as
|
||||
select * from public.set_registration_checked_in(
|
||||
'c7e10000-0000-0000-0000-000000000011', false);
|
||||
select pg_temp.assert_scr(
|
||||
(select points_removed = 30 from scr_off3),
|
||||
'un-check-in again removes the same 30');
|
||||
create temporary table scr_on4 as
|
||||
select * from public.set_registration_checked_in(
|
||||
'c7e10000-0000-0000-0000-000000000011', true);
|
||||
select pg_temp.assert_scr(
|
||||
(select points_added = 30 from scr_on4),
|
||||
'and toggling on restores it once more');
|
||||
|
||||
-- Someone with attendance but no session check-ins at all earns only the
|
||||
-- front-desk +10 on the way back on (SCRQR-2 has connection points, no rows).
|
||||
create temporary table scr_on3 as
|
||||
select * from public.set_registration_checked_in(
|
||||
'c7e10000-0000-0000-0000-000000000012', true);
|
||||
select pg_temp.assert_scr(
|
||||
(select points_added = 10 from scr_on3),
|
||||
'front-desk-only restore awards 10');
|
||||
select pg_temp.assert_scr(
|
||||
(select points = 35 from public.registrations where qr_token = 'SCRQR-2'),
|
||||
'front-desk +10 lands on top of connection points');
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 3b. Staff and Admin-domain contacts stay at zero in both directions.
|
||||
-- -----------------------------------------------------------------------------
|
||||
insert into public.contacts (email, full_name, is_admin)
|
||||
values ('[email protected]', 'SCR Staff', false);
|
||||
insert into public.registrations (id, event_id, contact_email, type, qr_token, checked_in, points)
|
||||
values ('c7e10000-0000-0000-0000-000000000013', 'c7e10000-0000-0000-0000-000000000001',
|
||||
'[email protected]', 'staff', 'SCRQR-3', true, 0);
|
||||
insert into public.checkins (event_id, contact_email, session_id, staff_email)
|
||||
values ('c7e10000-0000-0000-0000-000000000001', '[email protected]', 'c7e10000-0000-0000-0000-0000000000a1', '[email protected]');
|
||||
create temporary table scr_staff_off as
|
||||
select * from public.set_registration_checked_in(
|
||||
'c7e10000-0000-0000-0000-000000000013', false);
|
||||
create temporary table scr_staff_on as
|
||||
select * from public.set_registration_checked_in(
|
||||
'c7e10000-0000-0000-0000-000000000013', true);
|
||||
select pg_temp.assert_scr(
|
||||
((select points_removed = 0 from scr_staff_off) and (select points_added = 0 from scr_staff_on)),
|
||||
'staff toggle moves no points in either direction');
|
||||
select pg_temp.assert_scr(
|
||||
(select points = 0 from public.registrations where qr_token = 'SCRQR-3'),
|
||||
'staff registration stays at zero');
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
-- 4. Unknown registration id is rejected.
|
||||
|
||||
Reference in new issue
Block a user