Used preferred name in volunteer signup.
This commit is contained in:
parent
e7b25ea0c6
commit
ecfbfcd53e
2 changed files with 113 additions and 5 deletions
|
|
@ -315,6 +315,108 @@ func TestConfirmEmailWithSignupsOpen(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPublicSignupTicketNameDoesNotOverwritePreferredName(t *testing.T) {
|
||||
app := testApp(t)
|
||||
mux := testMux(app)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, testRequest("POST", "/api/public/signup", map[string]any{
|
||||
"preferred_name": "Titania",
|
||||
"ticket_name": "Titania Fairweather",
|
||||
"email": "titania@example.com",
|
||||
}))
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("expected 200, got %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
vol, _ := app.getVolunteerByEmail("titania@example.com")
|
||||
if vol == nil || vol.ParticipantID == nil {
|
||||
t.Fatal("volunteer/participant not created")
|
||||
}
|
||||
p, _ := app.getParticipant(*vol.ParticipantID)
|
||||
if p == nil {
|
||||
t.Fatal("participant not found")
|
||||
}
|
||||
if p.PreferredName != "Titania" {
|
||||
t.Errorf("participant preferred_name = %q, want %q (not ticket_name)", p.PreferredName, "Titania")
|
||||
}
|
||||
if vol.TicketName != "Titania Fairweather" {
|
||||
t.Errorf("vol.TicketName = %q, want %q", vol.TicketName, "Titania Fairweather")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfirmEmailStubTicketHasName(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{
|
||||
Name: "Titania",
|
||||
PreferredName: "Titania",
|
||||
TicketName: "Titania Fairweather",
|
||||
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)
|
||||
}
|
||||
result := parseJSON(t, w)
|
||||
if result["status"] != "confirmed" {
|
||||
t.Fatalf("expected confirmed, got %v", result["status"])
|
||||
}
|
||||
|
||||
// Stub ticket should have been created with TicketName as its name
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
func TestToggleShiftSignups(t *testing.T) {
|
||||
app := testApp(t)
|
||||
mux := testMux(app)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue