Large manual tests corruption fix
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
//go:build test
|
||||
// +build test
|
||||
|
||||
package admin
|
||||
|
||||
// Package admin contains tests for admin service management endpoints.
|
||||
//
|
||||
// Test Coverage:
|
||||
@@ -10,11 +12,6 @@
|
||||
// - DeleteServiceHandler: DELETE /api/admin/services/{id} - Soft delete service
|
||||
//
|
||||
// Authentication: All endpoints require admin role (403 for non-admins).
|
||||
package admin
|
||||
//go:build test
|
||||
// +build test
|
||||
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -30,6 +27,7 @@ import (
|
||||
// TestAdminServices_Create verifies that an admin can create a new service
|
||||
// with name, description, price, duration, and minimum age requirements. The new
|
||||
// service is active by default and stored in the database.
|
||||
func TestAdminServices_Create(t *testing.T) {
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -76,13 +74,14 @@ import (
|
||||
|
||||
// TestAdminServices_List tests that an admin can retrieve all services,
|
||||
// including inactive ones. This is useful for managing the full service catalog.
|
||||
func TestAdminServices_List(t *testing.T) {
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
// Insert test services
|
||||
_, err := db.DB.Exec(context.Background(), `
|
||||
INSERT INTO services (name, description, price, duration_minutes, is_active, minimum_age_required)
|
||||
VALUES
|
||||
VALUES
|
||||
('Manicure', 'Basic manicure', 25.00, 30, true, 0),
|
||||
('Pedicure', 'Basic pedicure', 30.00, 45, false, 0),
|
||||
('Gel Polish', 'Gel polish service', 40.00, 60, true, 16)
|
||||
@@ -127,6 +126,7 @@ import (
|
||||
// TestAdminServices_Toggle verifies that an admin can toggle a service's
|
||||
// active status on/off. This is used to temporarily disable a service without
|
||||
// deleting it from the system.
|
||||
func TestAdminServices_Toggle(t *testing.T) {
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -177,6 +177,7 @@ import (
|
||||
// TestAdminServices_Delete tests that an admin can soft-delete a service
|
||||
// by setting is_active to false. The service record remains but is hidden from
|
||||
// customers.
|
||||
func TestAdminServices_Delete(t *testing.T) {
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -212,6 +213,7 @@ import (
|
||||
// TestAdminServices_NonAdmin verifies that non-admin users receive HTTP 403
|
||||
// Forbidden when attempting to create, list, toggle, or delete services. This
|
||||
// ensures proper role-based access control.
|
||||
func TestAdminServices_NonAdmin(t *testing.T) {
|
||||
cleanup := setupTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
@@ -227,11 +229,11 @@ import (
|
||||
// Test CREATE - should get 403 when using middleware
|
||||
createHandler := mw.RequireAdmin(http.HandlerFunc(services.CreateServiceHandler))
|
||||
createReq := services.CreateServiceRequest{
|
||||
Name: "Test Service",
|
||||
Description: stringPtr("Test"),
|
||||
Price: 50.00,
|
||||
DurationMinutes: 60,
|
||||
MinimumAgeRequired: 16,
|
||||
Name: "Test Service",
|
||||
Description: stringPtr("Test"),
|
||||
Price: 50.00,
|
||||
DurationMinutes: 60,
|
||||
MinimumAgeRequired: 16,
|
||||
}
|
||||
w := makeUserRequest(createHandler, "POST", "/api/admin/services", createReq)
|
||||
if w.Code != http.StatusForbidden {
|
||||
|
||||
Reference in New Issue
Block a user