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