Migrate all test files from resetTestData(t) to testutils.SetupTestDB(t) for isolated per-package test databases. - Add new feature tests: name history assertions, referral discount preview, time blockers, email validation, GDPR export, loyalty manual redemption - Update existing tests to use batch queries and SetupTestDB - Remove test_helpers.go resetTestData infrastructure - Add comprehensive user profile tests (442 new lines) Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
//go:build test
|
|
// +build test
|
|
|
|
package admin
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"crussell/db"
|
|
"crussell/testutils"
|
|
"crussell/testutils/fixtures"
|
|
)
|
|
|
|
func TestPatchTests_CRUD(t *testing.T) {
|
|
testutils.SetupTestDB(t)
|
|
|
|
// Create a service to link
|
|
serviceID, err := fixtures.CreateTestService(db.DB)
|
|
if err != nil {
|
|
t.Fatalf("failed to create service: %v", err)
|
|
}
|
|
|
|
req := CreatePatchTestRequest{
|
|
Name: "Test Patch Test",
|
|
Description: strPtr("Description"),
|
|
NoticeDurationHours: 24,
|
|
ExpiryMonths: 6,
|
|
ServiceIDs: []string{serviceID},
|
|
}
|
|
w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", req)
|
|
if w.Code != http.StatusCreated {
|
|
t.Fatalf("expected 201, got %d", w.Code)
|
|
}
|
|
|
|
var created struct {
|
|
ID string `json:"id"`
|
|
}
|
|
parseResponseBody(w, &created)
|
|
|
|
w = makeAdminRequest(http.HandlerFunc(GetPatchTests), "GET", "/api/admin/patch-tests", nil)
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d", w.Code)
|
|
}
|
|
|
|
var list []PatchTest
|
|
parseResponseBody(w, &list)
|
|
if len(list) != 1 {
|
|
t.Errorf("expected 1 patch test, got %d", len(list))
|
|
}
|
|
|
|
newName := "Updated Name"
|
|
updateReq := UpdatePatchTestRequest{Name: &newName}
|
|
w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, updateReq)
|
|
if w.Code != http.StatusNoContent {
|
|
t.Fatalf("expected 204, got %d, body: %s", w.Code, w.Body.String())
|
|
}
|
|
|
|
w = makeAdminRequest(http.HandlerFunc(DeletePatchTest), "DELETE", "/api/admin/patch-tests/"+created.ID, nil)
|
|
if w.Code != http.StatusNoContent {
|
|
t.Fatalf("expected 204, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func strPtr(s string) *string {
|
|
return &s
|
|
}
|