-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathcreate-reset-password-demand.usecase.test.js
64 lines (54 loc) · 2.26 KB
/
create-reset-password-demand.usecase.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { usecases } from '../../../../../src/identity-access-management/domain/usecases/index.js';
import { databaseBuilder, expect, knex } from '../../../../test-helper.js';
describe('Integration | Identity Access Management | Domain | UseCase | create-reset-password-demand', function () {
const locale = 'fr';
it('creates a reset password demand', async function () {
// given
const email = '[email protected]';
const userId = databaseBuilder.factory.buildUser({ email }).id;
databaseBuilder.factory.buildAuthenticationMethod.withPixAsIdentityProviderAndHashedPassword({ userId });
await databaseBuilder.commit();
// when
await usecases.createResetPasswordDemand({
email,
locale,
});
// then
const resetPasswordDemand = await knex('reset-password-demands').where({ email }).first();
expect(resetPasswordDemand).to.exist;
});
context('when a user account exists but with an email differing by case', function () {
it('creates a reset password demand', async function () {
// given
const accountEmail = '[email protected]';
const passwordResetDemandEmail = '[email protected]';
const userId = databaseBuilder.factory.buildUser({ email: accountEmail }).id;
databaseBuilder.factory.buildAuthenticationMethod.withPixAsIdentityProviderAndHashedPassword({ userId });
await databaseBuilder.commit();
// when
await usecases.createResetPasswordDemand({
email: passwordResetDemandEmail,
locale,
});
// then
const resetPasswordDemand = await knex('reset-password-demands')
.whereRaw('LOWER("email") = LOWER(?)', passwordResetDemandEmail)
.first();
expect(resetPasswordDemand).to.exist;
});
});
context('when no user account with a matching email exist', function () {
it('does not create a reset password demand', async function () {
// given
const unknownEmail = '[email protected]';
// when
await usecases.createResetPasswordDemand({
email: unknownEmail,
locale,
});
// then
const resetPasswordDemand = await knex('reset-password-demands').where({ email: unknownEmail }).first();
expect(resetPasswordDemand).to.not.exist;
});
});
});