aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/dashboard/login.spec.ts
blob: cf482cd155196b454891d1f732ee138b22eb43da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { test } from '@japa/runner'
import UserFactory from '#database/factories/UserFactory'

test.group('Dashboard / Login page', () => {
  test('returns a 200 opening the login route', async ({ client }) => {
    const response = await client.get('/user/login')

    response.assertStatus(200)
  })

  test('returns `invalid mail or password` when validation fails', async ({ client }) => {
    const response = await client.post('/user/login').fields({
      mail: 'invalid',
      password: 'invalid',
    })

    response.assertRedirectsTo('/user/login')
    response.assertTextIncludes('Invalid mail or password')
  })

  test('returns `invalid mail or password` when account is not found', async ({ client }) => {
    const response = await client.post('/user/login').fields({
      mail: 'test+notexistingpassword@ferdium.org',
      password: 'notexistingpassword',
    })

    response.assertRedirectsTo('/user/login')
    response.assertTextIncludes('Invalid mail or password')
  })

  test('returns `invalid mail or password` when password is not valid', async ({ client }) => {
    await UserFactory.merge({
      email: 'test@ferdium.org',
    }).create()

    const response = await client.post('/user/login').fields({
      mail: 'test+invalid_password@ferdium.org',
      password: 'invalid_password',
    })

    response.assertRedirectsTo('/user/login')
    response.assertTextIncludes('Invalid mail or password')
  })

  test('redirects to account page when user is able to login', async ({ client }) => {
    await UserFactory.merge({
      email: 'test+password@ferdium.org',
    }).create()

    const response = await client.post('/user/login').fields({
      mail: 'test+password@ferdium.org',
      password: 'password',
    })

    response.assertRedirectsTo('/user/account')
  })
})