Skip to content

Commit cf236e2

Browse files
committed
Merge remote-tracking branch 'origin/master' into access-fix
2 parents 372f18c + 4640f50 commit cf236e2

5 files changed

Lines changed: 61 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ private List<DocumentEntity> createDocumentEntities(
181181
}
182182

183183
public DocumentType mapAdditionalDocumentTypeToDocumentType(AdditionalDocumentType additionalType) {
184+
if (additionalType == null) {
185+
return null;
186+
}
184187
return switch (additionalType) {
185188
case WITNESS_STATEMENT -> DocumentType.WITNESS_STATEMENT;
186189
case RENT_STATEMENT -> DocumentType.RENT_STATEMENT;

src/main/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ private List<DocumentEntity> createDocumentEntities(List<ListValue<UploadedDocum
144144
.fileName(updatedFilename)
145145
.binaryUrl(uploadedDocument.getDocument().getBinaryUrl())
146146
.categoryId(CaseFileCategory.APPLICATIONS.getId())
147-
.type(documentService.mapAdditionalDocumentTypeToDocumentType(uploadedDocument.getDocumentType()))
147+
.type(uploadedDocument.getDocumentType() != null
148+
? documentService.mapAdditionalDocumentTypeToDocumentType(uploadedDocument.getDocumentType())
149+
: null)
148150
.contentType(uploadedDocument.getContentType())
149151
.size(uploadedDocument.getSizeInBytes())
150152
.build();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE case_note DROP COLUMN claim_id;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,15 @@ void shouldMapAdditionalDocumentTypeToDocumentType(AdditionalDocumentType additi
804804
assertThat(actualDocumentType).isEqualTo(expectedDocumentType);
805805
}
806806

807+
@Test
808+
void shouldReturnNullWhenAdditionalDocumentTypeIsNull() {
809+
// When
810+
DocumentType actualDocumentType = underTest.mapAdditionalDocumentTypeToDocumentType(null);
811+
812+
// Then
813+
assertThat(actualDocumentType).isNull();
814+
}
815+
807816
private static Stream<Arguments> additionalDocumentCategoryScenarios() {
808817
return Stream.of(
809818
Arguments.of(

src/test/java/uk/gov/hmcts/reform/pcs/ccd/service/genapp/GenAppServiceTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,51 @@ void shouldSaveUploadedDocuments() {
387387
assertThat(documentEntity.getSize()).isEqualTo(1234L);
388388
}
389389

390+
@Test
391+
void shouldSaveUploadedDocumentWithNullTypeWhenNoDocumentType() {
392+
// Given
393+
String originalFilename = "original filename";
394+
String modifiedFilename = "modified filename";
395+
396+
Document document = Document.builder()
397+
.filename(originalFilename)
398+
.url("test url")
399+
.binaryUrl("test binary url")
400+
.build();
401+
402+
UUID applicantPartyId = UUID.randomUUID();
403+
when(applicantParty.getId()).thenReturn(applicantPartyId);
404+
when(documentNameService.appendGenAppPostfix(eq(originalFilename), isA(GenAppEntity.class),
405+
eq(mainClaim), eq(applicantPartyId)))
406+
.thenReturn(modifiedFilename);
407+
408+
UploadedDocument uploadedDocument = UploadedDocument.builder()
409+
.document(document)
410+
.contentType("test content type")
411+
.sizeInBytes(1234L)
412+
.build();
413+
414+
CitizenGenAppRequest genAppRequest = CitizenGenAppRequest.builder()
415+
.sotAccepted(VerticalYesNo.YES)
416+
.hasSupportingDocuments(VerticalYesNo.YES)
417+
.uploadedDocuments(List.of(ListValue.<UploadedDocument>builder().value(uploadedDocument).build()))
418+
.build();
419+
420+
when(documentRepository.saveAll(anyList())).thenReturn(List.of(mock(DocumentEntity.class)));
421+
422+
// When
423+
Throwable throwable = catchThrowable(
424+
() -> underTest.createGenAppEntity(genAppRequest, pcsCaseEntity, applicantParty)
425+
);
426+
427+
// Then
428+
assertThat(throwable).isNull();
429+
430+
verify(documentRepository).saveAll(documentEntityListCaptor.capture());
431+
assertThat(documentEntityListCaptor.getValue()).hasSize(1);
432+
assertThat(documentEntityListCaptor.getValue().getFirst().getType()).isNull();
433+
}
434+
390435
@Test
391436
void shouldNotSaveUploadedDocumentsIfSupportingDocumentsFlagIsNo() {
392437
// Given

0 commit comments

Comments
 (0)