@@ -631,9 +631,9 @@ class PurchaserRemoveServiceSpec extends SpecBase with MockitoSugar with BeforeA
631631 when(mockBackendConnector.updateReturnVersion(any())(any(), any()))
632632 .thenReturn(Future .successful(ReturnVersionUpdateReturn (Some (2 ))))
633633 when(mockBackendConnector.deletePurchaser(any())(any(), any()))
634- .thenReturn(Future .successful(( DeletePurchaserReturn (deleted = true ) )))
634+ .thenReturn(Future .successful(DeletePurchaserReturn (deleted = true )))
635635 when(mockBackendConnector.updatePurchaser(any())(any(), any()))
636- .thenReturn(Future .successful(( UpdatePurchaserReturn (updated = true ) )))
636+ .thenReturn(Future .successful(UpdatePurchaserReturn (updated = true )))
637637
638638 val result = service.handleRemoval(
639639 PurchaserRemove .Remove (nonmainPurchaserID),
@@ -644,6 +644,62 @@ class PurchaserRemoveServiceSpec extends SpecBase with MockitoSugar with BeforeA
644644 verify(mockBackendConnector).updateReturnVersion(any())(any(), any())
645645 verify(mockBackendConnector).deletePurchaser(any())(any(), any())
646646 verify(mockBackendConnector).updatePurchaser(any())(any(), any())
647+ verify(mockBackendConnector, never()).deleteCompanyDetails(any())(any(), any())
648+ }
649+
650+ " must handle Remove for non-main purchaser with multiple purchasers and main purchaser is company" in {
651+ val mainPurchaserID = " PURCH001"
652+ val nonmainPurchaserID = " PURCH002"
653+
654+ val purchaser1 = createPurchaser(
655+ mainPurchaserID,
656+ companyName = Some (" TestCo" ),
657+ isCompany = Some (" YES" ),
658+ nextPurchaserID = Some (nonmainPurchaserID),
659+ purchaserRef = Some (" 1" )
660+ )
661+ val purchaser2 = createPurchaser(
662+ nonmainPurchaserID,
663+ forename1 = Some (" Jane" ),
664+ surname = Some (" Doe" ),
665+ nextPurchaserID = None ,
666+ purchaserRef = Some (" 2" )
667+ )
668+
669+ val returnInfo = ReturnInfo (mainPurchaserID = Some (mainPurchaserID), version = Some (" 0" ))
670+ val fullReturn = emptyFullReturn.copy(
671+ purchaser = Some (Seq (purchaser1, purchaser2)),
672+ returnInfo = Some (returnInfo),
673+ companyDetails = Some (CompanyDetails (companyDetailsID = Some (" COMP001" )))
674+ )
675+ val purchaserRefs = PurchaserAndCompanyId (nonmainPurchaserID, Some (" COMP001" ))
676+ val userAnswers = emptyUserAnswers
677+ .copy(fullReturn = Some (fullReturn))
678+ .set(PurchaserOverviewRemovePage , purchaserRefs).success.value
679+
680+ implicit val request : DataRequest [AnyContent ] = DataRequest (
681+ FakeRequest (),
682+ " id" ,
683+ userAnswers
684+ )
685+
686+ when(mockBackendConnector.updateReturnVersion(any())(any(), any()))
687+ .thenReturn(Future .successful(ReturnVersionUpdateReturn (Some (2 ))))
688+ when(mockBackendConnector.deletePurchaser(any())(any(), any()))
689+ .thenReturn(Future .successful(DeletePurchaserReturn (deleted = true )))
690+ when(mockBackendConnector.updatePurchaser(any())(any(), any()))
691+ .thenReturn(Future .successful(UpdatePurchaserReturn (updated = true )))
692+
693+ val result = service.handleRemoval(
694+ PurchaserRemove .Remove (nonmainPurchaserID),
695+ userAnswers
696+ )
697+
698+ status(result) mustBe SEE_OTHER
699+ verify(mockBackendConnector).updateReturnVersion(any())(any(), any())
700+ verify(mockBackendConnector).deletePurchaser(any())(any(), any())
701+ verify(mockBackendConnector).updatePurchaser(any())(any(), any())
702+ verify(mockBackendConnector, never()).deleteCompanyDetails(any())(any(), any())
647703 }
648704
649705 " must handle Remove for main purchaser with exactly two purchasers" in {
@@ -681,11 +737,11 @@ class PurchaserRemoveServiceSpec extends SpecBase with MockitoSugar with BeforeA
681737 when(mockBackendConnector.updateReturnVersion(any())(any(), any()))
682738 .thenReturn(Future .successful(ReturnVersionUpdateReturn (Some (2 ))))
683739 when(mockBackendConnector.deletePurchaser(any())(any(), any()))
684- .thenReturn(Future .successful(( DeletePurchaserReturn (deleted = true ) )))
740+ .thenReturn(Future .successful(DeletePurchaserReturn (deleted = true )))
685741 when(mockBackendConnector.updatePurchaser(any())(any(), any()))
686- .thenReturn(Future .successful(( UpdatePurchaserReturn (updated = true ) )))
742+ .thenReturn(Future .successful(UpdatePurchaserReturn (updated = true )))
687743 when(mockBackendConnector.updateReturnInfo(any())(any(), any()))
688- .thenReturn(Future .successful(( ReturnInfoReturn (updated = true ) )))
744+ .thenReturn(Future .successful(ReturnInfoReturn (updated = true )))
689745
690746 val result = service.handleRemoval(
691747 PurchaserRemove .Remove (mainPurchaserID),
@@ -727,9 +783,9 @@ class PurchaserRemoveServiceSpec extends SpecBase with MockitoSugar with BeforeA
727783 when(mockBackendConnector.updateReturnVersion(any())(any(), any()))
728784 .thenReturn(Future .successful(ReturnVersionUpdateReturn (Some (2 ))))
729785 when(mockBackendConnector.deletePurchaser(any())(any(), any()))
730- .thenReturn(Future .successful(( DeletePurchaserReturn (deleted = true ) )))
786+ .thenReturn(Future .successful(DeletePurchaserReturn (deleted = true )))
731787 when(mockBackendConnector.deleteCompanyDetails(any())(any(), any()))
732- .thenReturn(Future .successful(( DeleteCompanyDetailsReturn (deleted = true ) )))
788+ .thenReturn(Future .successful(DeleteCompanyDetailsReturn (deleted = true )))
733789
734790 val result = service.handleRemoval(
735791 PurchaserRemove .Remove (purchaserId),
@@ -782,9 +838,9 @@ class PurchaserRemoveServiceSpec extends SpecBase with MockitoSugar with BeforeA
782838 when(mockBackendConnector.updateReturnVersion(any())(any(), any()))
783839 .thenReturn(Future .successful(ReturnVersionUpdateReturn (Some (2 ))))
784840 when(mockBackendConnector.deletePurchaser(any())(any(), any()))
785- .thenReturn(Future .successful(( DeletePurchaserReturn (deleted = true ) )))
841+ .thenReturn(Future .successful(DeletePurchaserReturn (deleted = true )))
786842 when(mockBackendConnector.updateReturnInfo(any())(any(), any()))
787- .thenReturn(Future .successful(( ReturnInfoReturn (updated = true ) )))
843+ .thenReturn(Future .successful(ReturnInfoReturn (updated = true )))
788844
789845 val result = service.handleRemoval(
790846 PurchaserRemove .SelectNewMain (newmainPurchaserID),
@@ -839,11 +895,11 @@ class PurchaserRemoveServiceSpec extends SpecBase with MockitoSugar with BeforeA
839895 when(mockBackendConnector.updateReturnVersion(any())(any(), any()))
840896 .thenReturn(Future .successful(ReturnVersionUpdateReturn (Some (2 ))))
841897 when(mockBackendConnector.deletePurchaser(any())(any(), any()))
842- .thenReturn(Future .successful(( DeletePurchaserReturn (deleted = true ) )))
898+ .thenReturn(Future .successful(DeletePurchaserReturn (deleted = true )))
843899 when(mockBackendConnector.updatePurchaser(any())(any(), any()))
844- .thenReturn(Future .successful(( UpdatePurchaserReturn (updated = true ) )))
900+ .thenReturn(Future .successful(UpdatePurchaserReturn (updated = true )))
845901 when(mockBackendConnector.updateReturnInfo(any())(any(), any()))
846- .thenReturn(Future .successful(( ReturnInfoReturn (updated = true ) )))
902+ .thenReturn(Future .successful(ReturnInfoReturn (updated = true )))
847903
848904 val result = service.handleRemoval(
849905 PurchaserRemove .SelectNewMain (newmainPurchaserID),
0 commit comments