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