Skip to content

Commit

Permalink
test(public-form): fixed tests so that privateFormError is checked co…
Browse files Browse the repository at this point in the history
…rrectly
  • Loading branch information
seaerchin committed Apr 12, 2021
1 parent 0ae0623 commit e4790c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
})
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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',
Expand All @@ -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,
}),
)

Expand Down

0 comments on commit e4790c5

Please sign in to comment.