@@ -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
7173mockCsrfProtectionMiddleware . mockClear ( ) ;
7274const 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} ) ;
0 commit comments