Used preferred name in volunteer signup.
This commit is contained in:
parent
e7b25ea0c6
commit
ecfbfcd53e
2 changed files with 113 additions and 5 deletions
|
|
@ -69,11 +69,7 @@ func (app *App) handlePublicSignup(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find or create participant by email.
|
// Find or create participant by email.
|
||||||
name := body.PreferredName
|
participant, _, err := app.upsertParticipant(body.Email, body.PreferredName)
|
||||||
if body.TicketName != "" {
|
|
||||||
name = body.TicketName
|
|
||||||
}
|
|
||||||
participant, _, err := app.upsertParticipant(body.Email, name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
writeError(w, "internal error", http.StatusInternalServerError)
|
writeError(w, "internal error", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
@ -166,8 +162,13 @@ func (app *App) handleConfirmEmail(w http.ResponseWriter, r *http.Request) {
|
||||||
if len(tickets) > 0 {
|
if len(tickets) > 0 {
|
||||||
ticketID = tickets[0].ID
|
ticketID = tickets[0].ID
|
||||||
} else {
|
} else {
|
||||||
|
tkName := vol.TicketName
|
||||||
|
if tkName == "" {
|
||||||
|
tkName = vol.PreferredName
|
||||||
|
}
|
||||||
stub, err := app.createTicket(Ticket{
|
stub, err := app.createTicket(Ticket{
|
||||||
ParticipantID: vol.ParticipantID,
|
ParticipantID: vol.ParticipantID,
|
||||||
|
Name: tkName,
|
||||||
Source: "manual",
|
Source: "manual",
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
@ -228,8 +229,13 @@ func (app *App) openShiftSignups() {
|
||||||
if len(tickets) > 0 {
|
if len(tickets) > 0 {
|
||||||
ticketID = tickets[0].ID
|
ticketID = tickets[0].ID
|
||||||
} else {
|
} else {
|
||||||
|
tkName := v.TicketName
|
||||||
|
if tkName == "" {
|
||||||
|
tkName = v.PreferredName
|
||||||
|
}
|
||||||
stub, err := app.createTicket(Ticket{
|
stub, err := app.createTicket(Ticket{
|
||||||
ParticipantID: v.ParticipantID,
|
ParticipantID: v.ParticipantID,
|
||||||
|
Name: tkName,
|
||||||
Source: "manual",
|
Source: "manual",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func TestToggleShiftSignups(t *testing.T) {
|
||||||
app := testApp(t)
|
app := testApp(t)
|
||||||
mux := testMux(app)
|
mux := testMux(app)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue