feat: mail service
This commit is contained in:
@@ -451,13 +451,14 @@ func newTestStore(t *testing.T, server *miniredis.Miniredis, cfg Config) *Store
|
||||
|
||||
func testPendingChallenge(now time.Time) challenge.Challenge {
|
||||
return challenge.Challenge{
|
||||
ID: common.ChallengeID("challenge-pending"),
|
||||
Email: common.Email("pilot@example.com"),
|
||||
CodeHash: []byte("hashed-pending-code"),
|
||||
Status: challenge.StatusPendingSend,
|
||||
DeliveryState: challenge.DeliveryPending,
|
||||
CreatedAt: now,
|
||||
ExpiresAt: now.Add(challenge.InitialTTL),
|
||||
ID: common.ChallengeID("challenge-pending"),
|
||||
Email: common.Email("pilot@example.com"),
|
||||
CodeHash: []byte("hashed-pending-code"),
|
||||
PreferredLanguage: "en",
|
||||
Status: challenge.StatusPendingSend,
|
||||
DeliveryState: challenge.DeliveryPending,
|
||||
CreatedAt: now,
|
||||
ExpiresAt: now.Add(challenge.InitialTTL),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,13 +474,14 @@ func testChallenge(now time.Time) challenge.Challenge {
|
||||
}
|
||||
|
||||
return challenge.Challenge{
|
||||
ID: common.ChallengeID("challenge-confirmed"),
|
||||
Email: common.Email("pilot@example.com"),
|
||||
CodeHash: []byte("hashed-code"),
|
||||
Status: challenge.StatusConfirmedPendingExpire,
|
||||
DeliveryState: challenge.DeliverySent,
|
||||
CreatedAt: now,
|
||||
ExpiresAt: now.Add(challenge.ConfirmedRetention),
|
||||
ID: common.ChallengeID("challenge-confirmed"),
|
||||
Email: common.Email("pilot@example.com"),
|
||||
CodeHash: []byte("hashed-code"),
|
||||
PreferredLanguage: "en",
|
||||
Status: challenge.StatusConfirmedPendingExpire,
|
||||
DeliveryState: challenge.DeliverySent,
|
||||
CreatedAt: now,
|
||||
ExpiresAt: now.Add(challenge.ConfirmedRetention),
|
||||
Attempts: challenge.AttemptCounters{
|
||||
Send: 1,
|
||||
Confirm: 2,
|
||||
@@ -495,6 +497,36 @@ func testChallenge(now time.Time) challenge.Challenge {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStoreGetDefaultsMissingPreferredLanguageToEnglish(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
server := miniredis.RunT(t)
|
||||
store := newTestStore(t, server, Config{})
|
||||
now := time.Unix(1_775_130_250, 0).UTC()
|
||||
|
||||
record := testPendingChallenge(now)
|
||||
stored, err := redisRecordFromChallenge(record)
|
||||
require.NoError(t, err)
|
||||
stored.PreferredLanguage = ""
|
||||
|
||||
payload := mustMarshalJSON(t, map[string]any{
|
||||
"challenge_id": stored.ChallengeID,
|
||||
"email": stored.Email,
|
||||
"code_hash_base64": stored.CodeHashBase64,
|
||||
"status": stored.Status,
|
||||
"delivery_state": stored.DeliveryState,
|
||||
"created_at": stored.CreatedAt,
|
||||
"expires_at": stored.ExpiresAt,
|
||||
"send_attempt_count": stored.SendAttemptCount,
|
||||
"confirm_attempt_count": stored.ConfirmAttemptCount,
|
||||
})
|
||||
server.Set(store.lookupKey(record.ID), payload)
|
||||
|
||||
got, err := store.Get(context.Background(), record.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "en", got.PreferredLanguage)
|
||||
}
|
||||
|
||||
func timePointer(value time.Time) *time.Time {
|
||||
return &value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user