diff options
Diffstat (limited to 'tests/functional/dashboard/login.spec.ts')
-rw-r--r-- | tests/functional/dashboard/login.spec.ts | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/tests/functional/dashboard/login.spec.ts b/tests/functional/dashboard/login.spec.ts index cf482cd..21101da 100644 --- a/tests/functional/dashboard/login.spec.ts +++ b/tests/functional/dashboard/login.spec.ts | |||
@@ -1,57 +1,65 @@ | |||
1 | import { test } from '@japa/runner' | 1 | import { test } from '@japa/runner'; |
2 | import UserFactory from '#database/factories/UserFactory' | 2 | import UserFactory from '#database/factories/UserFactory'; |
3 | 3 | ||
4 | test.group('Dashboard / Login page', () => { | 4 | test.group('Dashboard / Login page', () => { |
5 | test('returns a 200 opening the login route', async ({ client }) => { | 5 | test('returns a 200 opening the login route', async ({ client }) => { |
6 | const response = await client.get('/user/login') | 6 | const response = await client.get('/user/login'); |
7 | 7 | ||
8 | response.assertStatus(200) | 8 | response.assertStatus(200); |
9 | }) | 9 | }); |
10 | 10 | ||
11 | test('returns `invalid mail or password` when validation fails', async ({ client }) => { | 11 | test('returns `invalid mail or password` when validation fails', async ({ |
12 | client, | ||
13 | }) => { | ||
12 | const response = await client.post('/user/login').fields({ | 14 | const response = await client.post('/user/login').fields({ |
13 | mail: 'invalid', | 15 | mail: 'invalid', |
14 | password: 'invalid', | 16 | password: 'invalid', |
15 | }) | 17 | }); |
16 | 18 | ||
17 | response.assertRedirectsTo('/user/login') | 19 | response.assertRedirectsTo('/user/login'); |
18 | response.assertTextIncludes('Invalid mail or password') | 20 | response.assertTextIncludes('Invalid mail or password'); |
19 | }) | 21 | }); |
20 | 22 | ||
21 | test('returns `invalid mail or password` when account is not found', async ({ client }) => { | 23 | test('returns `invalid mail or password` when account is not found', async ({ |
24 | client, | ||
25 | }) => { | ||
22 | const response = await client.post('/user/login').fields({ | 26 | const response = await client.post('/user/login').fields({ |
23 | mail: 'test+notexistingpassword@ferdium.org', | 27 | mail: 'test+notexistingpassword@ferdium.org', |
24 | password: 'notexistingpassword', | 28 | password: 'notexistingpassword', |
25 | }) | 29 | }); |
26 | 30 | ||
27 | response.assertRedirectsTo('/user/login') | 31 | response.assertRedirectsTo('/user/login'); |
28 | response.assertTextIncludes('Invalid mail or password') | 32 | response.assertTextIncludes('Invalid mail or password'); |
29 | }) | 33 | }); |
30 | 34 | ||
31 | test('returns `invalid mail or password` when password is not valid', async ({ client }) => { | 35 | test('returns `invalid mail or password` when password is not valid', async ({ |
36 | client, | ||
37 | }) => { | ||
32 | await UserFactory.merge({ | 38 | await UserFactory.merge({ |
33 | email: 'test@ferdium.org', | 39 | email: 'test@ferdium.org', |
34 | }).create() | 40 | }).create(); |
35 | 41 | ||
36 | const response = await client.post('/user/login').fields({ | 42 | const response = await client.post('/user/login').fields({ |
37 | mail: 'test+invalid_password@ferdium.org', | 43 | mail: 'test+invalid_password@ferdium.org', |
38 | password: 'invalid_password', | 44 | password: 'invalid_password', |
39 | }) | 45 | }); |
40 | 46 | ||
41 | response.assertRedirectsTo('/user/login') | 47 | response.assertRedirectsTo('/user/login'); |
42 | response.assertTextIncludes('Invalid mail or password') | 48 | response.assertTextIncludes('Invalid mail or password'); |
43 | }) | 49 | }); |
44 | 50 | ||
45 | test('redirects to account page when user is able to login', async ({ client }) => { | 51 | test('redirects to account page when user is able to login', async ({ |
52 | client, | ||
53 | }) => { | ||
46 | await UserFactory.merge({ | 54 | await UserFactory.merge({ |
47 | email: 'test+password@ferdium.org', | 55 | email: 'test+password@ferdium.org', |
48 | }).create() | 56 | }).create(); |
49 | 57 | ||
50 | const response = await client.post('/user/login').fields({ | 58 | const response = await client.post('/user/login').fields({ |
51 | mail: 'test+password@ferdium.org', | 59 | mail: 'test+password@ferdium.org', |
52 | password: 'password', | 60 | password: 'password', |
53 | }) | 61 | }); |
54 | 62 | ||
55 | response.assertRedirectsTo('/user/account') | 63 | response.assertRedirectsTo('/user/account'); |
56 | }) | 64 | }); |
57 | }) | 65 | }); |