aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/dashboard/forgot-password.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/dashboard/forgot-password.spec.ts')
-rw-r--r--tests/functional/dashboard/forgot-password.spec.ts64
1 files changed, 34 insertions, 30 deletions
diff --git a/tests/functional/dashboard/forgot-password.spec.ts b/tests/functional/dashboard/forgot-password.spec.ts
index 7c356c8..82004ac 100644
--- a/tests/functional/dashboard/forgot-password.spec.ts
+++ b/tests/functional/dashboard/forgot-password.spec.ts
@@ -1,66 +1,70 @@
1import { test } from '@japa/runner' 1import { test } from '@japa/runner';
2import emitter from '@adonisjs/core/services/emitter' 2import emitter from '@adonisjs/core/services/emitter';
3import UserFactory from '#database/factories/UserFactory' 3import UserFactory from '#database/factories/UserFactory';
4 4
5test.group('Dashboard / Forgot password page', () => { 5test.group('Dashboard / Forgot password page', () => {
6 test('returns a 200 opening the forgot password route', async ({ client }) => { 6 test('returns a 200 opening the forgot password route', async ({
7 const response = await client.get('/user/forgot') 7 client,
8 }) => {
9 const response = await client.get('/user/forgot');
8 10
9 response.assertStatus(200) 11 response.assertStatus(200);
10 response.assertTextIncludes('Forgot Password?') 12 response.assertTextIncludes('Forgot Password?');
11 }) 13 });
12 14
13 test('returns `Please enter a valid email address` when providing invalid email', async ({ 15 test('returns `Please enter a valid email address` when providing invalid email', async ({
14 client, 16 client,
15 }) => { 17 }) => {
16 const response = await client.post('/user/forgot').fields({ 18 const response = await client.post('/user/forgot').fields({
17 mail: 'invalid', 19 mail: 'invalid',
18 }) 20 });
19 21
20 response.assertStatus(200) 22 response.assertStatus(200);
21 response.assertTextIncludes('Please enter a valid email address') 23 response.assertTextIncludes('Please enter a valid email address');
22 }) 24 });
23 25
24 test('returns `email send when exists` without forgot:password event', async ({ 26 test('returns `email send when exists` without forgot:password event', async ({
25 client, 27 client,
26 assert, 28 assert,
27 }) => { 29 }) => {
28 const emitterService = emitter.fake() 30 const emitterService = emitter.fake();
29 31
30 const response = await client.post('/user/forgot').fields({ 32 const response = await client.post('/user/forgot').fields({
31 mail: 'test@ferdium.org', 33 mail: 'test@ferdium.org',
32 }) 34 });
33 35
34 response.assertStatus(200) 36 response.assertStatus(200);
35 response.assertTextIncludes( 37 response.assertTextIncludes(
36 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.' 38 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.',
37 ) 39 );
38 40
39 assert.isFalse(emitterService.exists('forgot:password')) 41 assert.isFalse(emitterService.exists('forgot:password'));
40 }) 42 });
41 43
42 test('returns `email send when exists` and trigger forgot:password event', async ({ 44 test('returns `email send when exists` and trigger forgot:password event', async ({
43 client, 45 client,
44 assert, 46 assert,
45 }) => { 47 }) => {
46 const emitterService = emitter.fake() 48 const emitterService = emitter.fake();
47 const user = await UserFactory.merge({ 49 const user = await UserFactory.merge({
48 email: 'test+forgot_password@ferdium.org', 50 email: 'test+forgot_password@ferdium.org',
49 }).create() 51 }).create();
50 52
51 const response = await client.post('/user/forgot').fields({ 53 const response = await client.post('/user/forgot').fields({
52 mail: 'test+forgot_password@ferdium.org', 54 mail: 'test+forgot_password@ferdium.org',
53 }) 55 });
54 56
55 response.assertStatus(200) 57 response.assertStatus(200);
56 response.assertTextIncludes( 58 response.assertTextIncludes(
57 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.' 59 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.',
58 ) 60 );
59 61
60 assert.isTrue( 62 assert.isTrue(
61 emitterService.exists( 63 emitterService.exists(
62 (event) => event.name === 'forgot:password' && event.data.user.email === user.email 64 event =>
63 ) 65 event.name === 'forgot:password' &&
64 ) 66 event.data.user.email === user.email,
65 }) 67 ),
66}) 68 );
69 });
70});