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