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