Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public RewardResponse claimReward(RewardClaimCommand command) {
Egg grantedEgg = rewardEgg(command);
Long grantedLoveAmount = loveGrantService.grantLoveToUserWithDistance(runningRecord);
runningRecord.reward(command.userId());
return new RewardResponse(!grantedEgg.isEmpty(), grantedEgg.getItemCode(),
grantedEgg.getEggType().getName(),
grantedLoveAmount);
return RewardResponse.of(grantedEgg, grantedLoveAmount);
}

private Egg rewardEgg(RewardClaimCommand command) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package org.runimo.runimo.rewards.service.dto;


import org.runimo.runimo.item.domain.Egg;

public record RewardResponse(
Boolean isRewarded,
String eggCode,
String eggType,
String eggImgUrl,
Long lovePointAmount
) {

public static RewardResponse of(Egg egg, Long lovePointAmount) {
return new RewardResponse(
egg != Egg.EMPTY,
egg.getItemCode(),
egg.getEggType().getName(),
egg.getImgUrl(),
lovePointAmount
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.RequiredArgsConstructor;
import org.runimo.runimo.common.scale.Distance;
import org.runimo.runimo.records.domain.RunningRecord;
import org.runimo.runimo.user.domain.LovePoint;
import org.runimo.runimo.user.domain.User;
import org.runimo.runimo.user.service.LovePointProcessor;
import org.runimo.runimo.user.service.UserFinder;
Expand All @@ -23,8 +22,8 @@ public Long grantLoveToUserWithDistance(RunningRecord runningRecord) {
User user = userFinder.findUserById(runningRecord.getUserId())
.orElseThrow(IllegalStateException::new);
Long loveAmount = calculateLoveAmount(runningRecord.getTotalDistance());
LovePoint lovePoint = lovePointProcessor.acquireLovePoint(user.getId(), loveAmount);
return lovePoint.getAmount();
lovePointProcessor.acquireLovePoint(user.getId(), loveAmount);
return loveAmount;
}

private Long calculateLoveAmount(Distance distance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ void tearDown() {
.log().all()
.statusCode(HttpStatus.OK.value())
.body("payload.love_point_amount", notNullValue())
.body("payload.love_point_amount", greaterThan(0));
.body("payload.love_point_amount", greaterThan(0))
Copy link

Copilot AI May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The assertion that payload.love_point_amount is greater than 0 is redundant when you assert it equals 5 immediately after. Consider removing the redundant check to keep the test concise.

Suggested change
.body("payload.love_point_amount", greaterThan(0))

Copilot uses AI. Check for mistakes.
.body("payload.love_point_amount", equalTo(5))
.body("payload.egg_img_url", notNullValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.runimo.runimo.rewards.service.lovepoint;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import java.time.LocalDateTime;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.runimo.runimo.common.scale.Distance;
import org.runimo.runimo.records.domain.RunningRecord;
import org.runimo.runimo.user.UserFixtures;
import org.runimo.runimo.user.service.LovePointProcessor;
import org.runimo.runimo.user.service.UserFinder;

class LoveGrantServiceTest {


@InjectMocks
private LoveGrantService loveGrantService;
@Mock
private UserFinder userFinder;
@Mock
private LovePointProcessor lovePointProcessor;

@BeforeEach
void setup() {
initMocks(this);
}

@Test
void km_당_1포인트를_지급한다() {

RunningRecord record = RunningRecord.builder()
.isRewarded(false)
.startedAt(LocalDateTime.of(2020, 1, 1, 12, 0, 0))
.endAt(LocalDateTime.of(2020, 1, 1, 12, 30, 0))
.totalDistance(new Distance(7800L))
.build();

when(userFinder.findUserById(any())).thenReturn(
Optional.ofNullable(UserFixtures.getUserWithId(1L)));
Long amount = loveGrantService.grantLoveToUserWithDistance(record);

assertEquals(7L, amount);
}

@Test
void 달린거리_1km보다_작으면_지급하지_않는다() {
RunningRecord record = RunningRecord.builder()
.isRewarded(false)
.startedAt(LocalDateTime.of(2020, 1, 1, 12, 0, 0))
.endAt(LocalDateTime.of(2020, 1, 1, 12, 30, 0))
.totalDistance(new Distance(900L))
.build();

when(userFinder.findUserById(any())).thenReturn(
Optional.ofNullable(UserFixtures.getUserWithId(1L)));
Long amount = loveGrantService.grantLoveToUserWithDistance(record);

assertEquals(0L, amount);
}

}