diff --git a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java index 568ce47..43abae5 100644 --- a/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java +++ b/src/main/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverter.java @@ -81,6 +81,7 @@ private long getCountOfEventsPerAdviceSeekerMatchingOnMetadata(String adviceSeek private long getCountOfEventsPerAdviceSeekerMatchingOnMetadataByReceiverId(String adviceSeekerId, Collection createMessageEvents) { return createMessageEvents.stream() + .filter(event -> event.getMetaData() instanceof CreateMessageMetaData) .filter(event -> { CreateMessageMetaData metaData = (CreateMessageMetaData) event.getMetaData(); return metaData.getReceiverId() != null && metaData.getReceiverId() diff --git a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java index 936587a..0774200 100644 --- a/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java +++ b/src/test/java/de/caritas/cob/statisticsservice/api/helper/RegistrationStatisticsDTOConverterTest.java @@ -52,7 +52,8 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { givenValidStatisticEvent(1L); // when - RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, new StatisticEventsContainer()); + RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( + testEvent, new StatisticEventsContainer()); // then assertThat(result.getUserId(), is(ASKER_ID)); @@ -76,11 +77,11 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse() { } @Test - void convertStatisticsEvent_Should_convertToRegistrationStatisticResponseWithoutErrorIfMetadataIsLinkedHashMap() { + void convertStatisticsEvent_Should_convertToRegistrationStatisticResponse_SkipCounting() { // given givenValidStatisticEvent(1L); - var videoCallStartedEvent = StatisticsEvent.builder() + var eventWithInvalidMetadataType = StatisticsEvent.builder() .sessionId(1L) .eventType(EventType.REGISTRATION) .user(User.builder().userRole(UserRole.ASKER).id(ASKER_ID).build()) @@ -90,9 +91,13 @@ void convertStatisticsEvent_Should_convertToRegistrationStatisticResponseWithout .metaData(new LinkedHashMap<>()) .build(); - var statisticEventsContainer = StatisticEventsContainer.builder().videoCallStartedEvents(Lists.newArrayList(videoCallStartedEvent)).build(); + var statisticEventsContainer = StatisticEventsContainer.builder() + .videoCallStartedEvents(Lists.newArrayList(eventWithInvalidMetadataType)) + .bookingCreatedEvents(Lists.newArrayList(eventWithInvalidMetadataType)) + .consultantMessageCreatedEvents(Lists.newArrayList(eventWithInvalidMetadataType)).build(); // when - RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent(testEvent, statisticEventsContainer); + RegistrationStatisticsResponseDTO result = registrationStatisticsDTOConverter.convertStatisticsEvent( + testEvent, statisticEventsContainer); // then assertThat(result.getUserId(), is(ASKER_ID)); @@ -220,13 +225,15 @@ private void givenValidStatisticEvent(Long sessionId) { } private void givenAccountDeleteStatisticEvents() { - deleteAccountEvents = List.of(deleteEvent(ASKER_ID, "2022-10-19T10:00:00.00Z", "delete date for user 1"), + deleteAccountEvents = List.of( + deleteEvent(ASKER_ID, "2022-10-19T10:00:00.00Z", "delete date for user 1"), deleteEvent("user 2", "2022-10-17T10:00:00.00Z", "delete date for user 2")); } private void givenValidArchiveStatisticEvents() { - archiveSessionEvents = List.of(archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"), + archiveSessionEvents = List.of( + archiveEvent(1L, "2022-10-17T10:00:00.00Z", "1 end date for session 1"), archiveEvent(1L, "2022-10-18T10:00:00.00Z", "2 end date for session 1"), archiveEvent(2L, "2022-10-18T10:00:00.00Z", "end date for session 2"), archiveEvent(999L, "2022-10-19T10:00:00.00Z", "dummy end date")); @@ -234,13 +241,15 @@ private void givenValidArchiveStatisticEvents() { private StatisticsEvent archiveEvent(Long sessionId, String timestampString, String endDate) { Object metaData = ArchiveMetaData.builder().endDate(endDate).build(); - return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).sessionId(sessionId).metaData(metaData).build(); + return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).sessionId(sessionId) + .metaData(metaData).build(); } private StatisticsEvent deleteEvent(String userId, String timestampString, String deleteDate) { Object metaData = DeleteAccountMetaData.builder().deleteDate(deleteDate).build(); User user = new User(); user.setId(userId); - return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).user(user).metaData(metaData).build(); + return StatisticsEvent.builder().timestamp(Instant.parse(timestampString)).user(user) + .metaData(metaData).build(); } }