-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): make userToCreateRepository.create throw AlreadyRegistered…
…EmailError
- Loading branch information
1 parent
0d334ab
commit 33a27ca
Showing
2 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { User } from '../../../../../src/identity-access-management/domain/models/User.js'; | ||
import { UserToCreate } from '../../../../../src/identity-access-management/domain/models/UserToCreate.js'; | ||
import { userToCreateRepository } from '../../../../../src/identity-access-management/infrastructure/repositories/user-to-create.repository.js'; | ||
import { OrganizationLearnerAlreadyLinkedToUserError } from '../../../../../src/shared/domain/errors.js'; | ||
import { | ||
AlreadyRegisteredEmailError, | ||
OrganizationLearnerAlreadyLinkedToUserError, | ||
} from '../../../../../src/shared/domain/errors.js'; | ||
import { catchErr, databaseBuilder, expect, knex } from '../../../../test-helper.js'; | ||
|
||
describe('Integration | Identity Access Management | Infrastructure | Repository | user-to-create', function () { | ||
|
@@ -80,6 +83,30 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
expect(userSaved.cgu).to.equal(user.cgu); | ||
expect(userSaved.locale).to.equal(user.locale); | ||
}); | ||
|
||
context('when email is already taken', function () { | ||
it('throws an AlreadyRegisteredEmailError', async function () { | ||
// given | ||
const alreadyExistingEmail = '[email protected]'; | ||
databaseBuilder.factory.buildUser({ id: 7, email: alreadyExistingEmail }); | ||
await databaseBuilder.commit(); | ||
|
||
const now = new Date('2022-02-01'); | ||
const user = new UserToCreate({ | ||
firstName: 'laura', | ||
lastName: 'lune', | ||
email: alreadyExistingEmail, | ||
createdAt: now, | ||
updatedAt: now, | ||
}); | ||
|
||
// when | ||
const error = await catchErr(userToCreateRepository.create)({ user }); | ||
|
||
// then | ||
expect(error).to.be.instanceOf(AlreadyRegisteredEmailError); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |