From 65ba80b5a369de1546a1a040c2a42eda20dc901b Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 5 Apr 2024 18:02:52 +0800 Subject: [PATCH] fix tests --- packages/api/test/routers/auth.test.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/api/test/routers/auth.test.ts b/packages/api/test/routers/auth.test.ts index 92ded5e51..f1f6c5da6 100644 --- a/packages/api/test/routers/auth.test.ts +++ b/packages/api/test/routers/auth.test.ts @@ -1,4 +1,4 @@ -import { Job } from 'bullmq' +import { Job, Queue } from 'bullmq' import chai, { expect } from 'chai' import sinon from 'sinon' import sinonChai from 'sinon-chai' @@ -372,7 +372,11 @@ describe('auth router', () => { context('when reset password email sent', () => { before(() => { - sinon.replace(createTask, 'enqueueSendEmail', sinon.fake()) + sinon.replace( + createTask, + 'enqueueSendEmail', + sinon.fake.resolves(new Job(new Queue('test'), 'test', 'test')) + ) }) after(() => { @@ -426,6 +430,19 @@ describe('auth router', () => { }) }) }) + + context('when email is empty', () => { + before(() => { + email = '' + }) + + it('redirects to forgot-password page with error code INVALID_EMAIL', async () => { + const res = await emailResetPasswordReq(email).expect(302) + expect(res.header.location).to.endWith( + '/forgot-password?errorCodes=INVALID_EMAIL' + ) + }) + }) }) describe('reset-password', () => {