diff --git a/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchPollServiceTest.java b/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchPollServiceTest.java index e1700a279..985f1e497 100644 --- a/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchPollServiceTest.java +++ b/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchPollServiceTest.java @@ -11,6 +11,8 @@ import com.ssafy.ssafsound.domain.member.exception.MemberErrorInfo; import com.ssafy.ssafsound.domain.member.exception.MemberException; import com.ssafy.ssafsound.domain.member.repository.MemberRepository; +import com.ssafy.ssafsound.domain.meta.domain.Campus; +import com.ssafy.ssafsound.domain.meta.domain.MetaData; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -50,6 +52,7 @@ class LunchPollServiceTest { @InjectMocks private LunchPollService lunchPollService; + private MetaData SEOUL; private Lunch lunch1; private Lunch lunch2; private Lunch lunch3; @@ -66,18 +69,23 @@ class LunchPollServiceTest { @BeforeEach void setUp() { + SEOUL = new MetaData(Campus.SEOUL); + lunch1 = Lunch.builder() .id(1L) + .campus(SEOUL) .createdAt(today) .build(); lunch2 = Lunch.builder() .id(2L) + .campus(SEOUL) .createdAt(today) .build(); lunch3 = Lunch.builder() .id(3L) + .campus(SEOUL) .createdAt(today.plusDays(1)) .build(); @@ -118,8 +126,8 @@ void Given_MemberIdAndLunchId_When_SaveLunchPoll_Then_Succeed(Long memberId, Lon Integer expectedLunch2PollCount) { // given - lenient().when(lunchPollRepository.findByMemberAndPolledAt(member1, today)).thenReturn(lunchPoll); - lenient().when(lunchPollRepository.findByMemberAndPolledAt(member2, today)).thenReturn(null); + lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member1, SEOUL, today)).thenReturn(lunchPoll); + lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member2, SEOUL, today)).thenReturn(null); // when PostLunchPollResDto postLunchPollResDto = lunchPollService.saveLunchPoll(memberId, lunchId); @@ -167,13 +175,13 @@ void Given_AlreadyPolledLunchId_When_SaveLunchPoll_Then_ThrowException() { // given Long memberId = 1L; Long lunchId = 2L; - given(lunchPollRepository.findByMemberAndPolledAt(member1, today)).willReturn(lunchPoll); + given(lunchPollRepository.findByMemberAndCampusAndPolledAt(member1, SEOUL, today)).willReturn(lunchPoll); // when, then LunchException exception = assertThrows(LunchException.class, () -> lunchPollService.saveLunchPoll(memberId, lunchId)); assertEquals(LunchErrorInfo.DUPLICATE_LUNCH_POLL, exception.getInfo()); - verify(lunchPollRepository).findByMemberAndPolledAt(member1, today); + verify(lunchPollRepository).findByMemberAndCampusAndPolledAt(member1, SEOUL, today); } @Test diff --git a/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchServiceTest.java b/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchServiceTest.java index db7438916..3f029408a 100644 --- a/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchServiceTest.java +++ b/src/test/java/com/ssafy/ssafsound/domain/lunch/service/LunchServiceTest.java @@ -5,8 +5,6 @@ import com.ssafy.ssafsound.domain.lunch.dto.GetLunchListElementResDto; import com.ssafy.ssafsound.domain.lunch.dto.GetLunchListReqDto; import com.ssafy.ssafsound.domain.lunch.dto.GetLunchListResDto; -import com.ssafy.ssafsound.domain.lunch.exception.LunchErrorInfo; -import com.ssafy.ssafsound.domain.lunch.exception.LunchException; import com.ssafy.ssafsound.domain.lunch.repository.LunchPollRepository; import com.ssafy.ssafsound.domain.lunch.repository.LunchRepository; import com.ssafy.ssafsound.domain.member.domain.Member; @@ -36,8 +34,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.lenient; @@ -112,9 +108,9 @@ void setUp() { lenient().when(memberRepository.findById(1L)).thenReturn(Optional.of(member1)); lenient().when(memberRepository.findById(2L)).thenReturn(Optional.of(member2)); - lenient().when(lunchPollRepository.findByMemberAndPolledAt(member1, today)) + lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member1, testCampus, today)) .thenReturn(lunchPoll); - lenient().when(lunchPollRepository.findByMemberAndPolledAt(member2, today)) + lenient().when(lunchPollRepository.findByMemberAndCampusAndPolledAt(member2, testCampus, today)) .thenReturn(null); } @@ -132,7 +128,7 @@ void Given_DateAndCampus_When_FindLunches_Then_Succeed( given(clock.getZone()).willReturn(ZoneId.of("Asia/Seoul")); given(metaDataConsumer.getMetaData(MetaDataType.CAMPUS.name(), inputCampus)) - .willReturn(new MetaData(Campus.SEOUL)); + .willReturn(testCampus); given(lunchRepository.findAllByCampusAndDate( metaDataConsumer.getMetaData(MetaDataType.CAMPUS.name(), inputCampus), inputDate))