Cleaned up old Attendees model. Updated tests.
This commit is contained in:
parent
64ce97c74d
commit
d804a48b49
9 changed files with 75 additions and 285 deletions
|
|
@ -6,14 +6,14 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestAttendeesListCreateDelete(t *testing.T) {
|
||||
func TestParticipantsListCreateDelete(t *testing.T) {
|
||||
app := testApp(t)
|
||||
admin := testAdminUser(t, app)
|
||||
token := testToken(t, app, admin)
|
||||
mux := testMux(app)
|
||||
|
||||
// Create
|
||||
req := testAuthRequest("POST", "/api/attendees", map[string]string{"name": "Titania"}, token)
|
||||
req := testAuthRequest("POST", "/api/participants", map[string]string{"preferred_name": "Titania", "email": "titania@example.com"}, token)
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusCreated {
|
||||
|
|
@ -23,20 +23,20 @@ func TestAttendeesListCreateDelete(t *testing.T) {
|
|||
id := created["id"].(float64)
|
||||
|
||||
// List
|
||||
req = testAuthRequest("GET", "/api/attendees", nil, token)
|
||||
req = testAuthRequest("GET", "/api/participants", nil, token)
|
||||
w = httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("list: status = %d", w.Code)
|
||||
}
|
||||
list := parseJSON(t, w)
|
||||
attendees := list["attendees"].([]any)
|
||||
if len(attendees) != 1 {
|
||||
t.Errorf("list: got %d, want 1", len(attendees))
|
||||
participants := list["participants"].([]any)
|
||||
if len(participants) != 1 {
|
||||
t.Errorf("list: got %d, want 1", len(participants))
|
||||
}
|
||||
|
||||
// Delete
|
||||
req = testAuthRequest("DELETE", "/api/attendees/"+itoa(int(id)), nil, token)
|
||||
req = testAuthRequest("DELETE", "/api/participants/"+itoa(int(id)), nil, token)
|
||||
w = httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusNoContent {
|
||||
|
|
@ -44,66 +44,66 @@ func TestAttendeesListCreateDelete(t *testing.T) {
|
|||
}
|
||||
|
||||
// List again — should be empty
|
||||
req = testAuthRequest("GET", "/api/attendees", nil, token)
|
||||
req = testAuthRequest("GET", "/api/participants", nil, token)
|
||||
w = httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
list = parseJSON(t, w)
|
||||
if a2, ok := list["attendees"].([]any); ok && len(a2) != 0 {
|
||||
t.Errorf("after delete: got %d, want 0", len(a2))
|
||||
if ps, ok := list["participants"].([]any); ok && len(ps) != 0 {
|
||||
t.Errorf("after delete: got %d, want 0", len(ps))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckInAttendeeHandler(t *testing.T) {
|
||||
func TestCheckInTicketHandler(t *testing.T) {
|
||||
app := testApp(t)
|
||||
admin := testAdminUser(t, app)
|
||||
token := testToken(t, app, admin)
|
||||
mux := testMux(app)
|
||||
|
||||
app.createAttendee(Attendee{Name: "Oberon"})
|
||||
app.db.Exec(`UPDATE attendees SET party_size = 3 WHERE id = 1`)
|
||||
p, _ := app.createParticipant(Participant{PreferredName: "Oberon", Email: "oberon@example.com"})
|
||||
tk, _ := app.createTicket(Ticket{ParticipantID: &p.ID, Name: "Oberon", Source: "manual"})
|
||||
|
||||
// Check in 1
|
||||
req := testAuthRequest("POST", "/api/attendees/1/checkin", map[string]int{"count": 1}, token)
|
||||
req := testAuthRequest("POST", "/api/tickets/"+itoa(tk.ID)+"/checkin", nil, token)
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("checkin: status = %d\nbody: %s", w.Code, w.Body.String())
|
||||
}
|
||||
result := parseJSON(t, w)
|
||||
attendee := result["attendee"].(map[string]any)
|
||||
if attendee["checked_in_count"] != float64(1) {
|
||||
t.Errorf("checked_in_count = %v, want 1", attendee["checked_in_count"])
|
||||
ticket := result["ticket"].(map[string]any)
|
||||
if ticket["checked_in_at"] == nil {
|
||||
t.Error("checked_in_at should be set after check-in")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGateRoleCanCheckIn(t *testing.T) {
|
||||
func TestGatekeeperRoleCanCheckIn(t *testing.T) {
|
||||
app := testApp(t)
|
||||
gate := testUserWithRole(t, app, "gateuser", "gatekeeper", []int{})
|
||||
token := testToken(t, app, gate)
|
||||
mux := testMux(app)
|
||||
|
||||
app.createAttendee(Attendee{Name: "Puck"})
|
||||
p, _ := app.createParticipant(Participant{PreferredName: "Puck", Email: "puck@example.com"})
|
||||
tk, _ := app.createTicket(Ticket{ParticipantID: &p.ID, Name: "Puck", Source: "manual"})
|
||||
|
||||
req := testAuthRequest("POST", "/api/attendees/1/checkin", nil, token)
|
||||
req := testAuthRequest("POST", "/api/tickets/"+itoa(tk.ID)+"/checkin", nil, token)
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Errorf("gate checkin: status = %d", w.Code)
|
||||
t.Errorf("gatekeeper checkin: status = %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGateRoleCannotDelete(t *testing.T) {
|
||||
func TestGatekeeperRoleCannotDelete(t *testing.T) {
|
||||
app := testApp(t)
|
||||
gate := testUserWithRole(t, app, "gateuser", "gatekeeper", []int{})
|
||||
token := testToken(t, app, gate)
|
||||
mux := testMux(app)
|
||||
|
||||
app.createAttendee(Attendee{Name: "Puck"})
|
||||
p, _ := app.createParticipant(Participant{PreferredName: "Puck", Email: "puck@example.com"})
|
||||
|
||||
req := testAuthRequest("DELETE", "/api/attendees/1", nil, token)
|
||||
req := testAuthRequest("DELETE", "/api/participants/"+itoa(p.ID), nil, token)
|
||||
w := httptest.NewRecorder()
|
||||
mux.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusForbidden {
|
||||
t.Errorf("gate delete: status = %d, want 403", w.Code)
|
||||
t.Errorf("gatekeeper delete: status = %d, want 403", w.Code)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue