()
| 311 | } |
| 312 | |
| 313 | func (ts *UserTestSuite) TestUpdateUserEmailSuccess() { |
| 314 | userA, err := NewUser("", "foo@example.com", "", "authenticated", nil) |
| 315 | require.NoError(ts.T(), err) |
| 316 | require.NoError(ts.T(), ts.db.Create(userA)) |
| 317 | |
| 318 | primaryIdentity, err := NewIdentity(userA, "email", map[string]interface{}{ |
| 319 | "sub": userA.ID.String(), |
| 320 | "email": "foo@example.com", |
| 321 | }) |
| 322 | require.NoError(ts.T(), err) |
| 323 | require.NoError(ts.T(), ts.db.Create(primaryIdentity)) |
| 324 | |
| 325 | secondaryIdentity, err := NewIdentity(userA, "google", map[string]interface{}{ |
| 326 | "sub": userA.ID.String(), |
| 327 | "email": "bar@example.com", |
| 328 | }) |
| 329 | require.NoError(ts.T(), err) |
| 330 | require.NoError(ts.T(), ts.db.Create(secondaryIdentity)) |
| 331 | |
| 332 | // UpdateUserEmail should not do anything and the user's email should still use the primaryIdentity |
| 333 | require.NoError(ts.T(), userA.UpdateUserEmailFromIdentities(ts.db)) |
| 334 | require.Equal(ts.T(), primaryIdentity.GetEmail(), userA.GetEmail()) |
| 335 | |
| 336 | // remove primary identity |
| 337 | require.NoError(ts.T(), ts.db.Destroy(primaryIdentity)) |
| 338 | |
| 339 | // UpdateUserEmail should update the user to use the secondary identity's email |
| 340 | require.NoError(ts.T(), userA.UpdateUserEmailFromIdentities(ts.db)) |
| 341 | require.Equal(ts.T(), secondaryIdentity.GetEmail(), userA.GetEmail()) |
| 342 | } |
| 343 | |
| 344 | func (ts *UserTestSuite) TestUpdateUserEmailFailure() { |
| 345 | userA, err := NewUser("", "foo@example.com", "", "authenticated", nil) |
nothing calls this directly
no test coverage detected