diff options
Diffstat (limited to 'tests/functional/dashboard/export.spec.ts')
-rw-r--r-- | tests/functional/dashboard/export.spec.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/functional/dashboard/export.spec.ts b/tests/functional/dashboard/export.spec.ts new file mode 100644 index 0000000..4250622 --- /dev/null +++ b/tests/functional/dashboard/export.spec.ts | |||
@@ -0,0 +1,61 @@ | |||
1 | import { test } from '@japa/runner'; | ||
2 | import UserFactory from 'Database/factories/UserFactory'; | ||
3 | |||
4 | test.group('Dashboard / Export page', () => { | ||
5 | test('redirects to /user/login when accessing /user/transfer as guest', async ({ | ||
6 | client, | ||
7 | }) => { | ||
8 | const response = await client.get('/user/transfer'); | ||
9 | |||
10 | response.assertRedirectsTo('/user/login'); // Check if it redirects to the expected URL | ||
11 | }); | ||
12 | |||
13 | test('returns a correct export with user data', async ({ | ||
14 | assert, | ||
15 | client, | ||
16 | }) => { | ||
17 | const user = await UserFactory.create(); | ||
18 | const response = await client.get('/user/export').loginAs(user); | ||
19 | |||
20 | response.assertStatus(200); | ||
21 | const exportData = JSON.parse(response.text()); | ||
22 | |||
23 | assert.equal(exportData.username, user.username); | ||
24 | assert.equal(exportData.lastname, user.lastname); | ||
25 | assert.equal(exportData.mail, user.email); | ||
26 | }); | ||
27 | |||
28 | // TODO: We can improve this test by hard checking the export data | ||
29 | test('returns a correct export with service data', async ({ | ||
30 | assert, | ||
31 | client, | ||
32 | }) => { | ||
33 | const user = await UserFactory.with('services', 5).create(); | ||
34 | const response = await client.get('/user/export').loginAs(user); | ||
35 | |||
36 | response.assertStatus(200); | ||
37 | const exportData = JSON.parse(response.text()); | ||
38 | |||
39 | assert.equal(exportData.username, user.username); | ||
40 | assert.equal(exportData.lastname, user.lastname); | ||
41 | assert.equal(exportData.mail, user.email); | ||
42 | assert.equal(exportData.services.length, user.services.length); | ||
43 | }); | ||
44 | |||
45 | // TODO: We can improve this test by hard checking the export data | ||
46 | test('returns a correct export with workspace data', async ({ | ||
47 | assert, | ||
48 | client, | ||
49 | }) => { | ||
50 | const user = await UserFactory.with('workspaces', 5).create(); | ||
51 | const response = await client.get('/user/export').loginAs(user); | ||
52 | |||
53 | response.assertStatus(200); | ||
54 | const exportData = JSON.parse(response.text()); | ||
55 | |||
56 | assert.equal(exportData.username, user.username); | ||
57 | assert.equal(exportData.lastname, user.lastname); | ||
58 | assert.equal(exportData.mail, user.email); | ||
59 | assert.equal(exportData.workspaces.length, user.workspaces.length); | ||
60 | }); | ||
61 | }); | ||