2222import uk .gov .hmcts .reform .pcs .ccd .domain .genapp .CitizenGenAppRequest ;
2323import uk .gov .hmcts .reform .pcs .ccd .domain .genapp .GenAppType ;
2424import uk .gov .hmcts .reform .pcs .ccd .domain .genapp .XuiGenAppRequest ;
25+ import uk .gov .hmcts .reform .pcs .ccd .entity .DocumentEntity ;
2526import uk .gov .hmcts .reform .pcs .ccd .entity .GenAppEntity ;
2627import uk .gov .hmcts .reform .pcs .ccd .entity .PcsCaseEntity ;
2728import uk .gov .hmcts .reform .pcs .ccd .entity .party .PartyEntity ;
4849import static org .junit .jupiter .params .provider .Arguments .arguments ;
4950import static org .mockito .ArgumentMatchers .any ;
5051import static org .mockito .ArgumentMatchers .eq ;
52+ import static org .mockito .ArgumentMatchers .nullable ;
5153import static org .mockito .BDDMockito .given ;
54+ import static org .mockito .Mock .Strictness .LENIENT ;
5255import static org .mockito .Mockito .mock ;
5356import static org .mockito .Mockito .never ;
5457import static org .mockito .Mockito .verify ;
@@ -69,7 +72,7 @@ class MakeAnApplicationTest extends BaseEventTest {
6972 private GenAppRepository genAppRepository ;
7073 @ Mock
7174 private GenAppDocumentGenerator genAppDocumentGenerator ;
72- @ Mock
75+ @ Mock ( strictness = LENIENT )
7376 private DocumentImportService documentImportService ;
7477 @ Mock
7578 private LegalRepresentativeService legalRepresentativeService ;
@@ -221,6 +224,7 @@ class XuiSubmitEventTests {
221224
222225 @ BeforeEach
223226 void setUp () {
227+ stubDocumentImport ();
224228 given (pcsCaseService .loadCase (TEST_CASE_REFERENCE )).willReturn (pcsCaseEntity );
225229 }
226230
@@ -259,6 +263,7 @@ class CitizenSubmitEventTests {
259263
260264 @ BeforeEach
261265 void setUp () {
266+ stubDocumentImport ();
262267 given (pcsCaseService .loadCase (TEST_CASE_REFERENCE )).willReturn (pcsCaseEntity );
263268 }
264269
@@ -344,6 +349,37 @@ void shouldGenerateGenAppDocumentAndStoreMetadata() {
344349 );
345350 }
346351
352+ @ Test
353+ void shouldSetGenAppReferenceOnImportedDocumentEntity () {
354+ CitizenGenAppRequest genAppRequest = CitizenGenAppRequest .builder ()
355+ .applicationType (GenAppType .ADJOURN )
356+ .clientReference ("some reference" )
357+ .build ();
358+
359+ final PCSCase caseData = PCSCase .builder ()
360+ .citizenGenAppRequest (genAppRequest )
361+ .build ();
362+
363+ PartyEntity applicantParty = stubCurrentUserParty ();
364+
365+ GenAppEntity genAppEntity = mock (GenAppEntity .class );
366+ when (genAppService .createGenAppEntity (genAppRequest , pcsCaseEntity , applicantParty ))
367+ .thenReturn (genAppEntity );
368+
369+ String documentUrl = "some document URL" ;
370+ when (genAppDocumentGenerator
371+ .generateSubmissionDocument (TEST_CASE_REFERENCE , genAppRequest , genAppEntity , applicantParty ))
372+ .thenReturn (documentUrl );
373+
374+ DocumentEntity importedDocumentEntity = stubDocumentImport ();
375+
376+ // When
377+ callSubmitHandler (caseData );
378+
379+ // Then
380+ verify (importedDocumentEntity ).setGeneralApplication (genAppEntity );
381+ }
382+
347383 private PartyEntity stubCurrentUserParty () {
348384 PartyEntity currentUserParty = mock (PartyEntity .class );
349385 UUID currentUserId = UUID .randomUUID ();
@@ -353,4 +389,12 @@ private PartyEntity stubCurrentUserParty() {
353389 }
354390
355391 }
392+
393+ private DocumentEntity stubDocumentImport () {
394+ DocumentEntity importedDocumentEntity = mock (DocumentEntity .class );
395+ when (documentImportService
396+ .addDocumentToCase (eq (TEST_CASE_REFERENCE ), nullable (String .class ), any (CaseFileCategory .class )))
397+ .thenReturn (importedDocumentEntity );
398+ return importedDocumentEntity ;
399+ }
356400}
0 commit comments