refactor: optimize test DB setup — TestMain per package, truncate-only between tests

- Add TestMain to all 10 test packages (schema DROP+CREATE runs once per package)
- Convert per-test setupTestDB to resetTestData (TRUNCATE only, ~60% faster)
- Add 3 missing tables to TruncateTables (booking_edit_requests, exceptional_group_applications, business_settings)
- Remove dead truncateDiscountTables helper
- Consolidate discount_test.go into package bookings (was external test package)
- Update testutils.SetupTestDB to truncate-only
- Fix unused imports across user, bookings, and handlers packages
- Verify: 286 passing, 2 skipped, 0 failures with -count=2 (no state leakage)
This commit is contained in:
2026-05-10 17:27:51 +01:00
parent 83c62ffb97
commit e73c96b653
26 changed files with 554 additions and 920 deletions
@@ -59,8 +59,7 @@ func makeAdminReserveRequest(handler http.Handler, body interface{}, adminID str
// create a walk-in reservation with a valid duration. The test verifies
// the reservation is created in the database with the correct duration.
func TestAdminReserveSlot_WalkIn_Success(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)
@@ -117,8 +116,7 @@ func TestAdminReserveSlot_WalkIn_Success(t *testing.T) {
// create a call-in reservation with valid service IDs. The test verifies
// the reservation duration matches the service duration.
func TestAdminReserveSlot_CallIn_Success(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)
@@ -194,8 +192,7 @@ func TestAdminReserveSlot_CallIn_Success(t *testing.T) {
// TestAdminReserveSlot_WalkIn_MissingDuration tests that walk-in reservations
// fail with HTTP 400 when duration_minutes is missing or zero.
func TestAdminReserveSlot_WalkIn_MissingDuration(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)
@@ -233,8 +230,7 @@ func TestAdminReserveSlot_WalkIn_MissingDuration(t *testing.T) {
// TestAdminReserveSlot_CallIn_MissingServices tests that call-in reservations
// fail with HTTP 400 when service_ids is empty.
func TestAdminReserveSlot_CallIn_MissingServices(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)
@@ -275,8 +271,7 @@ func TestAdminReserveSlot_CallIn_MissingServices(t *testing.T) {
// TestAdminReserveSlot_InvalidReservationType tests that reservations
// fail with HTTP 400 when reservation_type is invalid.
func TestAdminReserveSlot_InvalidReservationType(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)
@@ -313,8 +308,7 @@ func TestAdminReserveSlot_InvalidReservationType(t *testing.T) {
// TestAdminReserveSlot_SlotOverlap tests that a reservation fails
// with HTTP 409 when the slot overlaps with an existing booking.
func TestAdminReserveSlot_SlotOverlap(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)
@@ -386,8 +380,7 @@ func TestAdminReserveSlot_SlotOverlap(t *testing.T) {
// TestAdminReserveSlot_ReplacesExisting tests that reserving twice
// on the same admin replaces the previous reservation.
func TestAdminReserveSlot_ReplacesExisting(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)
@@ -473,8 +466,7 @@ func TestAdminReserveSlot_ReplacesExisting(t *testing.T) {
// TestAdminReserveSlot_WalkIn_PastStart tests that walk-in reservations
func TestAdminReserveSlot_WalkIn_PastStart(t *testing.T) {
cleanup := setupTestDB(t)
defer cleanup()
resetTestData(t)
seedDefaultWorkingHours(t)