aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional/dashboard/delete.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional/dashboard/delete.spec.ts')
-rw-r--r--tests/functional/dashboard/delete.spec.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/functional/dashboard/delete.spec.ts b/tests/functional/dashboard/delete.spec.ts
new file mode 100644
index 0000000..ae3f0e6
--- /dev/null
+++ b/tests/functional/dashboard/delete.spec.ts
@@ -0,0 +1,37 @@
1import { test } from '@japa/runner';
2import User from 'App/Models/User';
3import UserFactory from 'Database/factories/UserFactory';
4
5test.group('Dashboard / Delete account page', () => {
6 test('redirects to /user/login when accessing /user/delete as guest', async ({
7 client,
8 }) => {
9 const response = await client.get('/user/delete');
10
11 response.assertRedirectsTo('/user/login'); // Check if it redirects to the expected URL
12 });
13
14 test('returns a 200 opening the delete route while logged in', async ({
15 client,
16 }) => {
17 const user = await UserFactory.create();
18 const response = await client.get('/user/delete').loginAs(user);
19
20 response.assertStatus(200);
21 response.assertTextIncludes('Delete your account');
22 });
23
24 test('returns a 200 opening the delete route while logged in', async ({
25 client,
26 assert,
27 }) => {
28 const user = await UserFactory.create();
29 const response = await client.post('/user/delete').loginAs(user);
30
31 response.assertRedirectsTo('/user/login');
32 // This asserts the session is deleted as well
33 response.assertSessionMissing('auth_web');
34
35 assert.isNull(await User.find(user.id));
36 });
37});