Files
Crussell/backend/handlers/admin/patch_tests_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

66 lines
1.7 KiB
Go

//go:build test
package admin
import (
"net/http"
"testing"
"crussell/testutils"
"crussell/testutils/fixtures"
)
func TestPatchTests_CRUD(t *testing.T) {
ctx, tx := testutils.SetupTestTx(t)
// Create a service to link
serviceID, err := fixtures.CreateTestService(tx)
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, ctx)
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, ctx)
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, ctx)
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, ctx)
if w.Code != http.StatusNoContent {
t.Fatalf("expected 204, got %d", w.Code)
}
}
func strPtr(s string) *string {
return &s
}