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