refactor(backend): replace resetTestData with SetupTestDB and add new tests

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>
This commit is contained in:
2026-06-20 16:57:36 +01:00
co-authored by Sisyphus
parent 9c68918c20
commit b03c4f6247
36 changed files with 1735 additions and 859 deletions
+6 -5
View File
@@ -20,6 +20,7 @@ import (
"testing"
"crussell/db"
"crussell/testutils"
"crussell/handlers/services"
"crussell/mw"
)
@@ -28,7 +29,7 @@ import (
// 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) {
resetTestData(t)
testutils.SetupTestDB(t)
// Create admin user in DB first
_, err := db.DB.Exec(context.Background(), `
@@ -74,7 +75,7 @@ func TestAdminServices_Create(t *testing.T) {
// 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) {
resetTestData(t)
testutils.SetupTestDB(t)
// Insert test services
_, err := db.DB.Exec(context.Background(), `
@@ -125,7 +126,7 @@ func TestAdminServices_List(t *testing.T) {
// active status on/off. This is used to temporarily disable a service without
// deleting it from the system.
func TestAdminServices_Toggle(t *testing.T) {
resetTestData(t)
testutils.SetupTestDB(t)
// Create a service
var serviceID string
@@ -175,7 +176,7 @@ func TestAdminServices_Toggle(t *testing.T) {
// by setting is_active to false. The service record remains but is hidden from
// customers.
func TestAdminServices_Delete(t *testing.T) {
resetTestData(t)
testutils.SetupTestDB(t)
// Create a service
var serviceID string
@@ -210,7 +211,7 @@ func TestAdminServices_Delete(t *testing.T) {
// Forbidden when attempting to create, list, toggle, or delete services. This
// ensures proper role-based access control.
func TestAdminServices_NonAdmin(t *testing.T) {
resetTestData(t)
testutils.SetupTestDB(t)
// Create regular user in DB
_, err := db.DB.Exec(context.Background(), `