Skip to content

Commit

Permalink
GRAD2-2817
Browse files Browse the repository at this point in the history
Fix for duplicated archive school reports
  • Loading branch information
arybakov-cgi committed Sep 6, 2024
1 parent 87bdd7c commit a777986
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public Integer archiveSchoolReports(long batchId, List<String> schoolOfRecords,
Integer updatedReportsCount = 0;
Integer deletedReportsCount = 0;
Integer originalReportsCount = 0;
String archivedReportType = StringUtils.upperCase(StringUtils.endsWith(reportType, "ARC") ? reportType : reportType + "ARC");
String archivedReportType = StringUtils.appendIfMissing(reportType, "ARC", "ARC");
if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) {
originalReportsCount += schoolReportsRepository.countBySchoolOfRecordsAndReportType(schoolOfRecords, reportType);
updatedReportsCount += schoolReportsRepository.archiveSchoolReports(schoolOfRecords, reportType, archivedReportType, batchId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1798,39 +1798,45 @@ public Page map(Function converter) {

@Test
public void testArchiveSchoolReports() {
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(1);
Integer count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType");
Integer count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(1);

Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(0);
count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType");
count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(0);

Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolReports("reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.archiveSchoolReports("reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(1);
count = commonService.archiveSchoolReports(1L, List.of(), "reportType");
count = commonService.archiveSchoolReports(1L, List.of(), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(1);

Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.deleteSchoolReports("reportTypeARC".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.archiveSchoolReports("reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(0);
count = commonService.archiveSchoolReports(1L, List.of(), "reportType");
count = commonService.archiveSchoolReports(1L, List.of(), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(0);
}

@Test
public void testArchiveSchoolReportsEmpty() {
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(0);
Mockito.when(schoolReportsRepository.archiveSchoolReports(new ArrayList<>(), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(0);
Integer count = commonService.archiveSchoolReports(1L, new ArrayList<>(), "reportType");
Integer count = commonService.archiveSchoolReports(1L, new ArrayList<>(), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(0);
}

@Test
public void testDeleteSchoolReports() {
Mockito.when(schoolReportsRepository.countBySchoolOfRecordsAndReportType(List.of("12345678"), "reportType".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.deleteSchoolReports(List.of("12345678"), "reportTypeARC".toUpperCase())).thenReturn(1);
Mockito.when(schoolReportsRepository.archiveSchoolReports(List.of("12345678"), "reportType".toUpperCase(), "reportTypeARC".toUpperCase(), 1L)).thenReturn(1);
Integer count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType");
Integer count = commonService.archiveSchoolReports(1L, List.of("12345678"), "reportType".toUpperCase());
assertThat(count).isNotNull().isEqualTo(1);
}

Expand Down

0 comments on commit a777986

Please sign in to comment.