Skip to content

Commit

Permalink
Merge pull request #669 from companieshouse/bug/IDVA5-1819-Sole-trade…
Browse files Browse the repository at this point in the history
…r-address-mapping-issue

Updating correspondence address for sole trader to be mapped to registeredOfficeAddress
  • Loading branch information
ttingle-ch authored Feb 21, 2025
2 parents bca78b1 + 6372c47 commit 7b1663a
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const previousPage: string = addLangToUrl(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_YOUR_ANSWERS, lang);
const currentUrl: string = UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_LOOKUP;

const payload = {
postCode: acspUpdatedFullProfile.serviceAddress?.postalCode,
premise: acspUpdatedFullProfile.serviceAddress?.premises
};
let payload;
if (acspUpdatedFullProfile.type === "sole-trader") {
payload = {
postCode: acspUpdatedFullProfile.registeredOfficeAddress?.postalCode,
premise: acspUpdatedFullProfile.registeredOfficeAddress?.premises
};
} else {
payload = {
postCode: acspUpdatedFullProfile.serviceAddress?.postalCode,
premise: acspUpdatedFullProfile.serviceAddress?.premises
};
}

res.render(config.AUTO_LOOKUP_ADDRESS, {
previousPage,
Expand Down Expand Up @@ -65,7 +73,7 @@ export const post = async (req: Request, res: Response, next: NextFunction) => {
const postcode = req.body.postCode;
const inputPremise = req.body.premise;
const addressLookUpService = new AddressLookUpService();
addressLookUpService.processAddressFromPostcodeUpdateJourney(req, postcode, inputPremise, acspUpdatedFullProfile, false,
addressLookUpService.processAddressFromPostcodeUpdateJourney(req, postcode, inputPremise, acspUpdatedFullProfile, acspUpdatedFullProfile.type === "sole-trader",
UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM, UPDATE_CORRESPONDENCE_ADDRESS_LIST).then(async (nextPageUrl) => {

session.setExtraData(ACSP_DETAILS_UPDATED, acspUpdatedFullProfile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const previousPage: string = addLangToUrl(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_LOOKUP, lang);
const currentUrl: string = UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM;

let correspondenceAddress;
if (acspUpdatedFullProfile.type === "sole-trader") {
correspondenceAddress = acspUpdatedFullProfile.registeredOfficeAddress;
} else {
correspondenceAddress = acspUpdatedFullProfile.serviceAddress;
}

res.render(config.CORRESPONDENCE_ADDRESS_CONFIRM, {
previousPage,
editPage: addLangToUrl(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_MANUAL, lang),
...getLocaleInfo(locales, lang),
currentUrl,
correspondenceAddress: acspUpdatedFullProfile?.serviceAddress
correspondenceAddress
});
} catch (err) {
next(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export const post = async (req: Request, res: Response, next: NextFunction) => {
const selectedPremise = req.body.correspondenceAddress;
// Save selected address
const correspondenceAddress: Address = addressList.filter((address) => address.premises === selectedPremise)[0];
acspUpdatedFullProfile.serviceAddress = correspondenceAddress;
if (acspUpdatedFullProfile.type === "sole-trader") {
acspUpdatedFullProfile.registeredOfficeAddress = correspondenceAddress;
} else {
acspUpdatedFullProfile.serviceAddress = correspondenceAddress;
}
session.setExtraData(ACSP_DETAILS_UPDATED, acspUpdatedFullProfile);

// Redirect to the address confirmation page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Session } from "@companieshouse/node-session-handler";
import countryList from "../../../../lib/countryListWithUKCountries";
import { AcspFullProfile } from "private-api-sdk-node/dist/services/acsp-profile/types";
import { ACSP_DETAILS_UPDATED } from "../../../common/__utils/constants";
import { BusinessAddressService } from "../../../services/business-address/businessAddressService";

export const get = async (req: Request, res: Response, next: NextFunction) => {
try {
Expand All @@ -20,8 +21,14 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const acspUpdatedFullProfile: AcspFullProfile = session.getExtraData(ACSP_DETAILS_UPDATED)!;

// Get existing correspondence address details and display on the page
const addressManualservice = new CorrespondenceAddressManualService();
const payload = addressManualservice.getCorrespondenceManualAddressUpdate(acspUpdatedFullProfile);
let payload;
if (acspUpdatedFullProfile.type === "sole-trader") {
const addressManualservice = new BusinessAddressService();
payload = addressManualservice.getBusinessManualAddress(acspUpdatedFullProfile);
} else {
const addressManualservice = new CorrespondenceAddressManualService();
payload = addressManualservice.getCorrespondenceManualAddressUpdate(acspUpdatedFullProfile);
}

res.render(config.CORRESPONDENCE_ADDRESS_MANUAL, {
...getLocaleInfo(locales, lang),
Expand Down Expand Up @@ -56,8 +63,13 @@ export const post = async (req: Request, res: Response, next: NextFunction) => {
});
} else {
// update acspUpdatedFullProfile
const addressManualservice = new CorrespondenceAddressManualService();
addressManualservice.saveCorrespondenceManualAddressUpdate(req, acspUpdatedFullProfile);
if (acspUpdatedFullProfile.type === "sole-trader") {
const addressManualservice = new BusinessAddressService();
addressManualservice.saveBusinessAddress(req, acspUpdatedFullProfile);
} else {
const addressManualservice = new CorrespondenceAddressManualService();
addressManualservice.saveCorrespondenceManualAddressUpdate(req, acspUpdatedFullProfile);
}
session.setExtraData(ACSP_DETAILS_UPDATED, acspUpdatedFullProfile);

// Redirect to the address confirmation page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>"
%}
{%endif%}
{% if profileDetailsUpdated.serviceAddress !== profileDetails.serviceAddress %}
{% if profileDetailsUpdated.registeredOfficeAddress !== profileDetails.registeredOfficeAddress %}
{% set updateStatusTextForCorrespondenceAddress =
"<div class='govuk-!-static-padding-top-3'>
<strong class='govuk-tag govuk-tag--blue govuk-!-static-margin-bottom-1'>"+i18n.updatedWarningCaption+"</strong>
Expand Down Expand Up @@ -104,7 +104,7 @@
classes: "govuk-!-width-one-third"
},
value: {
html: profileDetailsUpdated.serviceAddress + updateStatusTextForCorrespondenceAddress,
html: profileDetailsUpdated.registeredOfficeAddress + updateStatusTextForCorrespondenceAddress,
classes: "govuk-!-width-one-third"
},
actions: {
Expand All @@ -115,10 +115,10 @@
visuallyHiddenText: i18n.updateYourDetailsCorrespondenceAddress
},
{
href: cancelChangeUrl + "&cancel=serviceAddress",
href: cancelChangeUrl + "&cancel=registeredOfficeAddress",
text: i18n.updateYourDetailsCancel,
visuallyHiddenText: i18n.updateYourDetailsCorrespondenceAddress
} if profileDetailsUpdated.serviceAddress !== profileDetails.serviceAddress
} if profileDetailsUpdated.registeredOfficeAddress !== profileDetails.registeredOfficeAddress
],
classes: "govuk-!-width-one-third"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM, UP
import { getAddressFromPostcode } from "../../../../src/services/postcode-lookup-service";
import { UKAddress } from "@companieshouse/api-sdk-node/dist/services/postcode-lookup/types";
import * as localise from "../../../../src/utils/localise";
import { sessionMiddleware } from "../../../../src/middleware/session_middleware";
import { getSessionRequestWithPermission } from "../../../mocks/session.mock";
import { dummyFullProfile } from "../../../mocks/acsp_profile.mock";
import { ACSP_DETAILS_UPDATED, SUBMISSION_ID } from "../../../../src/common/__utils/constants";
import { Request, Response, NextFunction } from "express";

jest.mock("@companieshouse/api-sdk-node");
jest.mock("../../../../src/services/postcode-lookup-service.ts");
Expand Down Expand Up @@ -131,3 +136,26 @@ describe("POST" + UPDATE_CORRESPONDENCE_ADDRESS_LOOKUP, () => {
expect(res.text).toContain("Sorry we are experiencing technical difficulties");
});
});
let customMockSessionMiddleware: any;

describe("GET" + UPDATE_CORRESPONDENCE_ADDRESS_LOOKUP, () => {
it("should return 200 and render the page with sole-trader type", async () => {
createMockSessionMiddleware();
const res = await router.get(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_LOOKUP);
expect(res.status).toBe(200);
expect(mocks.mockSessionMiddleware).toHaveBeenCalled();
expect(mocks.mockUpdateAcspAuthenticationMiddleware).toHaveBeenCalled();
expect(res.text).toContain("What is the correspondence address?");
});
});

function createMockSessionMiddleware () {
customMockSessionMiddleware = sessionMiddleware as jest.Mock;
const session = getSessionRequestWithPermission();
session.setExtraData(ACSP_DETAILS_UPDATED, { ...dummyFullProfile, type: "sole-trader" });
session.setExtraData(SUBMISSION_ID, "transactionID");
customMockSessionMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => {
req.session = session;
next();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import supertest from "supertest";
import app from "../../../../src/app";
import * as localise from "../../../../src/utils/localise";
import { UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM, UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_YOUR_ANSWERS } from "../../../../src/types/pageURL";
import { sessionMiddleware } from "../../../../src/middleware/session_middleware";
import { getSessionRequestWithPermission } from "../../../mocks/session.mock";
import { ACSP_DETAILS_UPDATED, SUBMISSION_ID } from "../../../../src/common/__utils/constants";
import { dummyFullProfile } from "../../../mocks/acsp_profile.mock";
import { Request, Response, NextFunction } from "express";

jest.mock("@companieshouse/api-sdk-node");
const router = supertest(app);
Expand Down Expand Up @@ -44,3 +49,27 @@ describe("POST " + UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM, () => {
expect(res.text).toContain("Sorry we are experiencing technical difficulties");
});
});

let customMockSessionMiddleware: any;

describe("GET " + UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM, () => {
it("should render the confirmation page with status 200", async () => {
createMockSessionMiddleware();
const res = await router.get(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM);
expect(res.status).toBe(200);
expect(res.text).toContain("Confirm the correspondence address");
expect(mocks.mockSessionMiddleware).toHaveBeenCalled();
expect(mocks.mockUpdateAcspAuthenticationMiddleware).toHaveBeenCalled();
});
});

function createMockSessionMiddleware () {
customMockSessionMiddleware = sessionMiddleware as jest.Mock;
const session = getSessionRequestWithPermission();
session.setExtraData(ACSP_DETAILS_UPDATED, { ...dummyFullProfile, type: "sole-trader" });
session.setExtraData(SUBMISSION_ID, "transactionID");
customMockSessionMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => {
req.session = session;
next();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import supertest from "supertest";
import app from "../../../../src/app";
import * as localise from "../../../../src/utils/localise";
import { UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM, UPDATE_CORRESPONDENCE_ADDRESS_LIST } from "../../../../src/types/pageURL";
import { sessionMiddleware } from "../../../../src/middleware/session_middleware";
import { getSessionRequestWithPermission } from "../../../mocks/session.mock";
import { ACSP_DETAILS_UPDATED, ADDRESS_LIST, SUBMISSION_ID } from "../../../../src/common/__utils/constants";
import { dummyFullProfile } from "../../../mocks/acsp_profile.mock";
import { Request, Response, NextFunction } from "express";
import { addressList } from "../../../mocks/address.mock";

const router = supertest(app);

Expand Down Expand Up @@ -47,3 +53,26 @@ describe("POST" + UPDATE_CORRESPONDENCE_ADDRESS_LIST, () => {
expect(res.text).toContain("Sorry we are experiencing technical difficulties");
});
});

let customMockSessionMiddleware: any;

describe("POST" + UPDATE_CORRESPONDENCE_ADDRESS_LIST, () => {
it("should redirect to next page with status 302 with sole-trader type", async () => {
createMockSessionMiddleware();
const res = await router.post(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_LIST).send({ correspondenceAddress: "1" });
expect(res.status).toBe(302);
expect(res.header.location).toBe(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM + "?lang=en");
});
});

function createMockSessionMiddleware () {
customMockSessionMiddleware = sessionMiddleware as jest.Mock;
const session = getSessionRequestWithPermission();
session.setExtraData(ACSP_DETAILS_UPDATED, { ...dummyFullProfile, type: "sole-trader" });
session.setExtraData(ADDRESS_LIST, addressList);
session.setExtraData(SUBMISSION_ID, "transactionID");
customMockSessionMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => {
req.session = session;
next();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import supertest from "supertest";
import app from "../../../../src/app";
import * as localise from "../../../../src/utils/localise";
import { UPDATE_ACSP_DETAILS_BASE_URL, UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM, UPDATE_CORRESPONDENCE_ADDRESS_MANUAL } from "../../../../src/types/pageURL";
import { ACSP_DETAILS_UPDATED, SUBMISSION_ID } from "../../../../src/common/__utils/constants";
import { dummyFullProfile } from "../../../mocks/acsp_profile.mock";
import { Request, Response, NextFunction } from "express";
import { getSessionRequestWithPermission } from "../../../mocks/session.mock";
import { sessionMiddleware } from "../../../../src/middleware/session_middleware";

const router = supertest(app);

Expand Down Expand Up @@ -196,3 +201,35 @@ describe("POST" + UPDATE_CORRESPONDENCE_ADDRESS_MANUAL, () => {
expect(res.text).toContain("Sorry we are experiencing technical difficulties");
});
});

let customMockSessionMiddleware: any;

describe("GET" + UPDATE_CORRESPONDENCE_ADDRESS_MANUAL, () => {
it("should return status 200 with sole-trader type", async () => {
createMockSessionMiddleware();
await router.get(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_MANUAL).expect(200);
expect(mocks.mockSessionMiddleware).toHaveBeenCalled();
expect(mocks.mockUpdateAcspAuthenticationMiddleware).toHaveBeenCalled();
});
});

describe("POST " + UPDATE_CORRESPONDENCE_ADDRESS_MANUAL, () => {
it("should return status 302 after redirect with sole-trader type", async () => {
createMockSessionMiddleware();
const res = await router.post(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_MANUAL)
.send({ addressPropertyDetails: "abc", addressLine1: "pqr", addressLine2: "pqr", addressTown: "lmn", addressCounty: "lmnop", countryInput: "England", addressPostcode: "MK9 3GB" });
expect(res.status).toBe(302);
expect(res.header.location).toBe(UPDATE_ACSP_DETAILS_BASE_URL + UPDATE_CORRESPONDENCE_ADDRESS_CONFIRM + "?lang=en");
});
});

function createMockSessionMiddleware () {
customMockSessionMiddleware = sessionMiddleware as jest.Mock;
const session = getSessionRequestWithPermission();
session.setExtraData(ACSP_DETAILS_UPDATED, { ...dummyFullProfile, type: "sole-trader" });
session.setExtraData(SUBMISSION_ID, "transactionID");
customMockSessionMiddleware.mockImplementation((req: Request, res: Response, next: NextFunction) => {
req.session = session;
next();
});
}

0 comments on commit 7b1663a

Please sign in to comment.