Skip to content

Commit

Permalink
[kbss-cvut/record-manager-ui#184] Fixed importRecordsJsonImportsSpeci…
Browse files Browse the repository at this point in the history
…fiedRecordsAndReturnsImportResult importRecordsJsonReturnsConflictWhenServiceThrowsRecordAuthorNotFound
  • Loading branch information
palagdan committed Jul 20, 2024
1 parent f1255af commit 7b5579f
Showing 1 changed file with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,25 +305,6 @@ void exportRecordsExportsRecordsForProvidedInstitutionForSpecifiedPeriod() throw
Pageable.unpaged());
}

// @Test
// void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exception {
// final List<PatientRecord> records =
// List.of(Generator.generatePatientRecord(user), Generator.generatePatientRecord(user));
// final RecordImportResult importResult = new RecordImportResult(records.size());
// importResult.setImportedCount(records.size());
// when(patientRecordServiceMock.importRecords(anyList())).thenReturn(importResult);
//
// final MvcResult mvcResult = mockMvc.perform(
// post("/records/import/json").content(toJson(records)).contentType(MediaType.MULTIPART_FORM_DATA_VALUE)).andReturn();
// final RecordImportResult result = readValue(mvcResult, RecordImportResult.class);
// assertEquals(importResult.getTotalCount(), result.getTotalCount());
// assertEquals(importResult.getImportedCount(), result.getImportedCount());
// assertThat(importResult.getErrors(), anyOf(nullValue(), empty()));
// @SuppressWarnings("unchecked")
// final ArgumentCaptor<List<PatientRecord>> captor = ArgumentCaptor.forClass(List.class);
// verify(patientRecordServiceMock).importRecords(captor.capture());
// assertEquals(records.size(), captor.getValue().size());
// }

@Test
void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exception {
Expand All @@ -337,9 +318,6 @@ void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exc
MockMultipartFile file = new MockMultipartFile("file", "records.json",
MediaType.MULTIPART_FORM_DATA_VALUE, toJson(records).getBytes());

String jsonContent = new String(file.getBytes());
System.out.println("Received JSON content: " + jsonContent);

final MvcResult mvcResult = mockMvc.perform(
multipart("/records/import/json")
.file(file)
Expand All @@ -356,6 +334,7 @@ void importRecordsJsonImportsSpecifiedRecordsAndReturnsImportResult() throws Exc

@SuppressWarnings("unchecked")
final ArgumentCaptor<List<PatientRecord>> captor = ArgumentCaptor.forClass(List.class);
verify(patientRecordServiceMock).importRecords(captor.capture());
assertEquals(records.size(), captor.getValue().size());
}

Expand Down Expand Up @@ -388,8 +367,14 @@ void importRecordsJsonReturnsConflictWhenServiceThrowsRecordAuthorNotFound() thr
List.of(Generator.generatePatientRecord(user), Generator.generatePatientRecord(user));
when(patientRecordServiceMock.importRecords(anyList())).thenThrow(RecordAuthorNotFoundException.class);

mockMvc.perform(post("/records/import/json").content(toJson(records)).contentType(MediaType.MULTIPART_FORM_DATA_VALUE))
.andExpect(status().isConflict());
MockMultipartFile file = new MockMultipartFile("file", "records.json",
MediaType.MULTIPART_FORM_DATA_VALUE, toJson(records).getBytes());

mockMvc.perform(
multipart("/records/import/json")
.file(file)
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE)
).andExpect(status().isConflict());
}

@Test
Expand Down

0 comments on commit 7b5579f

Please sign in to comment.