From 5ac48650b88acc8a870beed9a7a70a2301748958 Mon Sep 17 00:00:00 2001 From: ospodaryk Date: Fri, 15 Sep 2023 10:14:07 +0300 Subject: [PATCH] Deleted incorrect values in rating enum --- .../enums/RatingCalculationEnum.java | 38 ++---------------- .../enums/RatingCalculationEnumTest.java | 8 ++-- .../service/AchievementServiceImpl.java | 26 ------------- .../service/HabitAssignServiceImpl.java | 21 ---------- .../service/AchievementServiceImplTest.java | 23 ----------- .../service/HabitAssignServiceImplTest.java | 39 ------------------- 6 files changed, 7 insertions(+), 148 deletions(-) diff --git a/service-api/src/main/java/greencity/enums/RatingCalculationEnum.java b/service-api/src/main/java/greencity/enums/RatingCalculationEnum.java index 265c359b6e..a12b43605c 100644 --- a/service-api/src/main/java/greencity/enums/RatingCalculationEnum.java +++ b/service-api/src/main/java/greencity/enums/RatingCalculationEnum.java @@ -4,57 +4,25 @@ @Getter public enum RatingCalculationEnum { - ACQUIRED_HABIT_14_DAYS(20), - - ACQUIRED_HABIT_21_DAYS(30), - - ACQUIRED_HABIT_30_PLUS_DAYS(40), - - DAYS_OF_HABIT_IN_PROGRESS(1), // 1 point per 1 day + DAYS_OF_HABIT_IN_PROGRESS(1), CREATE_NEWS(20), - ADDED_TIPS_AND_TRICKS(10), - COMMENT_OR_REPLY(2), LIKE_COMMENT_OR_REPLY(10), - SHARE_NEWS_OR_TIPS_AND_TRICKS(20), - - FIRST_5_ACHIEVEMENTS(20), - - FIRST_10_ACHIEVEMENTS(30), - - FIRST_15_ACHIEVEMENTS(40), - - FIRST_20_ACHIEVEMENTS(50), - - UNDO_ACQUIRED_HABIT_14_DAYS(-20), - - UNDO_ACQUIRED_HABIT_21_DAYS(-30), - - UNDO_ACQUIRED_HABIT_30_PLUS_DAYS(-40), + SHARE_NEWS(20), UNDO_DAYS_OF_HABIT_IN_PROGRESS(-1), DELETE_NEWS(-20), - DELETE_TIPS_AND_TRICKS(-10), - DELETE_COMMENT_OR_REPLY(-2), UNLIKE_COMMENT_OR_REPLY(-10), - UNDO_SHARE_NEWS_OR_TIPS_AND_TRICKS(-20), - - UNDO_FIRST_5_ACHIEVEMENTS(-20), - - UNDO_FIRST_10_ACHIEVEMENTS(-30), - - UNDO_FIRST_15_ACHIEVEMENTS(-40), - - UNDO_FIRST_20_ACHIEVEMENTS(-50); + UNDO_SHARE_NEWS(-20); private final long ratingPoints; diff --git a/service-api/src/test/java/greencity/enums/RatingCalculationEnumTest.java b/service-api/src/test/java/greencity/enums/RatingCalculationEnumTest.java index 5393e7be7b..795fd521d9 100644 --- a/service-api/src/test/java/greencity/enums/RatingCalculationEnumTest.java +++ b/service-api/src/test/java/greencity/enums/RatingCalculationEnumTest.java @@ -7,13 +7,13 @@ public class RatingCalculationEnumTest { @Test public void testEnumValues() { - assertEquals(20, RatingCalculationEnum.ACQUIRED_HABIT_14_DAYS.getRatingPoints()); - assertEquals(30, RatingCalculationEnum.ACQUIRED_HABIT_21_DAYS.getRatingPoints()); - assertEquals(40, RatingCalculationEnum.ACQUIRED_HABIT_30_PLUS_DAYS.getRatingPoints()); + assertEquals(20, RatingCalculationEnum.CREATE_NEWS.getRatingPoints()); + assertEquals(2, RatingCalculationEnum.COMMENT_OR_REPLY.getRatingPoints()); + assertEquals(10, RatingCalculationEnum.LIKE_COMMENT_OR_REPLY.getRatingPoints()); } @Test public void testEnumSize() { - assertEquals(26, RatingCalculationEnum.values().length); + assertEquals(10, RatingCalculationEnum.values().length); } } diff --git a/service/src/main/java/greencity/service/AchievementServiceImpl.java b/service/src/main/java/greencity/service/AchievementServiceImpl.java index bc1f72ba64..53bdab5fa7 100644 --- a/service/src/main/java/greencity/service/AchievementServiceImpl.java +++ b/service/src/main/java/greencity/service/AchievementServiceImpl.java @@ -235,32 +235,6 @@ public List findAchievementsWithStatusActive(Long userI public void calculateAchievements(Long id, AchievementType achievementType, AchievementCategoryType achievementCategory, Integer size) { achievementCalculation.calculateAchievement(id, achievementType, achievementCategory, size); - UserVO userVO = userService.findById(id); - String accessToken = httpServletRequest.getHeader(AUTHORIZATION); - - switch (size) { - case 5: - CompletableFuture.runAsync( - () -> ratingCalculation.ratingCalculation(RatingCalculationEnum.FIRST_5_ACHIEVEMENTS, userVO, - accessToken)); - break; - case 10: - CompletableFuture.runAsync( - () -> ratingCalculation.ratingCalculation(RatingCalculationEnum.FIRST_10_ACHIEVEMENTS, userVO, - accessToken)); - break; - case 15: - CompletableFuture.runAsync( - () -> ratingCalculation.ratingCalculation(RatingCalculationEnum.FIRST_15_ACHIEVEMENTS, userVO, - accessToken)); - break; - case 20: - CompletableFuture.runAsync( - () -> ratingCalculation.ratingCalculation(RatingCalculationEnum.FIRST_20_ACHIEVEMENTS, userVO, - accessToken)); - break; - default: - } } private List setAchievementNotifications( diff --git a/service/src/main/java/greencity/service/HabitAssignServiceImpl.java b/service/src/main/java/greencity/service/HabitAssignServiceImpl.java index 9141a51b80..8704d26079 100644 --- a/service/src/main/java/greencity/service/HabitAssignServiceImpl.java +++ b/service/src/main/java/greencity/service/HabitAssignServiceImpl.java @@ -896,27 +896,6 @@ public List findHabitAssignsBetweenDates(Long userId, L String accessToken = httpServletRequest.getHeader(AUTHORIZATION); habitAssignsBetweenDates.forEach(habitAssign -> buildHabitsDateEnrollmentDto(habitAssign, language, dtos)); - UserVO userVO = userService.findById(userId); - int dateSize = dates.size(); - switch (dateSize) { - case 14: - CompletableFuture.runAsync( - () -> ratingCalculation.ratingCalculation(RatingCalculationEnum.ACQUIRED_HABIT_14_DAYS, userVO, - accessToken)); - break; - case 21: - CompletableFuture.runAsync( - () -> ratingCalculation.ratingCalculation(RatingCalculationEnum.ACQUIRED_HABIT_21_DAYS, userVO, - accessToken)); - break; - case 30: - CompletableFuture.runAsync( - () -> ratingCalculation.ratingCalculation(RatingCalculationEnum.ACQUIRED_HABIT_30_PLUS_DAYS, userVO, - accessToken)); - break; - default: - } - return dtos; } diff --git a/service/src/test/java/greencity/service/AchievementServiceImplTest.java b/service/src/test/java/greencity/service/AchievementServiceImplTest.java index 7bc5e34166..98493f1f08 100644 --- a/service/src/test/java/greencity/service/AchievementServiceImplTest.java +++ b/service/src/test/java/greencity/service/AchievementServiceImplTest.java @@ -257,11 +257,6 @@ void findAchievementsWithStatusActive() { @Test void calculateAchievement() { - when(userService.findById(any())).thenReturn(ModelUtils.getUserVO()); - - String accessToken = "Token"; - when(httpServletRequest.getHeader("Authorization")).thenReturn(accessToken); - achievementService.calculateAchievements(1L, AchievementType.INCREMENT, AchievementCategoryType.ECO_NEWS, 1); verify(achievementCalculation).calculateAchievement( anyLong(), @@ -269,22 +264,4 @@ void calculateAchievement() { any(AchievementCategoryType.class), anyInt()); } - - @ParameterizedTest - @ValueSource(ints = {5, 10, 15, 20}) - void calculateAchievement(int incrementValue) { - when(userService.findById(any())).thenReturn(ModelUtils.getUserVO()); - - String accessToken = "Token"; - when(httpServletRequest.getHeader("Authorization")).thenReturn(accessToken); - - achievementService.calculateAchievements(1L, AchievementType.INCREMENT, AchievementCategoryType.ECO_NEWS, - incrementValue); - - verify(achievementCalculation).calculateAchievement( - anyLong(), - any(AchievementType.class), - any(AchievementCategoryType.class), - eq(incrementValue)); - } } diff --git a/service/src/test/java/greencity/service/HabitAssignServiceImplTest.java b/service/src/test/java/greencity/service/HabitAssignServiceImplTest.java index 86383c260e..28d7edab79 100644 --- a/service/src/test/java/greencity/service/HabitAssignServiceImplTest.java +++ b/service/src/test/java/greencity/service/HabitAssignServiceImplTest.java @@ -413,55 +413,16 @@ void findHabitAssignsBetweenDates() { new HabitEnrollDto(1L, "", "", false), new HabitEnrollDto(2L, "", "", false))) .build()); - when(userService.findById(any())).thenReturn(userVO); when(habitAssignRepo.findAllHabitAssignsBetweenDates(anyLong(), eq(LocalDate.of(2020, 12, 27)), eq(LocalDate.of(2020, 12, 29)))) .thenReturn(habitAssignList); - String accessToken = "Token"; - when(httpServletRequest.getHeader("Authorization")).thenReturn(accessToken); assertEquals(dtos, habitAssignService.findHabitAssignsBetweenDates(13L, LocalDate.of(2020, 12, 27), LocalDate.of(2020, 12, 29), "en")); } - @ParameterizedTest - @ValueSource(ints = {14, 21, 30}) - void findHabitAssignsBetweenDates(int num) { - HabitAssign habit1 = ModelUtils.getHabitAssign(); - HabitAssign habit2 = ModelUtils.getHabitAssign(); - habit2.setId(2L); - habit2.getHabit().setId(2L); - habit1.setDuration(3); - habit2.setDuration(3); - ZonedDateTime creation = ZonedDateTime.of(2020, 12, 1, - 12, 12, 12, 12, ZoneId.of("Europe/Kiev")); - habit1.setCreateDate(creation); - habit2.setCreateDate(creation); - habit1.setHabitStatusCalendars(Collections.singletonList(HabitStatusCalendar - .builder().enrollDate(LocalDate.of(2020, 12, 1)).build())); - habit2.setHabitStatusCalendars(Collections.emptyList()); - - List dtos = new ArrayList<>(); - for (int i = 1; i <= num; i++) { - dtos.add(HabitsDateEnrollmentDto.builder().enrollDate(LocalDate.of(2020, 12, i)) - .habitAssigns(Collections.emptyList()).build()); - } - - when(userService.findById(any())).thenReturn(userVO); - - when(habitAssignRepo.findAllHabitAssignsBetweenDates(anyLong(), - eq(LocalDate.of(2020, 12, 1)), eq(LocalDate.of(2020, 12, num)))) - .thenReturn(Collections.emptyList()); - String accessToken = "Token"; - when(httpServletRequest.getHeader("Authorization")).thenReturn(accessToken); - - assertEquals(dtos, habitAssignService.findHabitAssignsBetweenDates(13L, - LocalDate.of(2020, 12, 1), LocalDate.of(2020, 12, num), - "en")); - } - @Test void findHabitAssignsBetweenDatesThrowsBadRequestExceptionWhenFromDateIsLaterThenTo() { Long userId = 2L;