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