refactor: remove auto deposit penalty on no-shows, add comprehensive tests
- Remove automatic deposits_required=3 on no-shows, give admin flexibility - Add tests for no-show deposit logic (forgiven, over 24h, under 24h) - Add tests for reservation cleanup TTL (admin walk-in/call-in 15min) - Add tests for EXIF GPS data stripping in portfolio images - Add tests for contact info endpoint - Add tests for guest account anonymization
This commit is contained in:
@@ -696,6 +696,474 @@ func TestCleanupOldReservations(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Tests for CleanupOldReservations (Admin Walk-In) ---
|
||||
|
||||
// TestCleanupOldReservations_AdminWalkIn verifies that admin walk-in reservations
|
||||
// older than 15 minutes are deleted, while recent ones are preserved.
|
||||
func TestCleanupOldReservations_AdminWalkIn(t *testing.T) {
|
||||
cleanup := setupTimeBlockersTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
ukLocation, _ := time.LoadLocation("Europe/London")
|
||||
|
||||
// Create old walk-in reservation (>15 min old)
|
||||
oldTime := time.Now().Add(-16 * time.Minute).In(ukLocation)
|
||||
_, err := db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:walkin:guest:123', $2)
|
||||
`, oldTime, time.Now().Add(-16*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create old walk-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create recent walk-in reservation (<15 min old)
|
||||
recentTime := time.Now().Add(-14 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:walkin:guest:456', $2)
|
||||
`, recentTime, time.Now().Add(-14*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create recent walk-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Run cleanup
|
||||
err = CleanupOldReservations(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("CleanupOldReservations failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify old reservation was deleted
|
||||
var oldCount int
|
||||
err = db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:walkin:guest:123'").Scan(&oldCount)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to check old reservation: %v", err)
|
||||
}
|
||||
if oldCount != 0 {
|
||||
t.Error("expected old walk-in reservation (16 min) to be deleted")
|
||||
}
|
||||
|
||||
// Verify recent reservation still exists
|
||||
var recentCount int
|
||||
err = db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:walkin:guest:456'").Scan(&recentCount)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to check recent reservation: %v", err)
|
||||
}
|
||||
if recentCount != 1 {
|
||||
t.Error("expected recent walk-in reservation (14 min) to be preserved")
|
||||
}
|
||||
}
|
||||
|
||||
// --- Tests for CleanupOldReservations (Admin Call-In) ---
|
||||
|
||||
// TestCleanupOldReservations_AdminCallIn verifies that admin call-in reservations
|
||||
// older than 15 minutes are deleted, while recent ones are preserved.
|
||||
func TestCleanupOldReservations_AdminCallIn(t *testing.T) {
|
||||
cleanup := setupTimeBlockersTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
ukLocation, _ := time.LoadLocation("Europe/London")
|
||||
|
||||
// Create old call-in reservation (>15 min old)
|
||||
oldTime := time.Now().Add(-16 * time.Minute).In(ukLocation)
|
||||
_, err := db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:callin:guest:123', $2)
|
||||
`, oldTime, time.Now().Add(-16*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create old call-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create recent call-in reservation (<15 min old)
|
||||
recentTime := time.Now().Add(-14 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:callin:guest:456', $2)
|
||||
`, recentTime, time.Now().Add(-14*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create recent call-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Run cleanup
|
||||
err = CleanupOldReservations(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("CleanupOldReservations failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify old reservation was deleted
|
||||
var oldCount int
|
||||
err = db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:callin:guest:123'").Scan(&oldCount)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to check old reservation: %v", err)
|
||||
}
|
||||
if oldCount != 0 {
|
||||
t.Error("expected old call-in reservation (16 min) to be deleted")
|
||||
}
|
||||
|
||||
// Verify recent reservation still exists
|
||||
var recentCount int
|
||||
err = db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:callin:guest:456'").Scan(&recentCount)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to check recent reservation: %v", err)
|
||||
}
|
||||
if recentCount != 1 {
|
||||
t.Error("expected recent call-in reservation (14 min) to be preserved")
|
||||
}
|
||||
}
|
||||
|
||||
// --- Tests for CleanupOldReservations (Mixed Types) ---
|
||||
|
||||
// TestCleanupOldReservations_MixedTypes verifies that cleanup correctly handles
|
||||
// all reservation types with their respective TTLs.
|
||||
func TestCleanupOldReservations_MixedTypes(t *testing.T) {
|
||||
cleanup := setupTimeBlockersTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
ukLocation, _ := time.LoadLocation("Europe/London")
|
||||
|
||||
// Create old user reservation (>1 hour old)
|
||||
oldUserTime := time.Now().Add(-2 * time.Hour).In(ukLocation)
|
||||
_, err := db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:user:old', $2)
|
||||
`, oldUserTime, time.Now().Add(-2*time.Hour))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create old user reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create recent user reservation (<1 hour old)
|
||||
recentUserTime := time.Now().Add(-30 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:user:recent', $2)
|
||||
`, recentUserTime, time.Now().Add(-30*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create recent user reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create old anon reservation (>10 min old)
|
||||
oldAnonTime := time.Now().Add(-15 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:anon:old', $2)
|
||||
`, oldAnonTime, time.Now().Add(-15*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create old anon reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create recent anon reservation (<10 min old)
|
||||
recentAnonTime := time.Now().Add(-5 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:anon:recent', $2)
|
||||
`, recentAnonTime, time.Now().Add(-5*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create recent anon reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create old admin walk-in reservation (>15 min old)
|
||||
oldWalkinTime := time.Now().Add(-20 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:walkin:old', $2)
|
||||
`, oldWalkinTime, time.Now().Add(-20*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create old walk-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create recent admin walk-in reservation (<15 min old)
|
||||
recentWalkinTime := time.Now().Add(-10 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:walkin:recent', $2)
|
||||
`, recentWalkinTime, time.Now().Add(-10*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create recent walk-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create old admin call-in reservation (>15 min old)
|
||||
oldCallinTime := time.Now().Add(-20 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:callin:old', $2)
|
||||
`, oldCallinTime, time.Now().Add(-20*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create old call-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Create recent admin call-in reservation (<15 min old)
|
||||
recentCallinTime := time.Now().Add(-10 * time.Minute).In(ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_at)
|
||||
VALUES ($1, 60, 'RESERVATION:admin:callin:recent', $2)
|
||||
`, recentCallinTime, time.Now().Add(-10*time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create recent call-in reservation: %v", err)
|
||||
}
|
||||
|
||||
// Verify we have 8 reservations before cleanup
|
||||
var countBefore int
|
||||
err = db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description LIKE 'RESERVATION:%'").Scan(&countBefore)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to count reservations before cleanup: %v", err)
|
||||
}
|
||||
if countBefore != 8 {
|
||||
t.Errorf("expected 8 reservations before cleanup, got %d", countBefore)
|
||||
}
|
||||
|
||||
// Run cleanup
|
||||
err = CleanupOldReservations(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("CleanupOldReservations failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify old reservations were deleted (4 old ones)
|
||||
var oldUserCount, oldAnonCount, oldWalkinCount, oldCallinCount int
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:user:old'").Scan(&oldUserCount)
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:anon:old'").Scan(&oldAnonCount)
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:walkin:old'").Scan(&oldWalkinCount)
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:callin:old'").Scan(&oldCallinCount)
|
||||
|
||||
if oldUserCount != 0 {
|
||||
t.Error("expected old user reservation to be deleted")
|
||||
}
|
||||
if oldAnonCount != 0 {
|
||||
t.Error("expected old anon reservation to be deleted")
|
||||
}
|
||||
if oldWalkinCount != 0 {
|
||||
t.Error("expected old walk-in reservation to be deleted")
|
||||
}
|
||||
if oldCallinCount != 0 {
|
||||
t.Error("expected old call-in reservation to be deleted")
|
||||
}
|
||||
|
||||
// Verify recent reservations still exist (4 recent ones)
|
||||
var recentUserCount, recentAnonCount, recentWalkinCount, recentCallinCount int
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:user:recent'").Scan(&recentUserCount)
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:anon:recent'").Scan(&recentAnonCount)
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:walkin:recent'").Scan(&recentWalkinCount)
|
||||
db.DB.QueryRow(ctx, "SELECT COUNT(*) FROM time_blockers WHERE description = 'RESERVATION:admin:callin:recent'").Scan(&recentCallinCount)
|
||||
|
||||
if recentUserCount != 1 {
|
||||
t.Error("expected recent user reservation to be preserved")
|
||||
}
|
||||
if recentAnonCount != 1 {
|
||||
t.Error("expected recent anon reservation to be preserved")
|
||||
}
|
||||
if recentWalkinCount != 1 {
|
||||
t.Error("expected recent walk-in reservation to be preserved")
|
||||
}
|
||||
if recentCallinCount != 1 {
|
||||
t.Error("expected recent call-in reservation to be preserved")
|
||||
}
|
||||
}
|
||||
|
||||
// --- Tests for GetTimeBlockersInRange (Excludes Reservations) ---
|
||||
|
||||
// TestGetTimeBlockersInRange_ExcludesReservations verifies that reservation
|
||||
// blockers are excluded from the results.
|
||||
func TestGetTimeBlockersInRange_ExcludesReservations(t *testing.T) {
|
||||
cleanup := setupTimeBlockersTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
ukLocation, _ := time.LoadLocation("Europe/London")
|
||||
|
||||
// Create a regular blocker for tomorrow at 10:00
|
||||
tomorrow := time.Now().Add(24 * time.Hour).In(ukLocation)
|
||||
blockerTime := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 10, 0, 0, 0, ukLocation)
|
||||
_, err := db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_by)
|
||||
VALUES ($1, 60, 'Staff meeting', NULL)
|
||||
`, blockerTime)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create regular blocker: %v", err)
|
||||
}
|
||||
|
||||
// Create a reservation for tomorrow at 11:00
|
||||
reservationTime := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 11, 0, 0, 0, ukLocation)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO time_blockers (start_time, duration_minutes, description, created_by)
|
||||
VALUES ($1, 60, 'RESERVATION:user:abc:123', NULL)
|
||||
`, reservationTime)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create reservation: %v", err)
|
||||
}
|
||||
|
||||
// Query range covering both times
|
||||
start := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 0, 0, 0, 0, ukLocation)
|
||||
end := time.Date(tomorrow.Year(), tomorrow.Month(), tomorrow.Day(), 23, 59, 59, 0, ukLocation)
|
||||
|
||||
blockers, err := GetTimeBlockersInRange(ctx, start, end)
|
||||
if err != nil {
|
||||
t.Fatalf("GetTimeBlockersInRange failed: %v", err)
|
||||
}
|
||||
|
||||
// Should return only 1 blocker (the regular one, not the reservation)
|
||||
if len(blockers) != 1 {
|
||||
t.Errorf("expected 1 blocker, got %d", len(blockers))
|
||||
}
|
||||
|
||||
// Verify the blocker is "Staff meeting"
|
||||
if len(blockers) > 0 && blockers[0].Description != "Staff meeting" {
|
||||
t.Errorf("expected blocker 'Staff meeting', got '%s'", blockers[0].Description)
|
||||
}
|
||||
}
|
||||
|
||||
// --- Tests for AnonymizeStaleGuestAccounts ---
|
||||
|
||||
// TestAnonymizeStaleGuestAccounts_Exactly6Months verifies that a guest with
|
||||
// a booking exactly 6 months ago is anonymized.
|
||||
func TestAnonymizeStaleGuestAccounts_Exactly6Months(t *testing.T) {
|
||||
cleanup := setupTimeBlockersTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Create guest user
|
||||
guestID, err := fixtures.CreateTestUser(db.DB)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create guest user: %v", err)
|
||||
}
|
||||
|
||||
// Set account_role to guest
|
||||
_, err = db.DB.Exec(ctx, `UPDATE users SET account_role = 'guest' WHERE id = $1`, guestID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to set guest role: %v", err)
|
||||
}
|
||||
|
||||
// Create booking with start_time exactly 6 months ago
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO bookings (user_id, start_time, status, deposit_required)
|
||||
VALUES ($1, NOW() - INTERVAL '6 months', 'completed', false)
|
||||
`, guestID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create booking: %v", err)
|
||||
}
|
||||
|
||||
// Run anonymization
|
||||
err = AnonymizeStaleGuestAccounts(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("AnonymizeStaleGuestAccounts failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify guest was anonymized
|
||||
var firstName, lastName, email string
|
||||
err = db.DB.QueryRow(ctx, `SELECT n_first_name, n_last_name, email FROM users WHERE id = $1`, guestID).Scan(&firstName, &lastName, &email)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to query anonymized user: %v", err)
|
||||
}
|
||||
|
||||
if firstName != "Guest" {
|
||||
t.Errorf("expected first_name 'Guest', got '%s'", firstName)
|
||||
}
|
||||
if lastName != "Anonymized" {
|
||||
t.Errorf("expected last_name 'Anonymized', got '%s'", lastName)
|
||||
}
|
||||
if !strings.HasPrefix(email, "anon-") {
|
||||
t.Errorf("expected email to start with 'anon-', got '%s'", email)
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnonymizeStaleGuestAccounts_ActiveBooking_Skipped verifies that a guest
|
||||
// with an active (future) booking is NOT anonymized even if they have a past booking.
|
||||
func TestAnonymizeStaleGuestAccounts_ActiveBooking_Skipped(t *testing.T) {
|
||||
cleanup := setupTimeBlockersTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Create guest user
|
||||
guestID, err := fixtures.CreateTestUser(db.DB)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create guest user: %v", err)
|
||||
}
|
||||
|
||||
// Set account_role to guest
|
||||
_, err = db.DB.Exec(ctx, `UPDATE users SET account_role = 'guest' WHERE id = $1`, guestID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to set guest role: %v", err)
|
||||
}
|
||||
|
||||
// Create past booking (7 months ago)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO bookings (user_id, start_time, status, deposit_required)
|
||||
VALUES ($1, NOW() - INTERVAL '7 months', 'completed', false)
|
||||
`, guestID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create past booking: %v", err)
|
||||
}
|
||||
|
||||
// Create active booking (tomorrow)
|
||||
tomorrow := time.Now().Add(24 * time.Hour)
|
||||
_, err = db.DB.Exec(ctx, `
|
||||
INSERT INTO bookings (user_id, start_time, status, deposit_required)
|
||||
VALUES ($1, $2, 'confirmed', false)
|
||||
`, guestID, tomorrow)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create active booking: %v", err)
|
||||
}
|
||||
|
||||
// Run anonymization
|
||||
err = AnonymizeStaleGuestAccounts(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("AnonymizeStaleGuestAccounts failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify guest was NOT anonymized
|
||||
var firstName string
|
||||
err = db.DB.QueryRow(ctx, `SELECT n_first_name FROM users WHERE id = $1`, guestID).Scan(&firstName)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to query user: %v", err)
|
||||
}
|
||||
|
||||
// The first name should NOT be "Guest" (it should retain original name)
|
||||
if firstName == "Guest" {
|
||||
t.Error("expected guest with active booking to NOT be anonymized")
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnonymizeStaleGuestAccounts_NoBookings verifies that a guest with
|
||||
// no bookings is NOT anonymized.
|
||||
func TestAnonymizeStaleGuestAccounts_NoBookings(t *testing.T) {
|
||||
cleanup := setupTimeBlockersTestDB(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Create guest user with no bookings
|
||||
guestID, err := fixtures.CreateTestUser(db.DB)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create guest user: %v", err)
|
||||
}
|
||||
|
||||
// Set account_role to guest
|
||||
_, err = db.DB.Exec(ctx, `UPDATE users SET account_role = 'guest' WHERE id = $1`, guestID)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to set guest role: %v", err)
|
||||
}
|
||||
|
||||
// Run anonymization
|
||||
err = AnonymizeStaleGuestAccounts(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("AnonymizeStaleGuestAccounts failed: %v", err)
|
||||
}
|
||||
|
||||
// Verify guest was NOT anonymized
|
||||
var firstName string
|
||||
err = db.DB.QueryRow(ctx, `SELECT n_first_name FROM users WHERE id = $1`, guestID).Scan(&firstName)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to query user: %v", err)
|
||||
}
|
||||
|
||||
// The first name should NOT be "Guest" (it should retain original name)
|
||||
if firstName == "Guest" {
|
||||
t.Error("expected guest with no bookings to NOT be anonymized")
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure pool is used to avoid unused import error
|
||||
var _ = pgxpool.Pool{}
|
||||
var _ = bytes.Buffer{}
|
||||
|
||||
Reference in New Issue
Block a user