Skip to content
Open
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 @@ -26,6 +26,7 @@
import com.swyp.picke.domain.vote.entity.BattleVote;
import com.swyp.picke.domain.vote.repository.BattleVoteRepository;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -75,10 +76,20 @@ class BattleVoteServiceImplTest {
@InjectMocks
private BattleVoteServiceImpl battleVoteService;

/**
* BattleVoteServiceImpl은 "였늘"을 KST둜 νŒλ‹¨ν•œλ‹€(LocalDate.now(KST)).
* ν…ŒμŠ€νŠΈκ°€ μ‹œμŠ€ν…œ κΈ°λ³Έ μ‹œκ°„λŒ€λ₯Ό μ“°λ©΄ UTC λŸ¬λ„ˆμ—μ„œ 15μ‹œ μ΄ν›„λ‘œ ν•˜λ£¨κ°€ μ–΄κΈ‹λ‚˜ μ‹€νŒ¨ν•œλ‹€.
*/
private static final ZoneId KST = ZoneId.of("Asia/Seoul");

private static LocalDate today() {
return LocalDate.now(KST);
}

@Test
@DisplayName("였늘 배틀이 μ•„λ‹ˆλ©΄ 졜초 사전 νˆ¬ν‘œ μ‹œ BATTLE_ENTRY ν¬λ ˆλ”§μ„ μ°¨κ°ν•œλ‹€")
void preVote_chargesBattleEntryCreditForPastBattle() {
Battle battle = battle(100L, LocalDate.now().minusDays(1));
Battle battle = battle(100L, today().minusDays(1));
User user = user(10L);
BattleOption option = option(201L, battle, BattleOptionLabel.A);

Expand All @@ -99,7 +110,7 @@ void preVote_chargesBattleEntryCreditForPastBattle() {
@Test
@DisplayName("였늘 배틀이면 졜초 사전 νˆ¬ν‘œ μ‹œ ν¬λ ˆλ”§μ„ μ°¨κ°ν•˜μ§€ μ•ŠλŠ”λ‹€")
void preVote_doesNotChargeBattleEntryCreditForTodayBattle() {
Battle battle = battle(100L, LocalDate.now());
Battle battle = battle(100L, today());
User user = user(10L);
BattleOption option = option(201L, battle, BattleOptionLabel.A);

Expand All @@ -119,15 +130,15 @@ void preVote_doesNotChargeBattleEntryCreditForTodayBattle() {
@Test
@DisplayName("였늘의 배틀이라도 였늘 이미 무료 μ§„μž…μ„ μ‚¬μš©ν–ˆλ‹€λ©΄ ν¬λ ˆλ”§μ„ μ°¨κ°ν•œλ‹€")
void preVote_chargesBattleEntryCreditWhenFreeEntryAlreadyUsedToday() {
Battle battle = battle(100L, LocalDate.now());
Battle battle = battle(100L, today());
User user = user(10L);
BattleOption option = option(201L, battle, BattleOptionLabel.A);

when(battleService.findById(100L)).thenReturn(battle);
when(userRepository.findById(10L)).thenReturn(Optional.of(user));
when(battleOptionRepository.findById(201L)).thenReturn(Optional.of(option));
when(battleVoteRepository.findByBattleAndUser(battle, user)).thenReturn(Optional.empty());
when(battleVoteRepository.existsByUserIdAndBattle_TargetDate(10L, LocalDate.now())).thenReturn(true);
when(battleVoteRepository.existsByUserIdAndBattle_TargetDate(10L, today())).thenReturn(true);
when(userBattleService.getUserBattleStatus(user, battle))
.thenReturn(new UserBattleStatusResponse(100L, UserBattleStep.NONE));

Expand All @@ -140,7 +151,7 @@ void preVote_chargesBattleEntryCreditWhenFreeEntryAlreadyUsedToday() {
@Test
@DisplayName("이미 사전 νˆ¬ν‘œν•œ 배틀이면 μ˜΅μ…˜ λ³€κ²½ μ‹œ μΆ”κ°€ μ°¨κ°ν•˜μ§€ μ•ŠλŠ”λ‹€")
void preVote_doesNotChargeAgainWhenVoteAlreadyExists() {
Battle battle = battle(100L, LocalDate.now().minusDays(1));
Battle battle = battle(100L, today().minusDays(1));
User user = user(10L);
BattleOption oldOption = option(200L, battle, BattleOptionLabel.B);
BattleOption newOption = option(201L, battle, BattleOptionLabel.A);
Expand Down
Loading