From e4790c5603daa42b5ed991d2d12acc74c8411176 Mon Sep 17 00:00:00 2001 From: seaerchin Date: Wed, 7 Apr 2021 16:18:38 +0800 Subject: [PATCH] test(public-form): fixed tests so that privateFormError is checked correctly --- .../public-form/__tests__/public-form.controller.spec.ts | 5 ++++- .../public-form/__tests__/public-form.routes.spec.ts | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts b/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts index 2d592f65e1..980fa978ed 100644 --- a/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts +++ b/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts @@ -952,10 +952,11 @@ describe('public-form.controller', () => { // Arrange // 1. Mock the response const mockRes = expressHandler.mockResponse() + const MOCK_FORM_TITLE = 'private form' // 2. Mock the call to retrieve the form MockAuthService.getFormIfPublic.mockReturnValueOnce( - errAsync(new PrivateFormError(MOCK_ERROR_STRING, 'private form')), + errAsync(new PrivateFormError(MOCK_ERROR_STRING, MOCK_FORM_TITLE)), ) // Act @@ -977,6 +978,8 @@ describe('public-form.controller', () => { expect(mockRes.status).toHaveBeenCalledWith(404) expect(mockRes.json).toHaveBeenCalledWith({ message: MOCK_ERROR_STRING, + formTitle: MOCK_FORM_TITLE, + isPageFound: true, }) }) }) diff --git a/src/app/modules/form/public-form/__tests__/public-form.routes.spec.ts b/src/app/modules/form/public-form/__tests__/public-form.routes.spec.ts index 1c2eb1ac36..ddc33e7bc2 100644 --- a/src/app/modules/form/public-form/__tests__/public-form.routes.spec.ts +++ b/src/app/modules/form/public-form/__tests__/public-form.routes.spec.ts @@ -1,5 +1,5 @@ import SPCPAuthClient from '@opengovsg/spcp-auth-client' -import _ from 'lodash' +import { ObjectId } from 'bson-ext' import { errAsync } from 'neverthrow' import supertest, { Session } from 'supertest-session' import { mocked } from 'ts-jest/utils' @@ -196,7 +196,7 @@ describe('public-form.routes', () => { usedCount: 0, state: MyInfoCookieState.Success, }) - const MOCK_FORM_ID = _.pad('', 24, '1') + const MOCK_FORM_ID = new ObjectId().toHexString() const expectedResponseBody = JSON.parse( JSON.stringify({ message: 'Form not found', @@ -223,8 +223,9 @@ describe('public-form.routes', () => { }) const expectedResponseBody = JSON.parse( JSON.stringify({ - message: - 'If you think this is a mistake, please contact the agency that gave you the form link.', + message: form.inactiveMessage, + formTitle: form.title, + isPageFound: true, }), )