Skip to content

Commit

Permalink
Merge pull request #598 from companieshouse/bug/IDVA5-1722-Correspond…
Browse files Browse the repository at this point in the history
…ence-address-country

Fixing Correspondence address country input not showing on back
  • Loading branch information
ttingle-ch authored Jan 23, 2025
2 parents 63cd75a + 2dee375 commit 65badd1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const acspData = await getAcspRegistration(session, session.getExtraData(SUBMISSION_ID)!, res.locals.applicationId);
saveDataInSession(req, USER_DATA, acspData);

const { payload, countryInput } = new WhereDoYouLivBodyService().getCountryPayload(acspData);
const payload = new WhereDoYouLivBodyService().getCountryPayload(acspData);
res.render(config.SOLE_TRADER_WHERE_DO_YOU_LIVE, {
...getLocaleInfo(locales, lang),
previousPage,
currentUrl,
countryList: countryList,
firstName: acspData?.applicantDetails?.firstName,
lastName: acspData?.applicantDetails?.lastName,
countryInput,
payload
});
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
// This ensures functionality until the page is ready, at which point we can handle null separately.
const acspData: AcspData = session.getExtraData(USER_DATA) ? session.getExtraData(USER_DATA)! : {};

const { payload, countryInput } = new WhereDoYouLivBodyService().getCountryPayload(acspData);
const payload = new WhereDoYouLivBodyService().getCountryPayload(acspData);
const reqType = REQ_TYPE_UPDATE_ACSP;
res.render(config.SOLE_TRADER_WHERE_DO_YOU_LIVE, {
...getLocaleInfo(locales, lang),
Expand All @@ -30,7 +30,6 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
countryList: countryList,
firstName: acspData?.applicantDetails?.firstName,
lastName: acspData?.applicantDetails?.lastName,
countryInput,
payload,
reqType
});
Expand Down
23 changes: 12 additions & 11 deletions src/services/where-do-you-live/whereDoYouLive.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import { AcspData } from "@companieshouse/api-sdk-node/dist/services/acsp";

export class WhereDoYouLivBodyService {
public getCountryPayload (ascpData: AcspData): { payload: any, countryInput?: string } {
public getCountryPayload (ascpData: AcspData) {
let payload = {};
let countryInput: string | undefined;

switch (ascpData.applicantDetails?.countryOfResidence) {
if (!ascpData.applicantDetails?.countryOfResidence) {
return payload;
}

switch (ascpData.applicantDetails.countryOfResidence) {
case "England":
case "Scotland":
case "Wales":
case "Northern Ireland":
payload = { whereDoYouLiveRadio: ascpData?.applicantDetails?.countryOfResidence };
payload = { whereDoYouLiveRadio: ascpData.applicantDetails?.countryOfResidence };
break;
default:
if (ascpData.applicantDetails?.countryOfResidence) {
payload = { whereDoYouLiveRadio: "countryOutsideUK" };
countryInput = ascpData.applicantDetails?.countryOfResidence;
}
break;

payload = {
whereDoYouLiveRadio: "countryOutsideUK",
countryInput: ascpData.applicantDetails.countryOfResidence
};
}
return { payload, countryInput };
return payload;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
{% set dropdownDefaultText = i18n.whereDoYouLiveDefaultDropdownText %}
{% if payload.countryInput | length %}
{% set dropdownValue = payload.countryInput %}
{% set countryInput = payload.countryInput %}
{% endif %}
<p class="govuk-hint" id="typeahead-hint">{{ i18n.whereDoYouLiveHint }}</p>
<div id="my-autocomplete-container" class="autocomplete-wrapper govuk-!-width-two-thirds"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/views/partials/country-typeahead-input.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<script type="text/javascript" nonce={{ nonce | dump | safe }}>
const countryList = "{{countryList}}"
const error = "{{errors.countryInput.text}}"
const countryDefaultValue = "{{countryInput}}"
const countryDefaultValue = "{{payload.countryInput}}"
var autocompleteConfig = {
element: document.querySelector('#my-autocomplete-container'),
Expand Down
42 changes: 19 additions & 23 deletions test/src/services/where-do-you-live/whereDoYouLive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { AcspData } from "@companieshouse/api-sdk-node/dist/services/acsp/types"
import { WhereDoYouLivBodyService } from "../../../../src/services/where-do-you-live/whereDoYouLive";

describe("WhereDoYouLiveBodyService", () => {

let whereDoYouLiveBodyService: WhereDoYouLivBodyService;

beforeEach(() => {
whereDoYouLiveBodyService = new WhereDoYouLivBodyService();
});

it("should return payload for England", () => {
const whereDoYouLiveBodyService = new WhereDoYouLivBodyService();
const acspData: AcspData = {
id: "abc",
typeOfBusiness: "LIMITED",
Expand All @@ -12,13 +18,11 @@ describe("WhereDoYouLiveBodyService", () => {
}
};

const { payload, countryInput } = whereDoYouLiveBodyService.getCountryPayload(acspData);
const payload = whereDoYouLiveBodyService.getCountryPayload(acspData);
expect(payload).toEqual({ whereDoYouLiveRadio: "England" });
expect(countryInput).toBeUndefined();
});

it("should return payload for Scotland", () => {
const whereDoYouLiveBodyService = new WhereDoYouLivBodyService();
const acspData: AcspData = {
id: "abc",
typeOfBusiness: "LIMITED",
Expand All @@ -27,26 +31,23 @@ describe("WhereDoYouLiveBodyService", () => {
}
};

const { payload, countryInput } = whereDoYouLiveBodyService.getCountryPayload(acspData);
const payload = whereDoYouLiveBodyService.getCountryPayload(acspData);
expect(payload).toEqual({ whereDoYouLiveRadio: "Scotland" });
expect(countryInput).toBeUndefined();

});

it("should return payload with countryOfResidence when applicantDetails is defined", () => {
const whereDoYouLiveBodyService = new WhereDoYouLivBodyService();
const acspData: AcspData = {
id: "abc",
typeOfBusiness: "LIMITED"
};

const { payload, countryInput } = whereDoYouLiveBodyService.getCountryPayload(acspData);
const payload = whereDoYouLiveBodyService.getCountryPayload(acspData);

expect(payload).toEqual({});
expect(countryInput).toBeUndefined();
});

it("should return payload for Wales", () => {
const whereDoYouLiveBodyService = new WhereDoYouLivBodyService();
const acspData: AcspData = {
id: "abc",
typeOfBusiness: "LIMITED",
Expand All @@ -55,13 +56,11 @@ describe("WhereDoYouLiveBodyService", () => {
}
};

const { payload, countryInput } = whereDoYouLiveBodyService.getCountryPayload(acspData);
const payload = whereDoYouLiveBodyService.getCountryPayload(acspData);
expect(payload).toEqual({ whereDoYouLiveRadio: "Wales" });
expect(countryInput).toBeUndefined();
});

it("should return payload for Northern Ireland", () => {
const whereDoYouLiveBodyService = new WhereDoYouLivBodyService();
const acspData: AcspData = {
id: "abc",
typeOfBusiness: "LIMITED",
Expand All @@ -70,13 +69,11 @@ describe("WhereDoYouLiveBodyService", () => {
}
};

const { payload, countryInput } = whereDoYouLiveBodyService.getCountryPayload(acspData);
const payload = whereDoYouLiveBodyService.getCountryPayload(acspData);
expect(payload).toEqual({ whereDoYouLiveRadio: "Northern Ireland" });
expect(countryInput).toBeUndefined();
});

it("should return payload and countryInput for country outside UK", () => {
const whereDoYouLiveBodyService = new WhereDoYouLivBodyService();
const acspData: AcspData = {
id: "abc",
typeOfBusiness: "LIMITED",
Expand All @@ -85,10 +82,11 @@ describe("WhereDoYouLiveBodyService", () => {
}
};

const { payload, countryInput } =
whereDoYouLiveBodyService.getCountryPayload(acspData);
expect(payload).toEqual({ whereDoYouLiveRadio: "countryOutsideUK" });
expect(countryInput).toEqual("France");
const payload = whereDoYouLiveBodyService.getCountryPayload(acspData);
expect(payload).toEqual({
whereDoYouLiveRadio: "countryOutsideUK",
countryInput: "France"
});
});

it("should return empty payload if countryOfResidence is not valid", () => {
Expand All @@ -100,9 +98,7 @@ describe("WhereDoYouLiveBodyService", () => {
countryOfResidence: undefined
}
};

const { payload, countryInput } = whereDoYouLiveBodyService.getCountryPayload(acspData);
const payload = whereDoYouLiveBodyService.getCountryPayload(acspData);
expect(payload).toEqual({});
expect(countryInput).toBeUndefined();
});
});

0 comments on commit 65badd1

Please sign in to comment.