From 7584d2d7a7110aef0331ebfa178b2295842c59fa Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Sat, 10 Feb 2024 18:19:14 -0700 Subject: refactor: project maintenance - work in progress --- tests/functional/dashboard/forgot-password.spec.ts | 66 ++++++++++------------ 1 file changed, 31 insertions(+), 35 deletions(-) (limited to 'tests/functional/dashboard/forgot-password.spec.ts') diff --git a/tests/functional/dashboard/forgot-password.spec.ts b/tests/functional/dashboard/forgot-password.spec.ts index 9dcec5a..7c356c8 100644 --- a/tests/functional/dashboard/forgot-password.spec.ts +++ b/tests/functional/dashboard/forgot-password.spec.ts @@ -1,70 +1,66 @@ -import { test } from '@japa/runner'; -import Event from '@ioc:Adonis/Core/Event'; -import UserFactory from 'Database/factories/UserFactory'; +import { test } from '@japa/runner' +import emitter from '@adonisjs/core/services/emitter' +import UserFactory from '#database/factories/UserFactory' test.group('Dashboard / Forgot password page', () => { - test('returns a 200 opening the forgot password route', async ({ - client, - }) => { - const response = await client.get('/user/forgot'); + test('returns a 200 opening the forgot password route', async ({ client }) => { + const response = await client.get('/user/forgot') - response.assertStatus(200); - response.assertTextIncludes('Forgot Password?'); - }); + response.assertStatus(200) + response.assertTextIncludes('Forgot Password?') + }) test('returns `Please enter a valid email address` when providing invalid email', async ({ client, }) => { const response = await client.post('/user/forgot').fields({ mail: 'invalid', - }); + }) - response.assertStatus(200); - response.assertTextIncludes('Please enter a valid email address'); - }); + response.assertStatus(200) + response.assertTextIncludes('Please enter a valid email address') + }) test('returns `email send when exists` without forgot:password event', async ({ client, assert, }) => { - const emitter = Event.fake(); + const emitterService = emitter.fake() const response = await client.post('/user/forgot').fields({ mail: 'test@ferdium.org', - }); + }) - response.assertStatus(200); + response.assertStatus(200) response.assertTextIncludes( - 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.', - ); + 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.' + ) - assert.isFalse(emitter.exists('forgot:password')); - }); + assert.isFalse(emitterService.exists('forgot:password')) + }) test('returns `email send when exists` and trigger forgot:password event', async ({ client, assert, }) => { - const emitter = Event.fake(); + const emitterService = emitter.fake() const user = await UserFactory.merge({ email: 'test+forgot_password@ferdium.org', - }).create(); + }).create() const response = await client.post('/user/forgot').fields({ mail: 'test+forgot_password@ferdium.org', - }); + }) - response.assertStatus(200); + response.assertStatus(200) response.assertTextIncludes( - 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.', - ); + 'If your provided E-Mail address is linked to an account, we have just sent an E-Mail to that address.' + ) assert.isTrue( - emitter.exists( - event => - event.name === 'forgot:password' && - event.data.user.email === user.email, - ), - ); - }); -}); + emitterService.exists( + (event) => event.name === 'forgot:password' && event.data.user.email === user.email + ) + ) + }) +}) -- cgit v1.2.3-70-g09d2