From e1c47572a6235fd8fd20af888ac3a11c7ae1369d Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:37:40 -0700 Subject: updates --- tests/functional/dashboard/reset-password.spec.ts | 84 +++++++++++++---------- 1 file changed, 46 insertions(+), 38 deletions(-) (limited to 'tests/functional/dashboard/reset-password.spec.ts') diff --git a/tests/functional/dashboard/reset-password.spec.ts b/tests/functional/dashboard/reset-password.spec.ts index 8883665..cde8808 100644 --- a/tests/functional/dashboard/reset-password.spec.ts +++ b/tests/functional/dashboard/reset-password.spec.ts @@ -1,22 +1,26 @@ -import { test } from '@japa/runner' -import Token from '#app/Models/Token' -import UserFactory from '#database/factories/UserFactory' -import TokenFactory from '#database/factories/TokenFactory' +import { test } from '@japa/runner'; +import Token from '#app/Models/Token'; +import UserFactory from '#database/factories/UserFactory'; +import TokenFactory from '#database/factories/TokenFactory'; test.group('Dashboard / Reset password page', () => { - test('returns a `Invalid token` message when opening without a token', async ({ client }) => { - const response = await client.get('/user/reset') + test('returns a `Invalid token` message when opening without a token', async ({ + client, + }) => { + const response = await client.get('/user/reset'); - response.assertStatus(200) - response.assertTextIncludes('Invalid token') - }) + response.assertStatus(200); + response.assertTextIncludes('Invalid token'); + }); test('displays the form when a token is provided', async ({ client }) => { - const response = await client.get('/user/reset?token=randomtokenbutitworks') + const response = await client.get( + '/user/reset?token=randomtokenbutitworks', + ); - response.assertStatus(200) - response.assertTextIncludes('Reset Your Password') - }) + response.assertStatus(200); + response.assertTextIncludes('Reset Your Password'); + }); test('returns `passwords do not match` message when passwords do not match', async ({ client, @@ -25,20 +29,22 @@ test.group('Dashboard / Reset password page', () => { token: 'randomnotworkingtoken', password: 'password', password_confirmation: 'not_matching', - }) + }); - response.assertTextIncludes('Passwords do not match') - }) + response.assertTextIncludes('Passwords do not match'); + }); - test('returns `Cannot reset your password` when token does not exist', async ({ client }) => { + test('returns `Cannot reset your password` when token does not exist', async ({ + client, + }) => { const response = await client.post('/user/reset').fields({ token: 'randomnotworkingtoken', password: 'password', password_confirmation: 'password', - }) + }); - response.assertTextIncludes('Cannot reset your password') - }) + response.assertTextIncludes('Cannot reset your password'); + }); test('returns `Cannot reset your password` when token is older than 24 hours', async ({ client, @@ -48,39 +54,41 @@ test.group('Dashboard / Reset password page', () => { user_id: (await UserFactory.create()).id, }) .apply('old_token') - .create() + .create(); const response = await client.post('/user/reset').fields({ token: token.token, password: 'password', password_confirmation: 'password', - }) + }); - response.assertTextIncludes('Cannot reset your password') - }) + response.assertTextIncludes('Cannot reset your password'); + }); - test('returns `Cannot reset your password` when token is revoked', async ({ client }) => { + test('returns `Cannot reset your password` when token is revoked', async ({ + client, + }) => { const token = await TokenFactory.merge({ // eslint-disable-next-line unicorn/no-await-expression-member user_id: (await UserFactory.create()).id, }) .apply('revoked') - .create() + .create(); const response = await client.post('/user/reset').fields({ token: token.token, password: 'password', password_confirmation: 'password', - }) + }); - response.assertTextIncludes('Cannot reset your password') - }) + response.assertTextIncludes('Cannot reset your password'); + }); test('correctly resets password and deletes token and able to login with new password', async ({ client, assert, }) => { - const userEmail = 'working-reset-password-login@ferdium.org' + const userEmail = 'working-reset-password-login@ferdium.org'; const token = await TokenFactory.merge({ user_id: ( @@ -90,25 +98,25 @@ test.group('Dashboard / Reset password page', () => { // prettier-ignore // eslint-disable-next-line unicorn/no-await-expression-member ).id, - }).create() + }).create(); const response = await client.post('/user/reset').fields({ token: token.token, password: 'new_password', password_confirmation: 'new_password', - }) + }); // Assert response is as expected - response.assertTextIncludes('Successfully reset your password') + response.assertTextIncludes('Successfully reset your password'); // Token should be deleted from database - assert.isNull(await Token.query().where('token', token.token).first()) + assert.isNull(await Token.query().where('token', token.token).first()); const loginResponse = await client.post('/user/login').fields({ mail: userEmail, password: 'new_password', - }) + }); - loginResponse.assertRedirectsTo('/user/account') - }) -}) + loginResponse.assertRedirectsTo('/user/account'); + }); +}); -- cgit v1.2.3-70-g09d2