Skip to content

Commit

Permalink
Deleted incorrect values in rating enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ospodaryk committed Sep 15, 2023
1 parent 301299b commit 5ac4865
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,32 +235,6 @@ public List<AchievementNotification> 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<AchievementNotification> setAchievementNotifications(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,27 +896,6 @@ public List<HabitsDateEnrollmentDto> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,34 +257,11 @@ 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(),
any(AchievementType.class),
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<HabitsDateEnrollmentDto> 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;
Expand Down

0 comments on commit 5ac4865

Please sign in to comment.