feat: migrate to dedicated patch test management
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
//go:build test
|
||||
// +build test
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"crussell/db"
|
||||
"crussell/testutils/fixtures"
|
||||
)
|
||||
|
||||
func TestPatchTests_CRUD(t *testing.T) {
|
||||
resetTestData(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},
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", bytes.NewReader(body))
|
||||
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}
|
||||
updateBody, _ := json.Marshal(updateReq)
|
||||
w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, bytes.NewReader(updateBody))
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Fatalf("expected 204, got %d", w.Code)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user