-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve & in url upon redirect, shift prefill to textfield c…
…omponent (#569) * chore: replace '&' in ejs template * chore: remove he decoding * chore: shift stealth prefil to textfield component * chore: add tests for frontend.server.controller * chore: update package-lock * chore: add error handling to frontend.server.controller * chore: reorganize tests, add tests for invalid request * chore: log errors on frontend server controller * chore: reorganise tests * fix: relative paths * chore: standardise logger action to calling function * chore: return res
- Loading branch information
Showing
7 changed files
with
174 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/app/controllers/__tests__/frontend.server.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { StatusCodes } from 'http-status-codes' | ||
|
||
import expressHandler from 'tests/unit/backend/helpers/jest-express' | ||
|
||
import frontendServerController from '../frontend.server.controller' | ||
|
||
describe('frontend.server.controller', () => { | ||
afterEach(() => jest.clearAllMocks()) | ||
const mockRes = expressHandler.mockResponse() | ||
const mockReq = { | ||
app: { | ||
locals: { | ||
GATrackingID: 'abc', | ||
appName: 'xyz', | ||
environment: 'efg', | ||
}, | ||
}, | ||
query: { | ||
redirectPath: 'formId?fieldId1=abc&fieldId2=xyz', | ||
}, | ||
} | ||
const mockBadReq = { | ||
get: jest.fn().mockImplementation(() => 'abc'), | ||
} | ||
describe('datalayer', () => { | ||
it('should return the correct response when the request is valid', () => { | ||
frontendServerController.datalayer(mockReq, mockRes) | ||
expect(mockRes.send).toHaveBeenCalledWith( | ||
expect.stringContaining("'app_name': 'xyz'"), | ||
) | ||
expect(mockRes.send).toHaveBeenCalledWith( | ||
expect.stringContaining("'config', 'abc'"), | ||
) | ||
expect(mockRes.type).toHaveBeenCalledWith('text/javascript') | ||
expect(mockRes.status).toHaveBeenCalledWith(StatusCodes.OK) | ||
}) | ||
it('should return BAD_REQUEST if the request is not valid', () => { | ||
frontendServerController.datalayer(mockBadReq, mockRes) | ||
expect(mockRes.status).toHaveBeenCalledWith(StatusCodes.BAD_REQUEST) | ||
}) | ||
}) | ||
|
||
describe('environment', () => { | ||
it('should return the correct response when the request is valid', () => { | ||
frontendServerController.environment(mockReq, mockRes) | ||
expect(mockRes.send).toHaveBeenCalledWith('efg') | ||
expect(mockRes.type).toHaveBeenCalledWith('text/javascript') | ||
expect(mockRes.status).toHaveBeenCalledWith(StatusCodes.OK) | ||
}) | ||
it('should return BAD_REQUEST if the request is not valid', () => { | ||
frontendServerController.environment(mockBadReq, mockRes) | ||
expect(mockRes.status).toHaveBeenCalledWith(StatusCodes.BAD_REQUEST) | ||
}) | ||
}) | ||
|
||
describe('redirectLayer', () => { | ||
it('should return the correct response when the request is valid', () => { | ||
const mockReqModified = { | ||
// Test other special characters | ||
query: { | ||
redirectPath: 'formId?fieldId1=abc&fieldId2=<>\'"', | ||
}, | ||
} | ||
const redirectString = | ||
'window.location.hash = "#!/formId?fieldId1=abc&fieldId2=<>'"' | ||
// Note this is different from mockReqModified.query.redirectPath as | ||
// there are html-encoded characters | ||
frontendServerController.redirectLayer(mockReqModified, mockRes) | ||
expect(mockRes.send).toHaveBeenCalledWith( | ||
expect.stringContaining(redirectString), | ||
) | ||
expect(mockRes.type).toHaveBeenCalledWith('text/javascript') | ||
expect(mockRes.status).toHaveBeenCalledWith(StatusCodes.OK) | ||
}) | ||
it('should return BAD_REQUEST if the request is not valid', () => { | ||
frontendServerController.redirectLayer(mockBadReq, mockRes) | ||
expect(mockRes.status).toHaveBeenCalledWith(StatusCodes.BAD_REQUEST) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters