Refactored ticket code into kiosk code.

This commit is contained in:
Pen Anderson 2026-03-05 16:31:08 -06:00
parent 72b245d6d6
commit 3eec81af7f
5 changed files with 110 additions and 190 deletions

View file

@ -301,17 +301,14 @@ func TestConfirmEmailWithSignupsOpen(t *testing.T) {
t.Error("expected kiosk_link when signups are open")
}
// Ticket for participant should now have a code
tickets, _ := app.listTickets(&participant.ID, "")
hasCode := false
for _, tk := range tickets {
if tk.Code != nil && *tk.Code != "" {
hasCode = true
break
}
// Volunteer should now have a kiosk_code, no stub ticket created.
vol, _ := app.getVolunteerByEmail("titania@example.com")
if vol == nil || vol.KioskCode == nil {
t.Error("volunteer should have a kiosk_code after confirm with signups open")
}
if !hasCode {
t.Error("participant should have a ticket with code after confirm with signups open")
tickets, _ := app.listTickets(&participant.ID, "")
if len(tickets) != 0 {
t.Errorf("expected no stub tickets, got %d", len(tickets))
}
}
@ -345,14 +342,13 @@ func TestPublicSignupTicketNameDoesNotOverwritePreferredName(t *testing.T) {
}
}
func TestConfirmEmailStubTicketHasName(t *testing.T) {
func TestConfirmEmailAssignsKioskCode(t *testing.T) {
app := testApp(t)
mux := testMux(app)
app.db.Exec(`INSERT OR REPLACE INTO config (key, value) VALUES ('shift_signups_open', 'true')`)
app.baseURL = "https://example.com"
// Volunteer with a ticket_name but no pre-existing ticket
participant, _ := app.createParticipant(Participant{PreferredName: "Titania", Email: "titania@example.com"})
token := "abc123def456"
app.createVolunteer(Volunteer{
@ -373,47 +369,19 @@ func TestConfirmEmailStubTicketHasName(t *testing.T) {
if result["status"] != "confirmed" {
t.Fatalf("expected confirmed, got %v", result["status"])
}
if result["kiosk_link"] == nil {
t.Error("expected kiosk_link in response when signups are open")
}
// Stub ticket should have been created with TicketName as its name
// Kiosk code should be on the volunteer record, not a stub ticket.
vol, _ := app.getVolunteerByEmail("titania@example.com")
if vol == nil || vol.KioskCode == nil {
t.Fatal("expected volunteer to have a kiosk_code")
}
// No stub ticket should have been created.
tickets, _ := app.listTickets(&participant.ID, "")
if len(tickets) == 0 {
t.Fatal("expected stub ticket to be created")
}
if tickets[0].Name != "Titania Fairweather" {
t.Errorf("stub ticket name = %q, want %q", tickets[0].Name, "Titania Fairweather")
}
}
func TestConfirmEmailStubTicketFallsBackToPreferredName(t *testing.T) {
app := testApp(t)
mux := testMux(app)
app.db.Exec(`INSERT OR REPLACE INTO config (key, value) VALUES ('shift_signups_open', 'true')`)
app.baseURL = "https://example.com"
// Volunteer with no ticket_name — stub should use preferred_name
participant, _ := app.createParticipant(Participant{PreferredName: "Titania", Email: "titania@example.com"})
token := "abc123def456"
app.createVolunteer(Volunteer{
Name: "Titania",
PreferredName: "Titania",
Email: "titania@example.com",
ParticipantID: &participant.ID,
ConfirmationToken: &token,
})
w := httptest.NewRecorder()
mux.ServeHTTP(w, testRequest("POST", "/api/public/confirm", map[string]any{"token": token}))
if w.Code != 200 {
t.Fatalf("expected 200, got %d", w.Code)
}
tickets, _ := app.listTickets(&participant.ID, "")
if len(tickets) == 0 {
t.Fatal("expected stub ticket to be created")
}
if tickets[0].Name != "Titania" {
t.Errorf("stub ticket name = %q, want %q (preferred_name fallback)", tickets[0].Name, "Titania")
if len(tickets) != 0 {
t.Errorf("expected no stub tickets, got %d", len(tickets))
}
}