Skip to content

Commit

Permalink
chore(602): removing month name from trends response
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Feb 18, 2025
1 parent 1e99bdc commit 39975e7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
import ca.bc.gov.restapi.results.oracle.repository.OpeningRepository;
import ca.bc.gov.restapi.results.postgres.dto.OpeningsPerYearDto;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.IntStream;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -70,17 +67,11 @@ public List<OpeningsPerYearDto> getOpeningSubmissionTrends(
.map(yearMonth -> new OpeningsPerYearDto(
yearMonth.getMonthValue(),
yearMonth.getYear(),
getMonthName(yearMonth.getMonthValue()),
trendMap.getOrDefault(yearMonth, Collections.emptyMap())
.values().stream().mapToLong(Long::longValue).sum(),
trendMap.getOrDefault(yearMonth, Collections.emptyMap())
))
.toList();
}


private String getMonthName(int month) {
return Month.of(month).getDisplayName(TextStyle.SHORT, Locale.CANADA);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
public record OpeningsPerYearDto(
Integer month,
Integer year,
String monthName,
Long amount,
Map<String, Long> statusCounts
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Locale;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -92,9 +89,8 @@ void getOpeningsSubmissionTrends_happyPath_shouldSucceed() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$[12].month").value(LocalDate.now().getMonthValue()))
.andExpect(jsonPath("$[12].amount").value(1))
.andExpect(jsonPath("$[12].monthName").value(
Month.of(LocalDate.now().getMonthValue()).getDisplayName(TextStyle.SHORT, Locale.CANADA)));
.andExpect(jsonPath("$[12].amount").value(1));

}

@Test
Expand All @@ -120,9 +116,8 @@ void getOpeningsSubmissionTrends_withFilters_shouldSucceed() throws Exception {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$[12].month").value(LocalDate.now().getMonthValue()))
.andExpect(jsonPath("$[12].amount").value(1))
.andExpect(jsonPath("$[12].monthName").value(
Month.of(LocalDate.now().getMonthValue()).getDisplayName(TextStyle.SHORT, Locale.CANADA)));
.andExpect(jsonPath("$[12].amount").value(1));

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ void getOpeningSubmissionTrends_noFilters_shouldSucceed() {
Assertions.assertFalse(list.isEmpty());
Assertions.assertEquals(7, list.size());
Assertions.assertEquals(now.minusMonths(4).getMonthValue(), list.get(0).month());
Assertions.assertEquals(getMonthName(now.minusMonths(4).getMonth().getValue()), list.get(0).monthName());
Assertions.assertEquals(1, list.get(4).amount());
}

Expand All @@ -87,7 +86,6 @@ void getOpeningSubmissionTrends_orgUnitFilter_shouldSucceed() {
Assertions.assertFalse(list.isEmpty());
Assertions.assertEquals(3, list.size());
Assertions.assertEquals(now.minusMonths(1).getMonthValue(), list.get(0).month());
Assertions.assertEquals(getMonthName(now.minusMonths(1).getMonth().getValue()), list.get(0).monthName());
Assertions.assertEquals(1, list.get(1).amount());
}

Expand All @@ -105,12 +103,9 @@ void getOpeningSubmissionTrends_statusFilter_shouldSucceed() {
List.of("APP")
);

String monthName = getMonthName(now.getMonth().getValue());

Assertions.assertFalse(list.isEmpty());
Assertions.assertEquals(1, list.size());
Assertions.assertEquals(now.getMonthValue(), list.get(0).month());
Assertions.assertEquals(monthName, list.get(0).monthName());
Assertions.assertEquals(1, list.get(0).amount());
}

Expand Down Expand Up @@ -160,11 +155,9 @@ void getOpeningSubmissionTrends_datesFilter_shouldSucceed() {
null
);

String monthName = oneMonthBefore.getMonth().getDisplayName(TextStyle.SHORT, Locale.CANADA);
Assertions.assertFalse(list.isEmpty());
Assertions.assertEquals(3, list.size());
Assertions.assertEquals(oneMonthBefore.getMonthValue(), list.get(0).month());
Assertions.assertEquals(monthName, list.get(0).monthName());
Assertions.assertEquals(1, list.get(1).amount());
}

Expand All @@ -187,6 +180,7 @@ void getOpeningSubmissionTrends_noData_shouldSucceed() {
@Getter
@AllArgsConstructor
static class TestOpeningTrendsProjection implements OpeningTrendsProjection {

int year;
int month;
String status;
Expand Down

0 comments on commit 39975e7

Please sign in to comment.