()
| 342 | } |
| 343 | |
| 344 | func (ts *UserTestSuite) TestUpdateUserEmailFailure() { |
| 345 | userA, err := NewUser("", "foo@example.com", "", "authenticated", nil) |
| 346 | require.NoError(ts.T(), err) |
| 347 | require.NoError(ts.T(), ts.db.Create(userA)) |
| 348 | |
| 349 | primaryIdentity, err := NewIdentity(userA, "email", map[string]interface{}{ |
| 350 | "sub": userA.ID.String(), |
| 351 | "email": "foo@example.com", |
| 352 | }) |
| 353 | require.NoError(ts.T(), err) |
| 354 | require.NoError(ts.T(), ts.db.Create(primaryIdentity)) |
| 355 | |
| 356 | secondaryIdentity, err := NewIdentity(userA, "google", map[string]interface{}{ |
| 357 | "sub": userA.ID.String(), |
| 358 | "email": "bar@example.com", |
| 359 | }) |
| 360 | require.NoError(ts.T(), err) |
| 361 | require.NoError(ts.T(), ts.db.Create(secondaryIdentity)) |
| 362 | |
| 363 | userB, err := NewUser("", "bar@example.com", "", "authenticated", nil) |
| 364 | require.NoError(ts.T(), err) |
| 365 | require.NoError(ts.T(), ts.db.Create(userB)) |
| 366 | |
| 367 | // remove primary identity |
| 368 | require.NoError(ts.T(), ts.db.Destroy(primaryIdentity)) |
| 369 | |
| 370 | // UpdateUserEmail should fail with the email unique constraint violation error |
| 371 | // since userB is using the secondary identity's email |
| 372 | require.ErrorIs(ts.T(), userA.UpdateUserEmailFromIdentities(ts.db), UserEmailUniqueConflictError{}) |
| 373 | require.Equal(ts.T(), primaryIdentity.GetEmail(), userA.GetEmail()) |
| 374 | } |
| 375 | |
| 376 | func (ts *UserTestSuite) TestNewUserWithPasswordHashSuccess() { |
| 377 | cases := []struct { |
nothing calls this directly
no test coverage detected