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:
@@ -25,6 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"crussell/db"
|
||||
"crussell/testutils"
|
||||
"crussell/handlers/notifications"
|
||||
"crussell/handlers/today"
|
||||
"crussell/mw"
|
||||
@@ -33,7 +34,7 @@ import (
|
||||
// TestAdminToday_CurrentNext verifies that an admin can retrieve the currently
|
||||
// in-progress booking and the next upcoming booking for the dashboard.
|
||||
func TestAdminToday_CurrentNext(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Create test user
|
||||
var userID string
|
||||
@@ -108,7 +109,7 @@ func TestAdminToday_CurrentNext(t *testing.T) {
|
||||
// TestAdminToday_CurrentNext_ClosingTime verifies that the current-next endpoint
|
||||
// returns the closing time for today.
|
||||
func TestAdminToday_CurrentNext_ClosingTime(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Seed working hours for today (DB uses 0=Monday, 6=Sunday)
|
||||
todayWeekday := int(time.Now().Weekday())
|
||||
@@ -154,7 +155,7 @@ func TestAdminToday_CurrentNext_ClosingTime(t *testing.T) {
|
||||
// TestAdminToday_Appointments tests that an admin can get a list of all
|
||||
// bookings scheduled for today with their details.
|
||||
func TestAdminToday_Appointments(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Create test user
|
||||
var userID string
|
||||
@@ -229,7 +230,7 @@ func TestAdminToday_Appointments(t *testing.T) {
|
||||
// TestAdminToday_PendingApprovals verifies that an admin can see all pending
|
||||
// bookings that require approval/confirmation.
|
||||
func TestAdminToday_PendingApprovals(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Create test user
|
||||
var userID string
|
||||
@@ -311,7 +312,7 @@ func TestAdminToday_PendingApprovals(t *testing.T) {
|
||||
//
|
||||
// The transition happens silently in the background during GET requests, not via cron.
|
||||
func TestAdminToday_AutoTransition_ConfirmedToInProgress(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Create test user
|
||||
var userID string
|
||||
@@ -384,7 +385,7 @@ func TestAdminToday_AutoTransition_ConfirmedToInProgress(t *testing.T) {
|
||||
//
|
||||
// The transition happens silently in the background during GET requests, not via cron.
|
||||
func TestAdminToday_AutoTransition_InProgressToCompleted(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Create test user
|
||||
var userID string
|
||||
@@ -454,7 +455,7 @@ func TestAdminToday_AutoTransition_InProgressToCompleted(t *testing.T) {
|
||||
// TestAdminToday_NoAutoTransition_BeforeStartTime verifies that a confirmed
|
||||
// booking that hasn't started yet is NOT transitioned to in_progress.
|
||||
func TestAdminToday_NoAutoTransition_BeforeStartTime(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Create test user
|
||||
var userID string
|
||||
@@ -523,7 +524,7 @@ func TestAdminToday_NoAutoTransition_BeforeStartTime(t *testing.T) {
|
||||
// TestAdminToday_AutoTransition_CurrentNextHandler verifies that auto-transition
|
||||
// also works when calling GetCurrentAndNextHandler (not just appointments handler)
|
||||
func TestAdminToday_AutoTransition_CurrentNextHandler(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Create test user
|
||||
var userID string
|
||||
@@ -611,7 +612,7 @@ func TestAdminToday_AutoTransition_CurrentNextHandler(t *testing.T) {
|
||||
// - total_bookings counts non-cancelled bookings, excluding cancelled/no_show
|
||||
// - The range includes bookings from both the closed day and prior open days
|
||||
func TestAdminToday_ClosedDay_Summary(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
now := time.Now()
|
||||
@@ -732,7 +733,7 @@ func TestAdminToday_ClosedDay_Summary(t *testing.T) {
|
||||
// - summary_scope = "day" (today's summary)
|
||||
// - week_summary is present with summary_scope = "week"
|
||||
func TestAdminToday_WeekSummary_TomorrowClosed(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
now := time.Now()
|
||||
@@ -823,7 +824,7 @@ func TestAdminToday_WeekSummary_TomorrowClosed(t *testing.T) {
|
||||
// a closed day, even when default working_hours says today is open.
|
||||
// This tests the column name fix: monday_week_start → week_start.
|
||||
func TestAdminToday_ExceptionalHours_ClosedDay(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
ctx := context.Background()
|
||||
now := time.Now()
|
||||
@@ -963,7 +964,7 @@ func TestAdminNotifications_Acknowledge(t *testing.T) {
|
||||
// TestAdminToday_NonAdmin verifies that non-admin users receive HTTP 403
|
||||
// when accessing today's dashboard endpoints.
|
||||
func TestAdminToday_NonAdmin(t *testing.T) {
|
||||
resetTestData(t)
|
||||
testutils.SetupTestDB(t)
|
||||
|
||||
// Test current-next endpoint
|
||||
currentNextHandler := mw.RequireAdmin(http.HandlerFunc(today.GetCurrentAndNextHandler))
|
||||
|
||||
Reference in New Issue
Block a user