Files
Crussell/backend/handlers/admin/bookings_fields_test.go
T
popertotsandSisyphus 510828c924
CI / Go vulnerabilities (push) Successful in 1m10s
CI / Build & Vet (push) Successful in 1m39s
CI / Frontend build (gate) (push) Successful in 1m42s
CI / Frontend QC (audit) (push) Successful in 56s
CI / Frontend QC (typecheck) (push) Successful in 1m36s
CI / Frontend QC (lint) (push) Successful in 1m51s
CI / Tests (prod) (push) Has been cancelled
CI / Tests (dev) (push) Has been cancelled
CI / Race (prod) (push) Has been cancelled
CI / Race (dev) (push) Has been cancelled
chore: run go fix for Go 1.26 modernization
106 files: interface{}→any, strings.Split→SplitSeq, CutPrefix/Cut, strings.Builder, slices.Contains, remove redundant // +build directives, gofmt import ordering and indentation.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-07-09 17:25:23 +01:00

72 lines
2.0 KiB
Go

//go:build test
package admin
import (
"context"
"net/http"
"testing"
"crussell/handlers/bookings"
"crussell/testutils"
"crussell/testutils/fixtures"
)
// TestAdminBookings_Get_EnrichedFields verifies that CreatedByName and User.DateOfBirth are populated.
func TestAdminBookings_Get_EnrichedFields(t *testing.T) {
t.Parallel()
ctx, tx := testutils.SetupTestTx(t)
adminID, err := fixtures.CreateTestAdminUser(tx)
if err != nil {
t.Fatalf("failed to create admin user: %v", err)
}
userID, err := fixtures.CreateTestUser(tx)
if err != nil {
t.Fatalf("failed to create test user: %v", err)
}
serviceID, err := fixtures.CreateTestService(tx)
if err != nil {
t.Fatalf("failed to create test service: %v", err)
}
bookingID, err := fixtures.CreateTestBooking(tx, userID, serviceID)
if err != nil {
t.Fatalf("failed to create test booking: %v", err)
}
dob := "1990-01-01"
_, err = tx.Exec(context.Background(), "UPDATE users SET date_of_birth = $1 WHERE id = $2", dob, userID)
if err != nil {
t.Fatalf("failed to update user dob: %v", err)
}
_, err = tx.Exec(context.Background(), "UPDATE bookings SET created_by = $1 WHERE id = $2", adminID, bookingID)
if err != nil {
t.Fatalf("failed to update booking created_by: %v", err)
}
handler := http.HandlerFunc(bookings.GetAdminBookingHandler)
w := makeAdminRequest(handler, "GET", "/api/admin/bookings/"+bookingID, nil, ctx)
if w.Code != http.StatusOK {
t.Errorf("expected status 200, got %d. body: %s", w.Code, w.Body.String())
}
var booking bookings.Booking
if err := parseResponseBody(w, &booking); err != nil {
t.Fatalf("failed to parse response: %v", err)
}
if booking.CreatedByName == nil {
t.Error("expected CreatedByName to be populated")
}
if booking.User == nil || booking.User.DateOfBirth == nil {
t.Error("expected User.DateOfBirth to be populated")
} else if *booking.User.DateOfBirth != dob {
t.Errorf("expected date_of_birth %s, got %s", dob, *booking.User.DateOfBirth)
}
}