refactor(handlers): migrate remaining backend handlers to clock.Now() and transaction patterns
Apply clock.Now() migration, transaction wrapping, and minor refactors across admin, scheduling, today, user, auth handler, notifications, webhooks, services, portfolio, ratelimit, testutils, and main.go. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"time"
|
||||
|
||||
"crussell/auth"
|
||||
"crussell/clock"
|
||||
"crussell/db"
|
||||
"crussell/internal/dav"
|
||||
"crussell/mw"
|
||||
@@ -286,7 +287,7 @@ func TestRegister_InvalidInput_Under16(t *testing.T) {
|
||||
handler := http.HandlerFunc(RegisterHandler)
|
||||
|
||||
// Calculate a date that makes them under 16
|
||||
under16DOB := time.Now().AddDate(-15, 0, 0).Format("2006-01-02")
|
||||
under16DOB := clock.Now().AddDate(-15, 0, 0).Format("2006-01-02")
|
||||
|
||||
body := RegisterRequest{
|
||||
FirstName: "Young",
|
||||
@@ -601,7 +602,7 @@ func TestVerifyCheck_ValidCode(t *testing.T) {
|
||||
|
||||
// Create a verification code
|
||||
var code string
|
||||
expiresAt := time.Now().Add(24 * time.Hour)
|
||||
expiresAt := clock.Now().Add(24 * time.Hour)
|
||||
err = tx.QueryRow(ctx,
|
||||
`INSERT INTO verification_codes (user_id, purpose, expires_at) VALUES ($1, 'email_verify', $2) RETURNING code`,
|
||||
userID, expiresAt).Scan(&code)
|
||||
@@ -674,7 +675,7 @@ func TestVerifyCheck_ExpiredCode(t *testing.T) {
|
||||
|
||||
// Create an expired verification code
|
||||
var code string
|
||||
expiresAt := time.Now().Add(-1 * time.Hour) // Expired 1 hour ago
|
||||
expiresAt := clock.Now().Add(-1 * time.Hour) // Expired 1 hour ago
|
||||
err = tx.QueryRow(ctx,
|
||||
`INSERT INTO verification_codes (user_id, purpose, expires_at) VALUES ($1, 'email_verify', $2) RETURNING code`,
|
||||
userID, expiresAt).Scan(&code)
|
||||
@@ -786,7 +787,7 @@ func TestVerifyCheck_AlreadyUsed(t *testing.T) {
|
||||
|
||||
// Create a verification code
|
||||
var code string
|
||||
expiresAt := time.Now().Add(24 * time.Hour)
|
||||
expiresAt := clock.Now().Add(24 * time.Hour)
|
||||
err = tx.QueryRow(ctx,
|
||||
`INSERT INTO verification_codes (user_id, purpose, expires_at) VALUES ($1, 'email_verify', $2) RETURNING code`,
|
||||
userID, expiresAt).Scan(&code)
|
||||
@@ -840,7 +841,7 @@ func TestVerifyCheck_RoleChangeToVerified(t *testing.T) {
|
||||
|
||||
// Create a verification code
|
||||
var code string
|
||||
expiresAt := time.Now().Add(24 * time.Hour)
|
||||
expiresAt := clock.Now().Add(24 * time.Hour)
|
||||
err = tx.QueryRow(ctx,
|
||||
`INSERT INTO verification_codes (user_id, purpose, expires_at) VALUES ($1, 'email_verify', $2) RETURNING code`,
|
||||
userID, expiresAt).Scan(&code)
|
||||
@@ -1446,7 +1447,7 @@ func TestLoginInProgress_Cap(t *testing.T) {
|
||||
// Fill the loginInProgress map with 20 entries
|
||||
loginStateMu.Lock()
|
||||
for i := 0; i < maxLoginInProgress; i++ {
|
||||
loginInProgress[fmt.Sprintf("stale-user-%d", i)] = time.Now()
|
||||
loginInProgress[fmt.Sprintf("stale-user-%d", i)] = clock.Now()
|
||||
}
|
||||
loginStateMu.Unlock()
|
||||
|
||||
@@ -1736,7 +1737,7 @@ func TestJTI_Revocation_PostgreSQL(t *testing.T) {
|
||||
t.Fatalf("token should be valid before revocation: %v", err)
|
||||
}
|
||||
|
||||
auth.RevokeJTI(ctx, jti, time.Now().Add(1*time.Hour))
|
||||
auth.RevokeJTI(ctx, jti, clock.Now().Add(1*time.Hour))
|
||||
|
||||
if !auth.IsJTIRevoked(ctx, jti) {
|
||||
t.Error("JTI should be revoked after RevokeJTI call")
|
||||
|
||||
Reference in New Issue
Block a user