aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/dashboard/reset-password.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/dashboard/reset-password.spec.ts')
-rw-r--r--tests/functional/dashboard/reset-password.spec.ts84
1 files changed, 38 insertions, 46 deletions
diff --git a/tests/functional/dashboard/reset-password.spec.ts b/tests/functional/dashboard/reset-password.spec.ts
index e488482..8883665 100644
--- a/tests/functional/dashboard/reset-password.spec.ts
+++ b/tests/functional/dashboard/reset-password.spec.ts
@@ -1,26 +1,22 @@
1import { test } from '@japa/runner'; 1import { test } from '@japa/runner'
2import Token from 'App/Models/Token'; 2import Token from '#app/Models/Token'
3import UserFactory from 'Database/factories/UserFactory'; 3import UserFactory from '#database/factories/UserFactory'
4import TokenFactory from 'Database/factories/TokenFactory'; 4import TokenFactory from '#database/factories/TokenFactory'
5 5
6test.group('Dashboard / Reset password page', () => { 6test.group('Dashboard / Reset password page', () => {
7 test('returns a `Invalid token` message when opening without a token', async ({ 7 test('returns a `Invalid token` message when opening without a token', async ({ client }) => {
8 client, 8 const response = await client.get('/user/reset')
9 }) => {
10 const response = await client.get('/user/reset');
11 9
12 response.assertStatus(200); 10 response.assertStatus(200)
13 response.assertTextIncludes('Invalid token'); 11 response.assertTextIncludes('Invalid token')
14 }); 12 })
15 13
16 test('displays the form when a token is provided', async ({ client }) => { 14 test('displays the form when a token is provided', async ({ client }) => {
17 const response = await client.get( 15 const response = await client.get('/user/reset?token=randomtokenbutitworks')
18 '/user/reset?token=randomtokenbutitworks',
19 );
20 16
21 response.assertStatus(200); 17 response.assertStatus(200)
22 response.assertTextIncludes('Reset Your Password'); 18 response.assertTextIncludes('Reset Your Password')
23 }); 19 })
24 20
25 test('returns `passwords do not match` message when passwords do not match', async ({ 21 test('returns `passwords do not match` message when passwords do not match', async ({
26 client, 22 client,
@@ -29,22 +25,20 @@ test.group('Dashboard / Reset password page', () => {
29 token: 'randomnotworkingtoken', 25 token: 'randomnotworkingtoken',
30 password: 'password', 26 password: 'password',
31 password_confirmation: 'not_matching', 27 password_confirmation: 'not_matching',
32 }); 28 })
33 29
34 response.assertTextIncludes('Passwords do not match'); 30 response.assertTextIncludes('Passwords do not match')
35 }); 31 })
36 32
37 test('returns `Cannot reset your password` when token does not exist', async ({ 33 test('returns `Cannot reset your password` when token does not exist', async ({ client }) => {
38 client,
39 }) => {
40 const response = await client.post('/user/reset').fields({ 34 const response = await client.post('/user/reset').fields({
41 token: 'randomnotworkingtoken', 35 token: 'randomnotworkingtoken',
42 password: 'password', 36 password: 'password',
43 password_confirmation: 'password', 37 password_confirmation: 'password',
44 }); 38 })
45 39
46 response.assertTextIncludes('Cannot reset your password'); 40 response.assertTextIncludes('Cannot reset your password')
47 }); 41 })
48 42
49 test('returns `Cannot reset your password` when token is older than 24 hours', async ({ 43 test('returns `Cannot reset your password` when token is older than 24 hours', async ({
50 client, 44 client,
@@ -54,41 +48,39 @@ test.group('Dashboard / Reset password page', () => {
54 user_id: (await UserFactory.create()).id, 48 user_id: (await UserFactory.create()).id,
55 }) 49 })
56 .apply('old_token') 50 .apply('old_token')
57 .create(); 51 .create()
58 52
59 const response = await client.post('/user/reset').fields({ 53 const response = await client.post('/user/reset').fields({
60 token: token.token, 54 token: token.token,
61 password: 'password', 55 password: 'password',
62 password_confirmation: 'password', 56 password_confirmation: 'password',
63 }); 57 })
64 58
65 response.assertTextIncludes('Cannot reset your password'); 59 response.assertTextIncludes('Cannot reset your password')
66 }); 60 })
67 61
68 test('returns `Cannot reset your password` when token is revoked', async ({ 62 test('returns `Cannot reset your password` when token is revoked', async ({ client }) => {
69 client,
70 }) => {
71 const token = await TokenFactory.merge({ 63 const token = await TokenFactory.merge({
72 // eslint-disable-next-line unicorn/no-await-expression-member 64 // eslint-disable-next-line unicorn/no-await-expression-member
73 user_id: (await UserFactory.create()).id, 65 user_id: (await UserFactory.create()).id,
74 }) 66 })
75 .apply('revoked') 67 .apply('revoked')
76 .create(); 68 .create()
77 69
78 const response = await client.post('/user/reset').fields({ 70 const response = await client.post('/user/reset').fields({
79 token: token.token, 71 token: token.token,
80 password: 'password', 72 password: 'password',
81 password_confirmation: 'password', 73 password_confirmation: 'password',
82 }); 74 })
83 75
84 response.assertTextIncludes('Cannot reset your password'); 76 response.assertTextIncludes('Cannot reset your password')
85 }); 77 })
86 78
87 test('correctly resets password and deletes token and able to login with new password', async ({ 79 test('correctly resets password and deletes token and able to login with new password', async ({
88 client, 80 client,
89 assert, 81 assert,
90 }) => { 82 }) => {
91 const userEmail = 'working-reset-password-login@ferdium.org'; 83 const userEmail = 'working-reset-password-login@ferdium.org'
92 const token = await TokenFactory.merge({ 84 const token = await TokenFactory.merge({
93 user_id: 85 user_id:
94 ( 86 (
@@ -98,25 +90,25 @@ test.group('Dashboard / Reset password page', () => {
98 // prettier-ignore 90 // prettier-ignore
99 // eslint-disable-next-line unicorn/no-await-expression-member 91 // eslint-disable-next-line unicorn/no-await-expression-member
100 ).id, 92 ).id,
101 }).create(); 93 }).create()
102 94
103 const response = await client.post('/user/reset').fields({ 95 const response = await client.post('/user/reset').fields({
104 token: token.token, 96 token: token.token,
105 password: 'new_password', 97 password: 'new_password',
106 password_confirmation: 'new_password', 98 password_confirmation: 'new_password',
107 }); 99 })
108 100
109 // Assert response is as expected 101 // Assert response is as expected
110 response.assertTextIncludes('Successfully reset your password'); 102 response.assertTextIncludes('Successfully reset your password')
111 103
112 // Token should be deleted from database 104 // Token should be deleted from database
113 assert.isNull(await Token.query().where('token', token.token).first()); 105 assert.isNull(await Token.query().where('token', token.token).first())
114 106
115 const loginResponse = await client.post('/user/login').fields({ 107 const loginResponse = await client.post('/user/login').fields({
116 mail: userEmail, 108 mail: userEmail,
117 password: 'new_password', 109 password: 'new_password',
118 }); 110 })
119 111
120 loginResponse.assertRedirectsTo('/user/account'); 112 loginResponse.assertRedirectsTo('/user/account')
121 }); 113 })
122}); 114})