Skip to content

Commit

Permalink
Merge pull request #841 from govuk-one-login/ATO-925-fix-double-email…
Browse files Browse the repository at this point in the history
…-entry-bug

ATO-925: Fix double email entry bug
  • Loading branch information
kalpaitch authored Aug 7, 2024
2 parents 49b7315 + df56d98 commit 741f73c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions express/src/controllers/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const processGetEmailForm: RequestHandler = async (req, res) => {
console.info("In ProcessGetEmailForm");

req.session.emailAddress = emailAddress;
req.session.save();

try {
await s4.createUser(emailAddress);
Expand Down
6 changes: 6 additions & 0 deletions express/tests/controllers/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe("processGetEmailForm controller tests", () => {

await processGetEmailForm(mockReq, mockRes, mockNext);
expect(s4CreateUserSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(mockReq.session.save).toHaveBeenCalled();
expect(mockRes.redirect).toHaveBeenCalledWith("/register/enter-email-code");
});

Expand All @@ -106,6 +107,7 @@ describe("processGetEmailForm controller tests", () => {
await processGetEmailForm(mockReq, mockRes, mockNext);
expect(s4CreateUserSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(s4SignUpStatusSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(mockReq.session.save).toHaveBeenCalled();
expect(console.info).toHaveBeenCalledWith("Processing No HasEMail");
expect(mockRes.redirect).toHaveBeenCalledWith("resume-before-password");
});
Expand Down Expand Up @@ -134,6 +136,7 @@ describe("processGetEmailForm controller tests", () => {
expect(s4CreateUserSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(s4SignUpStatusSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(console.info).toHaveBeenCalledWith("Processing No HasPassword");
expect(mockReq.session.save).toHaveBeenCalled();
expect(mockRes.redirect).toHaveBeenCalledWith("resume-before-password");
});

Expand Down Expand Up @@ -162,6 +165,7 @@ describe("processGetEmailForm controller tests", () => {
expect(s4CreateUserSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(s4SignUpStatusSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(console.info).toHaveBeenCalledWith("Processing No HasPhoneNumber");
expect(mockReq.session.save).toHaveBeenCalled();
expect(mockRes.redirect).toHaveBeenCalledWith("resume-after-password");
});

Expand Down Expand Up @@ -190,6 +194,7 @@ describe("processGetEmailForm controller tests", () => {
await processGetEmailForm(mockReq, mockRes, mockNext);
expect(s4CreateUserSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(s4SignUpStatusSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(mockReq.session.save).toHaveBeenCalled();
expect(console.info).toHaveBeenCalledWith("Processing No HasTextCode");
expect(mockRes.redirect).toHaveBeenCalledWith("resume-after-password");
});
Expand All @@ -207,6 +212,7 @@ describe("processGetEmailForm controller tests", () => {

await expect(processGetEmailForm(mockReq, mockRes, mockNext)).rejects.toThrow();
expect(s4CreateUserSpy).toHaveBeenCalledWith(TEST_EMAIL);
expect(mockReq.session.save).toHaveBeenCalled();
expect(s4SignUpStatusSpy).not.toHaveBeenCalled();
});
});
Expand Down
7 changes: 5 additions & 2 deletions express/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ export const mockCognitoInterface = {
globalSignOut: jest.fn()
};

export const request = (properties?: Partial<Request> | object) =>
export const request = (properties?: Partial<Request> | Record<string, unknown>) =>
({
body: {},
session: {},
session: {
save: jest.fn(),
...(properties?.session as Partial<Request["session"]>)
},
app: {
get: (keyName: string) => {
if (keyName === "backing-service") return new SelfServiceServicesService(mockCognitoInterface, mockLambdaFacade);
Expand Down

0 comments on commit 741f73c

Please sign in to comment.