Skip to content

Commit bfadee7

Browse files
authored
Merge pull request #1751 from companieshouse/origin/feature/roecct-761-add-tests-filter-dummy-ap
ROECCT-761: Add more tests - filter dummy associated party form CHS pages
2 parents 4081c6e + 9ec3e5e commit bfadee7

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

test/controllers/trusts.involved.controller.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ import {
6767
TRUST_INDIVIDUAL_BENEFICIAL_OWNER_PAGE,
6868
UPDATE_MANAGE_TRUSTS_TELL_US_ABOUT_THE_FORMER_BO_PAGE, LANDING_URL,
6969
} from '../../src/config';
70+
import { IndividualTrustee, TrustIndividual, TrustKey } from "../../src/model/trust.model";
71+
import { ApplicationData } from "../../src/model";
7072

7173
mockCsrfProtectionMiddleware.mockClear();
7274
const mockIsActiveFeature = isActiveFeature as jest.Mock;
@@ -613,5 +615,56 @@ describe('Trust Involved controller', () => {
613615
expect(resp.text).toContain(ADD_TRUST_URL);
614616
expect(resp.text).not.toContain(PAGE_TITLE_ERROR);
615617
});
618+
619+
test(`filters out individuals without a forename or dummy associated parties`, async () => {
620+
621+
const individualTrustee1 = { surname: "dummySurname" } as IndividualTrustee;
622+
const individualTrustee2 = { forename: "empty" } as IndividualTrustee;
623+
624+
const mockAppData: ApplicationData = {
625+
[TrustKey]: [{
626+
'INDIVIDUALS': [ individualTrustee1, individualTrustee2 ] as TrustIndividual[],
627+
}]
628+
} as ApplicationData;
629+
630+
(fetchApplicationData as jest.Mock).mockResolvedValue(mockAppData);
631+
mockReq.body = {
632+
noMoreToAdd: 'noMoreToAdd',
633+
};
634+
mockIsActiveFeature.mockReturnValue(false);
635+
await post(mockReq, mockRes, mockNext);
636+
await postTrustInvolvedPage(mockReq, mockRes, mockNext, true, true);
637+
638+
expect(mockAppData.trusts?.[0].INDIVIDUALS).toEqual([individualTrustee2]);
639+
640+
expect(mockRes.redirect).toBeCalledWith(`${TRUST_ENTRY_URL + ADD_TRUST_URL}`);
641+
});
642+
643+
test(`keeps all valid individuals and ignore dummy associated parties`, async () => {
644+
645+
const individualTrustee1 = { forename: "TestOne" } as IndividualTrustee;
646+
const individualTrustee2 = { forename: "TestTwo" } as IndividualTrustee;
647+
const individualTrustee3 = { forename: "testThree", surname: "TestSurname" } as IndividualTrustee;
648+
const individualTrustee4 = { surname: "OE001022A1" } as IndividualTrustee;
649+
650+
const mockAppData: ApplicationData = {
651+
[TrustKey]: [{
652+
'INDIVIDUALS': [ individualTrustee1, individualTrustee2, individualTrustee3, individualTrustee4 ] as TrustIndividual[],
653+
}]
654+
} as ApplicationData;
655+
656+
(fetchApplicationData as jest.Mock).mockResolvedValue(mockAppData);
657+
mockReq.body = {
658+
noMoreToAdd: 'noMoreToAdd',
659+
};
660+
mockIsActiveFeature.mockReturnValue(false);
661+
await post(mockReq, mockRes, mockNext);
662+
await postTrustInvolvedPage(mockReq, mockRes, mockNext, true, true);
663+
664+
expect(mockAppData.trusts?.[0].INDIVIDUALS).toEqual([individualTrustee1, individualTrustee2, individualTrustee3]);
665+
expect(mockAppData.trusts?.[0].INDIVIDUALS).not.toEqual([individualTrustee4]);
666+
667+
expect(mockRes.redirect).toBeCalledWith(`${TRUST_ENTRY_URL + ADD_TRUST_URL}`);
668+
});
616669
});
617670
});

test/utils/trust.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ describe('Trust Utils method tests', () => {
471471

472472
const result = getIndividualTrustee(appData, test_trust_id, trusteeId);
473473
expect(result).toEqual(individualTrustee1);
474-
// expect(result.id).toEqual(trusteeId);
475474
});
476475

477476
test("test getIndividualTrusteeFromTrust with application data with no trusteeId", () => {

0 commit comments

Comments
 (0)