feat: add comprehensive test suite for recent backend changes

This commit is contained in:
2026-05-29 17:13:16 +01:00
parent 9ba4949d37
commit 9d8015f1b8
5 changed files with 339 additions and 68 deletions
@@ -347,3 +347,47 @@ func TestContact_ReturnsInfo(t *testing.T) {
t.Error("expected role in response")
}
}
// TestServices_Create_PatchTest verifies that creating a service with
// patch_test_duration_hours > 0 automatically creates a patch test record.
func TestServices_Create_PatchTest(t *testing.T) {
resetTestData(t)
adminToken := jwt.GenerateAdminToken()
handler := http.HandlerFunc(CreateServiceHandler)
req := CreateServiceRequest{
Name: "Lash Lift",
Description: strPtr("Lash lift service"),
Price: 50.00,
DurationMinutes: 60,
MinimumAgeRequired: 18,
PatchTestDurationHours: 48,
}
reqBody, _ := json.Marshal(req)
httpreq := httptest.NewRequest("POST", "/api/admin/services", bytes.NewReader(reqBody))
httpreq.Header.Set("Content-Type", "application/json")
httpreq.Header.Set("Authorization", "Bearer "+adminToken)
w := httptest.NewRecorder()
handler.ServeHTTP(w, httpreq)
if w.Code != http.StatusCreated {
t.Fatalf("expected status 201, got %d. body: %s", w.Code, w.Body.String())
}
var count int
err := db.DB.QueryRow(context.Background(),
"SELECT COUNT(*) FROM patch_tests WHERE notice_duration_hours = 48").Scan(&count)
if err != nil {
t.Fatalf("failed to query patch_tests: %v", err)
}
if count != 1 {
t.Errorf("expected 1 patch test record, got %d", count)
}
}
func strPtr(s string) *string {
return &s
}