Skip to content

Commit

Permalink
feat: stubable time in text package
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 71583c5 commit 22e4ed1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion text/message_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func NewErrorValidationLoginFlowExpired(ago time.Duration) *Message {
Text: fmt.Sprintf("The login flow expired %.2f minutes ago, please try again.", ago.Minutes()),
Type: Error,
Context: context(map[string]interface{}{
"expired_at": time.Now().Add(ago),
"expired_at": Now().UTC().Add(ago),
}),
}
}
Expand Down
4 changes: 2 additions & 2 deletions text/message_recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ func NewErrorValidationRecoveryFlowExpired(ago time.Duration) *Message {
Text: fmt.Sprintf("The recovery flow expired %.2f minutes ago, please try again.", ago.Minutes()),
Type: Error,
Context: context(map[string]interface{}{
"expired_at": time.Now().Add(ago),
"expired_at": Now().UTC().Add(ago),
}),
}
}

func NewRecoverySuccessful(privilegedSessionExpiresAt time.Time) *Message {
hasLeft := time.Until(privilegedSessionExpiresAt)
hasLeft := Until(privilegedSessionExpiresAt)
return &Message{
ID: InfoSelfServiceRecoverySuccessful,
Type: Info,
Expand Down
2 changes: 1 addition & 1 deletion text/message_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewErrorValidationRegistrationFlowExpired(ago time.Duration) *Message {
Text: fmt.Sprintf("The registration flow expired %.2f minutes ago, please try again.", ago.Minutes()),
Type: Error,
Context: context(map[string]interface{}{
"expired_at": time.Now().Add(ago),
"expired_at": Now().UTC().Add(ago),
}),
}
}
2 changes: 1 addition & 1 deletion text/message_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewErrorValidationSettingsFlowExpired(ago time.Duration) *Message {
Text: fmt.Sprintf("The settings flow expired %.2f minutes ago, please try again.", ago.Minutes()),
Type: Error,
Context: context(map[string]interface{}{
"expired_at": time.Now().Add(ago),
"expired_at": Now().UTC().Add(ago),
}),
}
}
Expand Down
2 changes: 1 addition & 1 deletion text/message_verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewErrorValidationVerificationFlowExpired(ago time.Duration) *Message {
Text: fmt.Sprintf("The verification flow expired %.2f minutes ago, please try again.", ago.Minutes()),
Type: Error,
Context: context(map[string]interface{}{
"expired_at": time.Now().Add(ago),
"expired_at": Now().UTC().Add(ago),
}),
}
}
Expand Down
5 changes: 5 additions & 0 deletions text/type.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package text

import "time"

// swagger:model uiTextType
type Type string

const (
Info Type = "info"
Error Type = "error"
)

var Now = time.Now
var Until = time.Until

0 comments on commit 22e4ed1

Please sign in to comment.