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/account.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/account.spec.ts')
-rw-r--r-- | tests/functional/dashboard/account.spec.ts | 129 |
1 files changed, 72 insertions, 57 deletions
diff --git a/tests/functional/dashboard/account.spec.ts b/tests/functional/dashboard/account.spec.ts index 25de22c..c5ede13 100644 --- a/tests/functional/dashboard/account.spec.ts +++ b/tests/functional/dashboard/account.spec.ts | |||
@@ -1,109 +1,124 @@ | |||
1 | import { test } from '@japa/runner' | 1 | import { test } from '@japa/runner'; |
2 | import User from '#app/Models/User' | 2 | import User from '#app/Models/User'; |
3 | import UserFactory from '#database/factories/UserFactory' | 3 | import UserFactory from '#database/factories/UserFactory'; |
4 | 4 | ||
5 | test.group('Dashboard / Account page', () => { | 5 | test.group('Dashboard / Account page', () => { |
6 | test('redirects to /user/login when accessing /user/account as guest', async ({ client }) => { | 6 | test('redirects to /user/login when accessing /user/account as guest', async ({ |
7 | const response = await client.get('/user/account') | 7 | client, |
8 | }) => { | ||
9 | const response = await client.get('/user/account'); | ||
8 | 10 | ||
9 | response.assertRedirectsTo('/user/login') // Check if it redirects to the expected URL | 11 | response.assertRedirectsTo('/user/login'); // Check if it redirects to the expected URL |
10 | }) | 12 | }); |
11 | 13 | ||
12 | test('returns a 200 opening the account route while logged in', async ({ client }) => { | 14 | test('returns a 200 opening the account route while logged in', async ({ |
13 | const user = await UserFactory.create() | 15 | client, |
14 | const response = await client.get('/user/account').loginAs(user) | 16 | }) => { |
17 | const user = await UserFactory.create(); | ||
18 | const response = await client.get('/user/account').loginAs(user); | ||
15 | 19 | ||
16 | response.assertStatus(200) | 20 | response.assertStatus(200); |
17 | response.assertTextIncludes('Your Ferdium account') | 21 | response.assertTextIncludes('Your Ferdium account'); |
18 | 22 | ||
19 | response.assertTextIncludes(user.email) | 23 | response.assertTextIncludes(user.email); |
20 | response.assertTextIncludes(user.username) | 24 | response.assertTextIncludes(user.username); |
21 | response.assertTextIncludes(user.lastname) | 25 | response.assertTextIncludes(user.lastname); |
22 | }) | 26 | }); |
23 | 27 | ||
24 | test('returns a validation error for all fields when missing', async ({ client }) => { | 28 | test('returns a validation error for all fields when missing', async ({ |
25 | const user = await UserFactory.create() | 29 | client, |
26 | const response = await client.post('/user/account').loginAs(user) | 30 | }) => { |
31 | const user = await UserFactory.create(); | ||
32 | const response = await client.post('/user/account').loginAs(user); | ||
27 | 33 | ||
28 | response.assertTextIncludes( | 34 | response.assertTextIncludes( |
29 | 'value="required validation failed,required validation failed" placeholder="E-Mail"' | 35 | 'value="required validation failed,required validation failed" placeholder="E-Mail"', |
30 | ) | 36 | ); |
31 | response.assertTextIncludes( | 37 | response.assertTextIncludes( |
32 | 'value="required validation failed,required validation failed" placeholder="Name"' | 38 | 'value="required validation failed,required validation failed" placeholder="Name"', |
33 | ) | 39 | ); |
34 | response.assertTextIncludes( | 40 | response.assertTextIncludes( |
35 | 'value="required validation failed,required validation failed" placeholder="Last Name"' | 41 | 'value="required validation failed,required validation failed" placeholder="Last Name"', |
36 | ) | 42 | ); |
37 | }) | 43 | }); |
38 | 44 | ||
39 | test('returns a validation error for username when there is another user with same username', async ({ | 45 | test('returns a validation error for username when there is another user with same username', async ({ |
40 | client, | 46 | client, |
41 | }) => { | 47 | }) => { |
42 | const user = await UserFactory.create() | 48 | const user = await UserFactory.create(); |
43 | const existingUser = await UserFactory.create() | 49 | const existingUser = await UserFactory.create(); |
44 | 50 | ||
45 | const response = await client.post('/user/account').loginAs(user).form({ | 51 | const response = await client.post('/user/account').loginAs(user).form({ |
46 | username: existingUser.username, | 52 | username: existingUser.username, |
47 | email: user.email, | 53 | email: user.email, |
48 | lastname: user.lastname, | 54 | lastname: user.lastname, |
49 | }) | 55 | }); |
50 | 56 | ||
51 | response.assertTextIncludes('value="unique validation failure" placeholder="Name"') | 57 | response.assertTextIncludes( |
52 | }) | 58 | 'value="unique validation failure" placeholder="Name"', |
59 | ); | ||
60 | }); | ||
53 | 61 | ||
54 | test('returns a validation error for email when there is another user with same email', async ({ | 62 | test('returns a validation error for email when there is another user with same email', async ({ |
55 | client, | 63 | client, |
56 | }) => { | 64 | }) => { |
57 | const user = await UserFactory.create() | 65 | const user = await UserFactory.create(); |
58 | const existingUser = await UserFactory.create() | 66 | const existingUser = await UserFactory.create(); |
59 | 67 | ||
60 | const response = await client.post('/user/account').loginAs(user).form({ | 68 | const response = await client.post('/user/account').loginAs(user).form({ |
61 | username: user.username, | 69 | username: user.username, |
62 | email: existingUser.email, | 70 | email: existingUser.email, |
63 | lastname: user.lastname, | 71 | lastname: user.lastname, |
64 | }) | 72 | }); |
65 | 73 | ||
66 | response.assertTextIncludes('value="unique validation failure" placeholder="E-Mail"') | 74 | response.assertTextIncludes( |
67 | }) | 75 | 'value="unique validation failure" placeholder="E-Mail"', |
76 | ); | ||
77 | }); | ||
68 | 78 | ||
69 | test('updates user data and ensures the data is persisted', async ({ client, assert }) => { | 79 | test('updates user data and ensures the data is persisted', async ({ |
70 | const user = await UserFactory.create() | 80 | client, |
81 | assert, | ||
82 | }) => { | ||
83 | const user = await UserFactory.create(); | ||
71 | const response = await client.post('/user/account').loginAs(user).form({ | 84 | const response = await client.post('/user/account').loginAs(user).form({ |
72 | username: 'edited-username', | 85 | username: 'edited-username', |
73 | email: 'edited-email', | 86 | email: 'edited-email', |
74 | lastname: 'edited-lastname', | 87 | lastname: 'edited-lastname', |
75 | }) | 88 | }); |
76 | 89 | ||
77 | response.assertStatus(200) | 90 | response.assertStatus(200); |
78 | 91 | ||
79 | // Ensure updated data is displayed on account page | 92 | // Ensure updated data is displayed on account page |
80 | response.assertTextIncludes('edited-username') | 93 | response.assertTextIncludes('edited-username'); |
81 | response.assertTextIncludes('edited-email') | 94 | response.assertTextIncludes('edited-email'); |
82 | response.assertTextIncludes('edited-lastname') | 95 | response.assertTextIncludes('edited-lastname'); |
83 | 96 | ||
84 | // Ensure updated data is persisted in database | 97 | // Ensure updated data is persisted in database |
85 | const updatedUser = await User.findBy('id', user.id) | 98 | const updatedUser = await User.findBy('id', user.id); |
86 | assert.equal(updatedUser?.username, 'edited-username') | 99 | assert.equal(updatedUser?.username, 'edited-username'); |
87 | assert.equal(updatedUser?.email, 'edited-email') | 100 | assert.equal(updatedUser?.email, 'edited-email'); |
88 | assert.equal(updatedUser?.lastname, 'edited-lastname') | 101 | assert.equal(updatedUser?.lastname, 'edited-lastname'); |
89 | }) | 102 | }); |
90 | 103 | ||
91 | test('updates user password and ensures the user can still login', async ({ client }) => { | 104 | test('updates user password and ensures the user can still login', async ({ |
92 | const user = await UserFactory.create() | 105 | client, |
106 | }) => { | ||
107 | const user = await UserFactory.create(); | ||
93 | const response = await client.post('/user/account').loginAs(user).form({ | 108 | const response = await client.post('/user/account').loginAs(user).form({ |
94 | username: user.username, | 109 | username: user.username, |
95 | email: user.email, | 110 | email: user.email, |
96 | lastname: user.lastname, | 111 | lastname: user.lastname, |
97 | password: 'modified-password-account-page', | 112 | password: 'modified-password-account-page', |
98 | }) | 113 | }); |
99 | 114 | ||
100 | response.assertStatus(200) | 115 | response.assertStatus(200); |
101 | 116 | ||
102 | const loginResponse = await client.post('/user/login').fields({ | 117 | const loginResponse = await client.post('/user/login').fields({ |
103 | mail: user.email, | 118 | mail: user.email, |
104 | password: 'modified-password-account-page', | 119 | password: 'modified-password-account-page', |
105 | }) | 120 | }); |
106 | 121 | ||
107 | loginResponse.assertRedirectsTo('/user/account') | 122 | loginResponse.assertRedirectsTo('/user/account'); |
108 | }) | 123 | }); |
109 | }) | 124 | }); |