Skip to content

Commit 3507e05

Browse files
HDPI-6099: Set gen app reference on generated submission doc entity
1 parent cff9d83 commit 3507e05

4 files changed

Lines changed: 61 additions & 10 deletions

File tree

src/main/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplication.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import uk.gov.hmcts.reform.pcs.ccd.domain.State;
1717
import uk.gov.hmcts.reform.pcs.ccd.domain.VerticalYesNo;
1818
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppRequest;
19+
import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity;
1920
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
2021
import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity;
2122
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
@@ -197,7 +198,13 @@ private void createSubmissionDocument(long caseReference,
197198
applicantParty
198199
);
199200

200-
documentImportService.addDocumentToCase(caseReference, documentUrl, CaseFileCategory.APPLICATIONS);
201+
DocumentEntity importedDocumentEntity = documentImportService.addDocumentToCase(
202+
caseReference,
203+
documentUrl,
204+
CaseFileCategory.APPLICATIONS
205+
);
206+
207+
importedDocumentEntity.setGeneralApplication(genAppEntity);
201208
}
202209

203210
@SuppressWarnings("SameParameterValue")

src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentImportService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public class DocumentImportService {
2323
private final IdamService idamService;
2424
private final AuthTokenGenerator authTokenGenerator;
2525

26-
public void addDocumentToCase(long caseReference,
27-
String documentUrl,
28-
CaseFileCategory caseFileCategory) {
26+
public DocumentEntity addDocumentToCase(long caseReference,
27+
String documentUrl,
28+
CaseFileCategory caseFileCategory) {
2929

3030
String[] urlParts = documentUrl.split("/");
3131
UUID documentId = UUID.fromString(urlParts[urlParts.length - 1]);
@@ -48,6 +48,8 @@ public void addDocumentToCase(long caseReference,
4848

4949
PcsCaseEntity pcsCaseEntity = pcsCaseService.loadCase(caseReference);
5050
pcsCaseEntity.addDocuments(List.of(documentEntity));
51+
52+
return documentEntity;
5153
}
5254

5355
}

src/test/java/uk/gov/hmcts/reform/pcs/ccd/event/genapp/MakeAnApplicationTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.CitizenGenAppRequest;
2323
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.GenAppType;
2424
import uk.gov.hmcts.reform.pcs.ccd.domain.genapp.XuiGenAppRequest;
25+
import uk.gov.hmcts.reform.pcs.ccd.entity.DocumentEntity;
2526
import uk.gov.hmcts.reform.pcs.ccd.entity.GenAppEntity;
2627
import uk.gov.hmcts.reform.pcs.ccd.entity.PcsCaseEntity;
2728
import uk.gov.hmcts.reform.pcs.ccd.entity.party.PartyEntity;
@@ -47,6 +48,7 @@
4748
import static org.assertj.core.api.Assertions.assertThat;
4849
import static org.junit.jupiter.params.provider.Arguments.arguments;
4950
import static org.mockito.ArgumentMatchers.any;
51+
import static org.mockito.ArgumentMatchers.anyString;
5052
import static org.mockito.ArgumentMatchers.eq;
5153
import static org.mockito.BDDMockito.given;
5254
import static org.mockito.Mockito.mock;
@@ -344,6 +346,40 @@ void shouldGenerateGenAppDocumentAndStoreMetadata() {
344346
);
345347
}
346348

349+
@Test
350+
void shouldSetGenAppReferenceOnImportedDocumentEntity() {
351+
CitizenGenAppRequest genAppRequest = CitizenGenAppRequest.builder()
352+
.applicationType(GenAppType.ADJOURN)
353+
.clientReference("some reference")
354+
.build();
355+
356+
final PCSCase caseData = PCSCase.builder()
357+
.citizenGenAppRequest(genAppRequest)
358+
.build();
359+
360+
PartyEntity applicantParty = stubCurrentUserParty();
361+
362+
GenAppEntity genAppEntity = mock(GenAppEntity.class);
363+
when(genAppService.createGenAppEntity(genAppRequest, pcsCaseEntity, applicantParty))
364+
.thenReturn(genAppEntity);
365+
366+
String documentUrl = "some document URL";
367+
when(genAppDocumentGenerator
368+
.generateSubmissionDocument(TEST_CASE_REFERENCE, genAppRequest, genAppEntity, applicantParty))
369+
.thenReturn(documentUrl);
370+
371+
DocumentEntity importedDocumentEntity = mock(DocumentEntity.class);
372+
when(documentImportService
373+
.addDocumentToCase(eq(TEST_CASE_REFERENCE), anyString(), any(CaseFileCategory.class)))
374+
.thenReturn(importedDocumentEntity);
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();

src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/document/DocumentImportServiceTest.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,23 @@ void shouldAddDocumentToCaseWithMetadata() {
7171
when(pcsCaseService.loadCase(CASE_REFERENCE)).thenReturn(pcsCaseEntity);
7272

7373
// When
74-
underTest.addDocumentToCase(CASE_REFERENCE, documentUrl, CaseFileCategory.HEARING_DOCUMENTS);
74+
DocumentEntity returnedDocumentEntity = underTest.addDocumentToCase(
75+
CASE_REFERENCE,
76+
documentUrl,
77+
CaseFileCategory.HEARING_DOCUMENTS
78+
);
7579

7680
// Then
7781
verify(pcsCaseEntity).addDocuments(documentEntityListCaptor.capture());
7882
assertThat(documentEntityListCaptor.getValue()).hasSize(1);
7983

80-
DocumentEntity documentEntity = documentEntityListCaptor.getValue().getFirst();
81-
assertThat(documentEntity.getFileName()).isEqualTo("original filename");
82-
assertThat(documentEntity.getUrl()).isEqualTo("test url");
83-
assertThat(documentEntity.getBinaryUrl()).isEqualTo("test binary url");
84-
assertThat(documentEntity.getCategoryId()).isEqualTo(CaseFileCategory.HEARING_DOCUMENTS.getId());
84+
DocumentEntity addedDocumentEntity = documentEntityListCaptor.getValue().getFirst();
85+
assertThat(addedDocumentEntity.getFileName()).isEqualTo("original filename");
86+
assertThat(addedDocumentEntity.getUrl()).isEqualTo("test url");
87+
assertThat(addedDocumentEntity.getBinaryUrl()).isEqualTo("test binary url");
88+
assertThat(addedDocumentEntity.getCategoryId()).isEqualTo(CaseFileCategory.HEARING_DOCUMENTS.getId());
89+
90+
assertThat(returnedDocumentEntity).isSameAs(addedDocumentEntity);
8591
}
8692

8793
@SuppressWarnings("SameParameterValue")

0 commit comments

Comments
 (0)