test(admin): add settings validation, public info, and out_of_hours tests

Add comprehensive tests for business settings validation (name length, phone, email, VAT number, URL, voucher type, VAT rate). Add GetPublicBusinessInfo tests verifying correct JSON shape. Add out_of_hours field search tests for admin booking search.

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-22 17:05:52 +01:00
co-authored by Sisyphus
parent 280b05bd34
commit 9d70d42bd4
2 changed files with 1017 additions and 91 deletions
+141
View File
@@ -1444,6 +1444,147 @@ func TestAdminBookings_Search_MultipleResults(t *testing.T) {
}
}
// =============================================================================
// SearchAdminBookingsHandler — out_of_hours field
// =============================================================================
func TestAdminBookings_Search_OutOfHoursField(t *testing.T) {
t.Parallel()
ctx, tx := testutils.SetupTestTx(t)
_, 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)
}
futureTime := time.Now().Add(72 * time.Hour).Truncate(time.Second)
var bookingID string
err = tx.QueryRow(ctx, `
INSERT INTO bookings (user_id, start_time, status, out_of_hours, notes)
VALUES ($1, $2, 'confirmed', true, 'OutOfHoursSearchTest')
RETURNING id
`, userID, futureTime).Scan(&bookingID)
if err != nil {
t.Fatalf("failed to create out-of-hours booking: %v", err)
}
_, err = tx.Exec(ctx, `
INSERT INTO booking_services (booking_id, service_id)
VALUES ($1, $2)
`, bookingID, serviceID)
if err != nil {
t.Fatalf("failed to link service: %v", err)
}
handler := http.HandlerFunc(bookings.SearchAdminBookingsHandler)
w := makeAdminRequest(handler, "GET", "/api/admin/bookings/search?q=OutOfHoursSearchTest", nil, ctx)
if w.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d. body: %s", w.Code, w.Body.String())
}
var resp bookings.BookingListResponse
if err := parseResponseBody(w, &resp); err != nil {
t.Fatalf("failed to parse response: %v", err)
}
if len(resp.Bookings) == 0 {
t.Fatal("expected at least 1 booking in search results")
}
var found bool
for _, b := range resp.Bookings {
if b.ID == bookingID {
if !b.OutOfHours {
t.Error("expected out_of_hours=true for the out-of-hours booking in search results")
}
found = true
break
}
}
if !found {
t.Error("expected out-of-hours booking to appear in search results")
}
}
func TestAdminBookings_Search_OutOfHoursFalseByDefault(t *testing.T) {
t.Parallel()
ctx, tx := testutils.SetupTestTx(t)
_, 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)
}
var bookingID string
err = tx.QueryRow(ctx, `
INSERT INTO bookings (user_id, start_time, status, notes)
VALUES ($1, $2, 'confirmed', 'NormalSearchBooking')
RETURNING id
`, userID, time.Now().Add(72*time.Hour).Truncate(time.Second)).Scan(&bookingID)
if err != nil {
t.Fatalf("failed to create booking: %v", err)
}
_, err = tx.Exec(ctx, `
INSERT INTO booking_services (booking_id, service_id)
VALUES ($1, $2)
`, bookingID, serviceID)
if err != nil {
t.Fatalf("failed to link service: %v", err)
}
handler := http.HandlerFunc(bookings.SearchAdminBookingsHandler)
w := makeAdminRequest(handler, "GET", "/api/admin/bookings/search?q=NormalSearchBooking", nil, ctx)
if w.Code != http.StatusOK {
t.Fatalf("expected status 200, got %d. body: %s", w.Code, w.Body.String())
}
var resp bookings.BookingListResponse
if err := parseResponseBody(w, &resp); err != nil {
t.Fatalf("failed to parse response: %v", err)
}
if len(resp.Bookings) == 0 {
t.Fatal("expected at least 1 booking in search results")
}
var found bool
for _, b := range resp.Bookings {
if b.ID == bookingID {
if b.OutOfHours {
t.Error("expected out_of_hours=false (default) for normal booking in search results")
}
found = true
break
}
}
if !found {
t.Error("expected normal booking to appear in search results")
}
}
// =============================================================================
// Admin List Edit Requests Tests
// =============================================================================