-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #698 from companieshouse/feature/ecct-813-capture-…
…first-time-email-in-request-body-to-cs-api Feature/ecct 813 capture first time email in request body to confirmation statement api
- Loading branch information
Showing
7 changed files
with
65 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
jest.mock("../../../src/middleware/company.authentication.middleware"); | ||
jest.mock("../../../src/utils/update.confirmation.statement.submission"); | ||
|
||
import request from "supertest"; | ||
import mocks from "../../mocks/all.middleware.mock"; | ||
import { companyAuthenticationMiddleware } from "../../../src/middleware/company.authentication.middleware"; | ||
|
@@ -8,49 +11,56 @@ import { sendUpdate } from "../../../src/utils/update.confirmation.statement.sub | |
import { SECTIONS } from "../../../src/utils/constants"; | ||
import { SectionStatus } from "@companieshouse/api-sdk-node/dist/services/confirmation-statement"; | ||
|
||
const mockCompanyAuthenticationMiddleware = companyAuthenticationMiddleware as jest.Mock; | ||
mockCompanyAuthenticationMiddleware.mockImplementation((req, res, next) => next()); | ||
const mockSendUpdate = sendUpdate as jest.Mock; | ||
|
||
const PAGE_HEADING = "Check the email address"; | ||
const EXPECTED_ERROR_TEXT = "Sorry, the service is unavailable"; | ||
const COMPANY_NUMBER = "12345678"; | ||
const TASK_LIST_URL = TASK_LIST_PATH.replace(`:${urlParams.PARAM_COMPANY_NUMBER}`, COMPANY_NUMBER); | ||
const CONFIRM_EMAIL_ADDRESS_URL = CONFIRM_EMAIL_PATH.replace(`:${urlParams.PARAM_COMPANY_NUMBER}`, COMPANY_NUMBER); | ||
const ENTERED_EMAIL = "[email protected]"; | ||
|
||
jest.mock("../../../src/middleware/company.authentication.middleware"); | ||
jest.mock("../../../src/utils/update.confirmation.statement.submission"); | ||
const mockCompanyAuthenticationMiddleware = companyAuthenticationMiddleware as jest.Mock; | ||
mockCompanyAuthenticationMiddleware.mockImplementation((req, res, next) => next()); | ||
const mockSendUpdate = sendUpdate as jest.Mock; | ||
|
||
describe("Confirm Email Address controller tests", () => { | ||
|
||
beforeEach(() => { | ||
mocks.mockAuthenticationMiddleware.mockClear(); | ||
mocks.mockServiceAvailabilityMiddleware.mockClear(); | ||
mocks.mockSessionMiddleware.mockClear(); | ||
}); | ||
|
||
it("Should navigate to the Confirm Email Address page", async () => { | ||
const response = await request(app).get(CONFIRM_EMAIL_ADDRESS_URL); | ||
|
||
expect(response.text).toContain(PAGE_HEADING); | ||
expect(response.text).toContain("Email address"); | ||
}); | ||
describe("When entered email has been provided", () => { | ||
|
||
beforeEach(() => { | ||
mocks.mockAuthenticationMiddleware.mockClear(); | ||
mocks.mockServiceAvailabilityMiddleware.mockClear(); | ||
mocks.mockSessionMiddleware.mockClear(); | ||
}); | ||
|
||
it("Should return to task list page when email address is confirmed", async () => { | ||
const response = await request(app).post(CONFIRM_EMAIL_ADDRESS_URL); | ||
expect(mockSendUpdate.mock.calls[0][1]).toBe(SECTIONS.EMAIL); | ||
expect(mockSendUpdate.mock.calls[0][2]).toBe(SectionStatus.INITIAL_FILING); | ||
expect(response.status).toEqual(302); | ||
expect(response.header.location).toEqual(TASK_LIST_URL); | ||
}); | ||
it("Should navigate to the Confirm Email Address page", async () => { | ||
const response = await request(app).get(CONFIRM_EMAIL_ADDRESS_URL); | ||
expect(response.text).toContain(PAGE_HEADING); | ||
expect(response.text).toContain("Email address"); | ||
}); | ||
|
||
it("Should redirect to an error page when error is thrown", async () => { | ||
const spyGetUrlToPath = jest.spyOn(urlUtils, "getUrlToPath"); | ||
spyGetUrlToPath.mockImplementationOnce(() => { throw new Error(); }); | ||
const response = await request(app).get(CONFIRM_EMAIL_ADDRESS_URL); | ||
it("Should return to task list page when email address is confirmed", async () => { | ||
const response = await request(app).post(CONFIRM_EMAIL_ADDRESS_URL); | ||
expect(mockSendUpdate.mock.calls[0][1]).toBe(SECTIONS.EMAIL); | ||
expect(mockSendUpdate.mock.calls[0][2]).toBe(SectionStatus.INITIAL_FILING); | ||
expect(response.status).toEqual(302); | ||
expect(response.header.location).toEqual(TASK_LIST_URL); | ||
}); | ||
|
||
expect(response.text).toContain(EXPECTED_ERROR_TEXT); | ||
it("Should return to task list page when email address is provided", async () => { | ||
const response = await request(app).post(CONFIRM_EMAIL_ADDRESS_URL); | ||
expect(mockSendUpdate.mock.calls[0][3]).toBe(ENTERED_EMAIL); | ||
expect(response.status).toEqual(302); | ||
expect(response.header.location).toEqual(TASK_LIST_URL); | ||
}); | ||
|
||
spyGetUrlToPath.mockRestore(); | ||
it("Should redirect to an error page when error is thrown", async () => { | ||
const spyGetUrlToPath = jest.spyOn(urlUtils, "getUrlToPath"); | ||
spyGetUrlToPath.mockImplementationOnce(() => { throw new Error(); }); | ||
const response = await request(app).get(CONFIRM_EMAIL_ADDRESS_URL); | ||
|
||
expect(response.text).toContain(EXPECTED_ERROR_TEXT); | ||
|
||
spyGetUrlToPath.mockRestore(); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ export const session = new Session(); | |
mockSessionMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => { | ||
req.session = session; | ||
req.session.data.extra_data["payment-nonce"] = "123456"; | ||
req.session.data.extra_data["entered-email-address"] = "[email protected]" | ||
next(); | ||
}); | ||
|
||
|
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