-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/test/java/com/nexters/goalpanzi/application/history/HistoryServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.nexters.goalpanzi.application.history; | ||
|
||
import com.nexters.goalpanzi.config.redis.RedisInitializer; | ||
import com.nexters.goalpanzi.domain.member.Member; | ||
import com.nexters.goalpanzi.domain.member.SocialType; | ||
import com.nexters.goalpanzi.domain.mission.Mission; | ||
import com.nexters.goalpanzi.domain.mission.MissionMember; | ||
import com.nexters.goalpanzi.domain.mission.MissionStatus; | ||
import com.nexters.goalpanzi.domain.mission.MissionVerification; | ||
import com.nexters.goalpanzi.domain.mission.repository.MissionMemberRepository; | ||
import com.nexters.goalpanzi.domain.mission.repository.MissionRepository; | ||
import com.nexters.goalpanzi.domain.mission.repository.MissionVerificationRepository; | ||
import com.nexters.goalpanzi.fixture.MemberFixture; | ||
import com.nexters.goalpanzi.fixture.MissionFixture; | ||
import com.nexters.goalpanzi.fixture.MissionVerificationFixture; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SpringBootTest | ||
@ContextConfiguration( | ||
initializers = {RedisInitializer.class} | ||
) | ||
class HistoryServiceTest { | ||
|
||
@Autowired | ||
private HistoryService historyService; | ||
|
||
@MockBean | ||
private MissionRepository missionRepository; | ||
|
||
@MockBean | ||
private MissionMemberRepository missionMemberRepository; | ||
|
||
@MockBean | ||
private MissionVerificationRepository missionVerificationRepository; | ||
|
||
@Test | ||
void 완료된_미션_기록을_조회한다() { | ||
// given | ||
Member member = Member.socialLogin("abc", "email", SocialType.GOOGLE); | ||
Mission mission = MissionFixture.create(); | ||
|
||
int VERIFICATION_COUNT = 1; | ||
Long COMPLETED_MISSION_COUNT = 1L; | ||
MissionMember missionMember = new MissionMember(member, mission, VERIFICATION_COUNT); | ||
MissionVerification missionVerification = MissionVerificationFixture.create(mission, member, MissionFixture.UPLOADED_IMAGE_URL, mission.getBoardCount()); | ||
ReflectionTestUtils.setField(mission, "id", 1L); | ||
ReflectionTestUtils.setField(member, "id", 1L); | ||
|
||
when(missionRepository.findAllById(any())).thenReturn(List.of(mission)); | ||
when(missionMemberRepository.findByMemberIdAndMissionStatus(any(), eq(MissionStatus.COMPLETED), any())).thenReturn(List.of(missionMember)); | ||
when(missionMemberRepository.countByMemberIdAndMissionStatus(any(), eq(MissionStatus.COMPLETED))).thenReturn(COMPLETED_MISSION_COUNT); | ||
when(missionVerificationRepository.findByMemberIdAndMissionIdIn(any(), any())).thenReturn(List.of(missionVerification)); | ||
|
||
// when | ||
var actual = historyService.getMissionHistories( | ||
MemberFixture.MEMBER_ID, | ||
PageRequest.ofSize(10) | ||
); | ||
|
||
// then | ||
assertAll( | ||
() -> assertThat(actual.totalCount()).isEqualTo(COMPLETED_MISSION_COUNT), | ||
() -> assertThat(actual.resultList()).hasSize(1), | ||
() -> assertThat(actual.resultList().getFirst().myVerificationCount()).isEqualTo(VERIFICATION_COUNT), | ||
() -> assertThat(actual.resultList().getFirst().totalVerificationCount()).isEqualTo(mission.getBoardCount()), | ||
() -> assertThat(actual.resultList().getFirst().rank()).isEqualTo(1)); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/com/nexters/goalpanzi/fixture/MissionVerificationFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.nexters.goalpanzi.fixture; | ||
|
||
import com.nexters.goalpanzi.domain.member.Member; | ||
import com.nexters.goalpanzi.domain.mission.Mission; | ||
import com.nexters.goalpanzi.domain.mission.MissionVerification; | ||
|
||
public class MissionVerificationFixture { | ||
public static MissionVerification create( | ||
Mission mission, | ||
Member member, | ||
String imageUrl, | ||
Integer boardCount | ||
) { | ||
return new MissionVerification( | ||
member, | ||
mission, | ||
imageUrl, | ||
boardCount | ||
); | ||
} | ||
} |