fix: unify email identity sync and retry first-bind defaults
This commit is contained in:
@@ -31,6 +31,8 @@ type emailSyncRepoStub struct {
|
||||
updated []*User
|
||||
ensureCalls []ensureEmailCall
|
||||
replaceCalls []replaceEmailCall
|
||||
ensureErr error
|
||||
replaceErr error
|
||||
}
|
||||
|
||||
func (s *emailSyncRepoStub) Create(_ context.Context, user *User) error {
|
||||
@@ -125,7 +127,7 @@ func (s *emailSyncRepoStub) DisableTotp(context.Context, int64) error { return n
|
||||
|
||||
func (s *emailSyncRepoStub) EnsureEmailAuthIdentity(_ context.Context, userID int64, email string) error {
|
||||
s.ensureCalls = append(s.ensureCalls, ensureEmailCall{userID: userID, email: email})
|
||||
return nil
|
||||
return s.ensureErr
|
||||
}
|
||||
|
||||
func (s *emailSyncRepoStub) ReplaceEmailAuthIdentity(_ context.Context, userID int64, oldEmail, newEmail string) error {
|
||||
@@ -134,11 +136,14 @@ func (s *emailSyncRepoStub) ReplaceEmailAuthIdentity(_ context.Context, userID i
|
||||
oldEmail: oldEmail,
|
||||
newEmail: newEmail,
|
||||
})
|
||||
return nil
|
||||
return s.replaceErr
|
||||
}
|
||||
|
||||
func TestAdminService_CreateUser_EnsuresEmailAuthIdentity(t *testing.T) {
|
||||
repo := &emailSyncRepoStub{nextID: 55}
|
||||
func TestAdminService_CreateUser_DoesNotReturnPartialSuccessFromEmailIdentityResync(t *testing.T) {
|
||||
repo := &emailSyncRepoStub{
|
||||
nextID: 55,
|
||||
ensureErr: fmt.Errorf("unexpected email resync"),
|
||||
}
|
||||
svc := &adminServiceImpl{userRepo: repo}
|
||||
|
||||
user, err := svc.CreateUser(context.Background(), &CreateUserInput{
|
||||
@@ -147,14 +152,12 @@ func TestAdminService_CreateUser_EnsuresEmailAuthIdentity(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, user)
|
||||
require.Equal(t, []ensureEmailCall{{
|
||||
userID: 55,
|
||||
email: "admin-created@example.com",
|
||||
}}, repo.ensureCalls)
|
||||
require.Equal(t, int64(55), user.ID)
|
||||
require.Empty(t, repo.ensureCalls)
|
||||
require.Empty(t, repo.replaceCalls)
|
||||
}
|
||||
|
||||
func TestAdminService_UpdateUser_ReplacesEmailAuthIdentity(t *testing.T) {
|
||||
func TestAdminService_UpdateUser_DoesNotReturnPartialSuccessFromEmailIdentityResync(t *testing.T) {
|
||||
repo := &emailSyncRepoStub{
|
||||
user: &User{
|
||||
ID: 91,
|
||||
@@ -163,6 +166,7 @@ func TestAdminService_UpdateUser_ReplacesEmailAuthIdentity(t *testing.T) {
|
||||
Status: StatusActive,
|
||||
Concurrency: 3,
|
||||
},
|
||||
replaceErr: fmt.Errorf("unexpected email resync"),
|
||||
}
|
||||
svc := &adminServiceImpl{userRepo: repo}
|
||||
|
||||
@@ -172,10 +176,6 @@ func TestAdminService_UpdateUser_ReplacesEmailAuthIdentity(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, updated)
|
||||
require.Equal(t, "after@example.com", updated.Email)
|
||||
require.Equal(t, []replaceEmailCall{{
|
||||
userID: 91,
|
||||
oldEmail: "before@example.com",
|
||||
newEmail: "after@example.com",
|
||||
}}, repo.replaceCalls)
|
||||
require.Empty(t, repo.replaceCalls)
|
||||
require.Empty(t, repo.ensureCalls)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user