Skip to content

Commit

Permalink
Merge pull request #502 from companieshouse/IDVA51277
Browse files Browse the repository at this point in the history
IDVA5-1277
  • Loading branch information
rdas-ch authored Oct 15, 2024
2 parents 2eab4e2 + 658b81b commit c19c1a8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/controllers/features/common/typeOfBusinessController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { validationResult } from "express-validator";
import * as config from "../../../config";
import { formatValidationError, getPageProperties } from "../../../validation/validation";
import { selectLang, addLangToUrl, getLocalesService, getLocaleInfo } from "../../../utils/localise";
import { TYPE_OF_BUSINESS, OTHER_TYPE_OF_BUSINESS, SOLE_TRADER_WHAT_IS_YOUR_ROLE, BASE_URL, LIMITED_WHAT_IS_THE_COMPANY_NUMBER, UNINCORPORATED_NAME_REGISTERED_WITH_AML } from "../../../types/pageURL";
import { TYPE_OF_BUSINESS, OTHER_TYPE_OF_BUSINESS, LIMITED_BUSINESS_MUSTBE_AML_REGISTERED_KICKOUT, SOLE_TRADER_WHAT_IS_YOUR_ROLE, BASE_URL, LIMITED_WHAT_IS_THE_COMPANY_NUMBER, UNINCORPORATED_NAME_REGISTERED_WITH_AML } from "../../../types/pageURL";
import { TypeOfBusinessService } from "../../../services/typeOfBusinessService";
import { SUBMISSION_ID, POST_ACSP_REGISTRATION_DETAILS_ERROR, GET_ACSP_REGISTRATION_DETAILS_ERROR, USER_DATA } from "../../../common/__utils/constants";
import logger from "../../../utils/logger";
Expand All @@ -15,6 +15,7 @@ import { getAcspRegistration } from "../../../services/acspRegistrationService";
import { AcspData } from "@companieshouse/api-sdk-node/dist/services/acsp";
import { ErrorService } from "../../../services/errorService";
import { AcspDataService } from "../../../services/acspDataService";
import { getPreviousPageUrl } from "../../../services/url";

export const get = async (req: Request, res: Response, next: NextFunction) => {
const lang = selectLang(req.query.lang);
Expand All @@ -39,7 +40,11 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
const acspData = await getAcspRegistration(session, session.getExtraData(SUBMISSION_ID)!, res.locals.applicationId);
if (acspData !== undefined) {
saveDataInSession(req, USER_DATA, acspData);
if (acspData.typeOfBusiness === "UNINCORPORATED" || acspData.typeOfBusiness === "CORPORATE_BODY") {
const prevUrl = getPreviousPageUrl(req, BASE_URL);
const isRedirectedForSoleTrader: boolean = prevUrl?.includes(LIMITED_BUSINESS_MUSTBE_AML_REGISTERED_KICKOUT);
if (isRedirectedForSoleTrader) {
typeOfBusiness = "SOLE_TRADER";
} else if (acspData.typeOfBusiness === "UNINCORPORATED" || acspData.typeOfBusiness === "CORPORATE_BODY") {
typeOfBusiness = "OTHER";
} else {
typeOfBusiness = acspData.typeOfBusiness!;
Expand Down Expand Up @@ -73,7 +78,6 @@ export const post = async (req: Request, res: Response, next: NextFunction) => {
const session: Session = req.session as any as Session;
const acspData: AcspData = session?.getExtraData(USER_DATA)!;
try {

if (!errorList.isEmpty()) {
const pageProperties = getPageProperties(formatValidationError(errorList.array(), lang));
res.status(400).render(config.TYPE_OF_BUSINESS, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const get = async (req: Request, res: Response, next: NextFunction) => {
try {
// update typeOfBusiness in DB
const acspData = await getAcspRegistration(session, session.getExtraData(SUBMISSION_ID)!, res.locals.applicationId);
acspData.typeOfBusiness = "SOLE_TRADER";
const acspDataService = new AcspDataService();
await acspDataService.saveAcspData(session, acspData);

Expand Down
1 change: 0 additions & 1 deletion test/mocks/transaction_mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const validTransaction: Transaction = {
},
description: "Mandatory transaction description"
};

export const validTransactionSDKResource: Resource<Transaction> = {
httpStatusCode: StatusCodes.OK,
resource: validTransaction
Expand Down
58 changes: 57 additions & 1 deletion test/src/controllers/common/typeOfBusinessController.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mocks from "../../../mocks/all_middleware_mock";
import supertest from "supertest";
import app from "../../../../src/app";
import { TYPE_OF_BUSINESS, BASE_URL, LIMITED_WHAT_IS_THE_COMPANY_NUMBER, OTHER_TYPE_OF_BUSINESS, UNINCORPORATED_NAME_REGISTERED_WITH_AML, SOLE_TRADER_WHAT_IS_YOUR_ROLE } from "../../../../src/types/pageURL";
import { TYPE_OF_BUSINESS, BASE_URL, LIMITED_BUSINESS_MUSTBE_AML_REGISTERED_KICKOUT, LIMITED_WHAT_IS_THE_COMPANY_NUMBER, OTHER_TYPE_OF_BUSINESS, UNINCORPORATED_NAME_REGISTERED_WITH_AML, SOLE_TRADER_WHAT_IS_YOUR_ROLE } from "../../../../src/types/pageURL";
import { getAcspRegistration, postAcspRegistration, putAcspRegistration } from "../../../../src/services/acspRegistrationService";
import { AcspData } from "@companieshouse/api-sdk-node/dist/services/acsp/types";
import { sessionMiddleware } from "../../../../src/middleware/session_middleware";
Expand All @@ -26,8 +26,50 @@ const acspData: AcspData = {
id: "abc",
typeOfBusiness: "LIMITED"
};

const acspDataUnIncorporated: AcspData = {
id: "unincorporated",
typeOfBusiness: "UNINCORPORATED"
};

const acspDataCorporateBody: AcspData = {
id: "corporatebody",
typeOfBusiness: "CORPORATE_BODY"
};

describe("GET " + TYPE_OF_BUSINESS, () => {

it("should return status for the 200", async () => {
mockGetAcspRegistration.mockResolvedValueOnce(acspData);
const res = await router.get(BASE_URL + TYPE_OF_BUSINESS)
.set("Custom-Header", BASE_URL + LIMITED_BUSINESS_MUSTBE_AML_REGISTERED_KICKOUT);
expect(mocks.mockSessionMiddleware).toHaveBeenCalled();
expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled();
expect(mockGetAcspRegistration).toHaveBeenCalledTimes(1);
expect(res.status).toBe(200);
expect(res.text).toContain("What type of business are you registering?");
});

it("should return status 200", async () => {
mockGetAcspRegistration.mockResolvedValueOnce(acspDataUnIncorporated);
const res = await router.get(BASE_URL + TYPE_OF_BUSINESS);
expect(mocks.mockSessionMiddleware).toHaveBeenCalled();
expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled();
expect(mockGetAcspRegistration).toHaveBeenCalledTimes(1);
expect(res.status).toBe(200);
expect(res.text).toContain("What type of business are you registering?");
});

it("should return status 200", async () => {
mockGetAcspRegistration.mockResolvedValueOnce(acspDataCorporateBody);
const res = await router.get(BASE_URL + TYPE_OF_BUSINESS);
expect(mocks.mockSessionMiddleware).toHaveBeenCalled();
expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled();
expect(mockGetAcspRegistration).toHaveBeenCalledTimes(1);
expect(res.status).toBe(200);
expect(res.text).toContain("What type of business are you registering?");
});

it("should return status 200", async () => {
mockGetAcspRegistration.mockResolvedValueOnce(acspData);
const res = await router.get(BASE_URL + TYPE_OF_BUSINESS);
Expand Down Expand Up @@ -102,6 +144,20 @@ describe("POST " + TYPE_OF_BUSINESS, () => {
});
});

describe("GET for SUBMISSION_ID = null" + TYPE_OF_BUSINESS, () => {
beforeEach(() => {
createMockSessionMiddleware();
});
it("should return status 200 and create a transaction", async () => {
mockPostTransaction.mockResolvedValueOnce({ id: "12345" });
const res = await router.get(BASE_URL + TYPE_OF_BUSINESS);
expect(mocks.mockSessionMiddleware).toHaveBeenCalled();
expect(mocks.mockAuthenticationMiddleware).toHaveBeenCalled();
expect(res.status).toBe(200);
expect(res.text).toContain("What type of business are you registering?");
});
});

describe("POST for acspData = null" + TYPE_OF_BUSINESS, () => {
beforeEach(() => {
createMockSessionMiddleware();
Expand Down

0 comments on commit c19c1a8

Please sign in to comment.