feat: support time_zone for user registration context
This commit is contained in:
@@ -63,13 +63,13 @@ func (d *InMemoryUserDirectory) ExistsByUserID(ctx context.Context, userID commo
|
||||
return ok, nil
|
||||
}
|
||||
|
||||
// EnsureUserByEmail returns an existing user for email, creates a new user
|
||||
// when registration is allowed, or reports a blocked outcome.
|
||||
func (d *InMemoryUserDirectory) EnsureUserByEmail(ctx context.Context, email common.Email) (ports.EnsureUserResult, error) {
|
||||
// EnsureUserByEmail returns an existing user for input.Email, creates a new
|
||||
// user when registration is allowed, or reports a blocked outcome.
|
||||
func (d *InMemoryUserDirectory) EnsureUserByEmail(ctx context.Context, input ports.EnsureUserInput) (ports.EnsureUserResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return ports.EnsureUserResult{}, err
|
||||
}
|
||||
if err := email.Validate(); err != nil {
|
||||
if err := input.Validate(); err != nil {
|
||||
return ports.EnsureUserResult{}, fmt.Errorf("ensure user by email: %w", err)
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ func (d *InMemoryUserDirectory) EnsureUserByEmail(ctx context.Context, email com
|
||||
d.emailByUserID = make(map[common.UserID]common.Email)
|
||||
}
|
||||
|
||||
entry, ok := d.byEmail[email]
|
||||
entry, ok := d.byEmail[input.Email]
|
||||
if ok {
|
||||
if !entry.BlockReasonCode.IsZero() {
|
||||
result := ports.EnsureUserResult{
|
||||
@@ -104,8 +104,8 @@ func (d *InMemoryUserDirectory) EnsureUserByEmail(ctx context.Context, email com
|
||||
if err != nil {
|
||||
return ports.EnsureUserResult{}, err
|
||||
}
|
||||
d.byEmail[email] = userDirectoryEntry{UserID: userID}
|
||||
d.emailByUserID[userID] = email
|
||||
d.byEmail[input.Email] = userDirectoryEntry{UserID: userID}
|
||||
d.emailByUserID[userID] = input.Email
|
||||
|
||||
result := ports.EnsureUserResult{
|
||||
Outcome: ports.EnsureUserOutcomeCreated,
|
||||
|
||||
@@ -94,7 +94,13 @@ func TestInMemoryUserDirectoryEnsureUserExistingCreatedAndBlocked(t *testing.T)
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got, err := directory.EnsureUserByEmail(context.Background(), tt.email)
|
||||
got, err := directory.EnsureUserByEmail(context.Background(), ports.EnsureUserInput{
|
||||
Email: tt.email,
|
||||
RegistrationContext: &ports.RegistrationContext{
|
||||
PreferredLanguage: "en",
|
||||
TimeZone: "Europe/Kaliningrad",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
require.Failf(t, "test failed", "EnsureUserByEmail() returned error: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user