Skip to content

Commit

Permalink
fix : lp-317 - add constant for prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
lduranteau committed Dec 18, 2024
1 parent aec5dfb commit a14ae76
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const LOG_LEVEL = getEnvironmentValue("LOG_LEVEL");
export const NODE_ENV = process.env["NODE_ENV"];
export const OAUTH2_CLIENT_ID = getEnvironmentValue("OAUTH2_CLIENT_ID");
export const OAUTH2_CLIENT_SECRET = getEnvironmentValue("OAUTH2_CLIENT_SECRET");
export const PIWIK_REGISTRATION_START_GOAL_ID = getEnvironmentValue("PIWIK_REGISTRATION_START_GOAL_ID");
export const PIWIK_REGISTRATION_START_GOAL_ID = getEnvironmentValue(
"PIWIK_REGISTRATION_START_GOAL_ID"
);
export const PIWIK_SITE_ID = getEnvironmentValue("PIWIK_SITE_ID");
export const PIWIK_URL = getEnvironmentValue("PIWIK_URL");
export const PORT = getEnvironmentValue("PORT");
Expand All @@ -31,6 +33,7 @@ export const isLocalesEnabled = () =>

export const SERVICE_NAME = "File for a limited partnership";
export const APPLICATION_CACHE_KEY = "limited_partnership";
export const APPLICATION_CACHE_KEY_PREFIX_REGISTRATION = "registration_";

// Templates
export const ERROR_TEMPLATE = "error-page";
Expand Down
11 changes: 8 additions & 3 deletions src/presentation/controller/registration/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import RegistrationService from "../../../application/registration/Service";
import registrationsRouting from "./Routing";
import AbstractController from "../AbstractController";
import RegistrationPageType from "./PageType";
import { SUBMISSION_ID, TRANSACTION_ID } from "../../../config/constants";
import {
APPLICATION_CACHE_KEY_PREFIX_REGISTRATION,
SUBMISSION_ID,
TRANSACTION_ID,
} from "../../../config/constants";
import CacheService from "../../../application/CacheService";

class RegistrationController extends AbstractController {
Expand Down Expand Up @@ -86,7 +90,7 @@ class RegistrationController extends AbstractController {

await this.cacheService.removeDataFromCache(
session,
`registration_${RegistrationPageType.whichType}`
`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`
);

response.redirect(url);
Expand All @@ -113,7 +117,8 @@ class RegistrationController extends AbstractController {
const parameter = escape(request.body.parameter);

await this.cacheService.addDataToCache(session, {
[`registration_${pageType}`]: parameter,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${pageType}`]:
parameter,
});

response.redirect(registrationRouting.nextUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import app from "../app";
import { appDevDependencies } from "../../../../config/dev-dependencies";
import { NAME_URL } from "../../../controller/registration/Routing";
import RegistrationPageType from "../../../controller/registration/PageType";
import { APPLICATION_CACHE_KEY } from "../../../../config/constants";
import {
APPLICATION_CACHE_KEY,
APPLICATION_CACHE_KEY_PREFIX_REGISTRATION,
} from "../../../../config/constants";

describe("Create transaction and the first submission", () => {
beforeAll(() => {
Expand All @@ -20,7 +23,8 @@ describe("Create transaction and the first submission", () => {

it("should load the name page with status 200", async () => {
appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.LP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.LP,
});

const res = await request(app).get(NAME_URL);
Expand All @@ -31,7 +35,8 @@ describe("Create transaction and the first submission", () => {

it("should create a transaction and the first submission", async () => {
appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.LP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.LP,
});

const url = appDevDependencies.registrationController.insertIdsInUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
} from "../../../controller/registration/Routing";
import RegistrationPageType from "../../../../presentation/controller/registration/PageType";
import { appDevDependencies } from "../../../../config/dev-dependencies";
import { APPLICATION_CACHE_KEY } from "../../../../config/constants";
import {
APPLICATION_CACHE_KEY,
APPLICATION_CACHE_KEY_PREFIX_REGISTRATION,
} from "../../../../config/constants";

describe("General Partner Choice Page", () => {
beforeEach(() => {
Expand Down Expand Up @@ -59,7 +62,7 @@ describe("General Partner Choice Page", () => {
// to be removed - not store in cache
expect(appDevDependencies.cacheRepository.cache).toEqual({
[APPLICATION_CACHE_KEY]: {
[`registration_${RegistrationPageType.generalPartnerChoice}`]:
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.generalPartnerChoice}`]:
selectedType,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import request from "supertest";
import { LocalesService } from "@companieshouse/ch-node-utils";

import * as constants from "../../../../config/constants";
import { appDevDependencies, APPLICATION_CACHE_KEY } from "../../../../config";
import {
appDevDependencies,
APPLICATION_CACHE_KEY,
APPLICATION_CACHE_KEY_PREFIX_REGISTRATION,
} from "../../../../config";
import enTranslationText from "../../../../../locales/en/translations.json";
import cyTranslationText from "../../../../../locales/cy/translations.json";
import app from "../app";
Expand Down Expand Up @@ -75,7 +79,7 @@ describe("Limited Partner Choice Page", () => {
// to be removed - not store in cache
expect(appDevDependencies.cacheRepository.cache).toEqual({
[APPLICATION_CACHE_KEY]: {
[`registration_${RegistrationPageType.limitedPartnerChoice}`]:
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.limitedPartnerChoice}`]:
selectedChoice,
},
});
Expand Down
29 changes: 20 additions & 9 deletions src/presentation/test/integration/registration/name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import enTranslationText from "../../../../../locales/en/translations.json";
import cyTranslationText from "../../../../../locales/cy/translations.json";
import app from "../app";
import { NAME_URL } from "../../../controller/registration/Routing";
import { appDevDependencies } from "../../../../config";
import {
appDevDependencies,
APPLICATION_CACHE_KEY_PREFIX_REGISTRATION,
} from "../../../../config";
import RegistrationPageType from "../../../controller/registration/PageType";
import { PartnershipType } from "@companieshouse/api-sdk-node/dist/services/limited-partnerships";

Expand All @@ -27,7 +30,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.LP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.LP,
});

const res = await request(app).get(NAME_URL + "?lang=cy");
Expand All @@ -43,7 +47,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.LP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.LP,
});

const res = await request(app).get(NAME_URL + "?lang=en");
Expand All @@ -60,7 +65,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.PFLP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.PFLP,
});

const res = await request(app).get(NAME_URL + "?lang=cy");
Expand All @@ -77,7 +83,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.PFLP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.PFLP,
});

const res = await request(app).get(NAME_URL + "?lang=en");
Expand All @@ -95,7 +102,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.SLP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.SLP,
});

const res = await request(app).get(NAME_URL + "?lang=cy");
Expand All @@ -110,7 +118,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.SLP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.SLP,
});

const res = await request(app).get(NAME_URL + "?lang=en");
Expand All @@ -126,7 +135,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.SPFLP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.SPFLP,
});

const res = await request(app).get(NAME_URL + "?lang=cy");
Expand All @@ -143,7 +153,8 @@ describe("Name Page", () => {
setLocalesEnabled(true);

appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.SPFLP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.SPFLP,
});

const res = await request(app).get(NAME_URL + "?lang=en");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {
import { appDevDependencies } from "../../../../config/dev-dependencies";
import enTranslationText from "../../../../../locales/en/translations.json";
import RegistrationPageType from "../../../../presentation/controller/registration/PageType";
import { APPLICATION_CACHE_KEY } from "../../../../config/constants";
import {
APPLICATION_CACHE_KEY,
APPLICATION_CACHE_KEY_PREFIX_REGISTRATION,
} from "../../../../config/constants";

describe("Which type Page", () => {
beforeEach(() => {
Expand Down Expand Up @@ -40,14 +43,16 @@ describe("Which type Page", () => {

expect(appDevDependencies.cacheRepository.cache).toEqual({
[APPLICATION_CACHE_KEY]: {
[`registration_${RegistrationPageType.whichType}`]: selectedType,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
selectedType,
},
});
});

it("should redirect to name page and update type in cache", async () => {
appDevDependencies.cacheRepository.feedCache({
[`registration_${RegistrationPageType.whichType}`]: PartnershipType.LP,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
PartnershipType.LP,
});

const selectedType = PartnershipType.PFLP;
Expand All @@ -62,7 +67,8 @@ describe("Which type Page", () => {

expect(appDevDependencies.cacheRepository.cache).toEqual({
[APPLICATION_CACHE_KEY]: {
[`registration_${RegistrationPageType.whichType}`]: selectedType,
[`${APPLICATION_CACHE_KEY_PREFIX_REGISTRATION}${RegistrationPageType.whichType}`]:
selectedType,
},
});
});
Expand Down

0 comments on commit a14ae76

Please sign in to comment.