Moved properties from Volunteer to Participant.
This commit is contained in:
parent
fcf5bf1f34
commit
7d56ef2f33
9 changed files with 200 additions and 428 deletions
|
|
@ -58,27 +58,27 @@ func TestPublicSignup(t *testing.T) {
|
|||
if err != nil || vol == nil {
|
||||
t.Fatal("volunteer not created")
|
||||
}
|
||||
if vol.PreferredName != "Titania" {
|
||||
t.Errorf("preferred_name = %q, want Titania", vol.PreferredName)
|
||||
if vol.Name != "Titania" {
|
||||
t.Errorf("name = %q, want Titania", vol.Name)
|
||||
}
|
||||
if vol.Pronouns != "she/they" {
|
||||
t.Errorf("pronouns = %q, want she/they", vol.Pronouns)
|
||||
}
|
||||
if vol.ConfirmationToken == nil || *vol.ConfirmationToken == "" {
|
||||
t.Error("expected confirmation token to be set")
|
||||
}
|
||||
if vol.EmailConfirmed {
|
||||
t.Error("should not be confirmed yet")
|
||||
}
|
||||
|
||||
// Participant should be auto-created and linked
|
||||
if vol.ParticipantID == nil {
|
||||
if vol.ParticipantID == 0 {
|
||||
t.Fatal("expected participant to be linked")
|
||||
}
|
||||
p, _ := app.getParticipant(*vol.ParticipantID)
|
||||
p, _ := app.getParticipant(vol.ParticipantID)
|
||||
if p == nil {
|
||||
t.Fatal("linked participant not found")
|
||||
}
|
||||
if p.ConfirmationToken == nil || *p.ConfirmationToken == "" {
|
||||
t.Error("expected confirmation token on participant")
|
||||
}
|
||||
if p.Email != "titania@example.com" {
|
||||
t.Errorf("participant email = %q, want titania@example.com", p.Email)
|
||||
}
|
||||
|
|
@ -105,8 +105,8 @@ func TestPublicSignupAutoMatchParticipant(t *testing.T) {
|
|||
if vol == nil {
|
||||
t.Fatal("volunteer not created")
|
||||
}
|
||||
if vol.ParticipantID == nil || *vol.ParticipantID != existing.ID {
|
||||
t.Errorf("expected volunteer linked to existing participant %d, got %v", existing.ID, vol.ParticipantID)
|
||||
if vol.ParticipantID == 0 || vol.ParticipantID != existing.ID {
|
||||
t.Errorf("expected volunteer linked to existing participant %d, got %d", existing.ID, vol.ParticipantID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,12 +200,8 @@ func TestConfirmEmail(t *testing.T) {
|
|||
mux := testMux(app)
|
||||
|
||||
token := "abc123def456"
|
||||
app.createVolunteer(Volunteer{
|
||||
Name: "Titania",
|
||||
PreferredName: "Titania",
|
||||
Email: "titania@example.com",
|
||||
ConfirmationToken: &token,
|
||||
})
|
||||
p, _ := app.createParticipant(Participant{PreferredName: "Titania", Email: "titania@example.com", ConfirmationToken: &token})
|
||||
app.createVolunteer(Volunteer{ParticipantID: p.ID})
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, testRequest("POST", "/api/public/confirm", map[string]any{"token": token}))
|
||||
|
|
@ -217,12 +213,13 @@ func TestConfirmEmail(t *testing.T) {
|
|||
t.Errorf("expected confirmed, got %v", result["status"])
|
||||
}
|
||||
|
||||
// Verify volunteer is confirmed
|
||||
// Verify participant is email confirmed
|
||||
vol, _ := app.getVolunteerByEmail("titania@example.com")
|
||||
if vol == nil || !vol.EmailConfirmed {
|
||||
t.Error("volunteer should be email confirmed")
|
||||
t.Error("volunteer should show email confirmed via participant")
|
||||
}
|
||||
if vol.ConfirmationToken != nil {
|
||||
updatedP, _ := app.getParticipant(p.ID)
|
||||
if updatedP.ConfirmationToken != nil {
|
||||
t.Error("confirmation token should be cleared after confirmation")
|
||||
}
|
||||
}
|
||||
|
|
@ -247,12 +244,8 @@ func TestConfirmEmailAlreadyConfirmed(t *testing.T) {
|
|||
mux := testMux(app)
|
||||
|
||||
token := "abc123def456"
|
||||
app.createVolunteer(Volunteer{
|
||||
Name: "Titania",
|
||||
PreferredName: "Titania",
|
||||
Email: "titania@example.com",
|
||||
ConfirmationToken: &token,
|
||||
})
|
||||
p, _ := app.createParticipant(Participant{PreferredName: "Titania", Email: "titania@example.com", ConfirmationToken: &token})
|
||||
app.createVolunteer(Volunteer{ParticipantID: p.ID})
|
||||
|
||||
// Confirm first time
|
||||
w := httptest.NewRecorder()
|
||||
|
|
@ -277,15 +270,9 @@ func TestConfirmEmailWithSignupsOpen(t *testing.T) {
|
|||
app.db.Exec(`INSERT OR REPLACE INTO config (key, value) VALUES ('shift_signups_open', 'true')`)
|
||||
app.baseURL = "https://example.com"
|
||||
|
||||
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,
|
||||
})
|
||||
participant, _ := app.createParticipant(Participant{PreferredName: "Titania", Email: "titania@example.com", ConfirmationToken: &token})
|
||||
app.createVolunteer(Volunteer{ParticipantID: participant.ID})
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, testRequest("POST", "/api/public/confirm", map[string]any{"token": token}))
|
||||
|
|
@ -327,10 +314,10 @@ func TestPublicSignupTicketNameDoesNotOverwritePreferredName(t *testing.T) {
|
|||
}
|
||||
|
||||
vol, _ := app.getVolunteerByEmail("titania@example.com")
|
||||
if vol == nil || vol.ParticipantID == nil {
|
||||
if vol == nil || vol.ParticipantID == 0 {
|
||||
t.Fatal("volunteer/participant not created")
|
||||
}
|
||||
p, _ := app.getParticipant(*vol.ParticipantID)
|
||||
p, _ := app.getParticipant(vol.ParticipantID)
|
||||
if p == nil {
|
||||
t.Fatal("participant not found")
|
||||
}
|
||||
|
|
@ -349,15 +336,9 @@ func TestConfirmEmailAssignsKioskCode(t *testing.T) {
|
|||
app.db.Exec(`INSERT OR REPLACE INTO config (key, value) VALUES ('shift_signups_open', 'true')`)
|
||||
app.baseURL = "https://example.com"
|
||||
|
||||
participant, _ := app.createParticipant(Participant{PreferredName: "Titania", TicketName: "Titania Fairweather", Email: "titania@example.com"})
|
||||
token := "abc123def456"
|
||||
app.createVolunteer(Volunteer{
|
||||
Name: "Titania",
|
||||
PreferredName: "Titania",
|
||||
Email: "titania@example.com",
|
||||
ParticipantID: &participant.ID,
|
||||
ConfirmationToken: &token,
|
||||
})
|
||||
participant, _ := app.createParticipant(Participant{PreferredName: "Titania", TicketName: "Titania Fairweather", Email: "titania@example.com", ConfirmationToken: &token})
|
||||
app.createVolunteer(Volunteer{ParticipantID: participant.ID})
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, testRequest("POST", "/api/public/confirm", map[string]any{"token": token}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue