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