Skip to content

Commit

Permalink
test: ParticipationService 테스트코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
songhaechan committed Nov 1, 2024
1 parent 0f2e62a commit 0d95ef4
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 64 deletions.
49 changes: 15 additions & 34 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ <h4 id="_그룹_등록_http_request"><a class="link" href="#_그룹_등록_http_
"name" : "AmorGakCo",
"description" : "모각코 합시다.",
"groupCapacity" : 4,
"beginAt" : "2024-10-31T22:04:06.134279",
"endAt" : "2024-11-01T01:04:06.134279",
"beginAt" : "2024-11-01T19:14:10.035867",
"endAt" : "2024-11-01T22:14:10.035867",
"latitude" : 37.5703901,
"longitude" : 126.9748397,
"address" : "서울특별시 종로구 신문로1가 23"
Expand Down Expand Up @@ -686,8 +686,8 @@ <h4 id="_그룹_단건_조회_상세페이지용_http_response"><a class="link"
"address" : "서울특별시 종로구 신문로1가 23",
"longitude" : 126.9748397,
"latitude" : 37.5703901,
"beginAt" : "2024-10-31T22:04:06.043143",
"endAt" : "2024-11-01T01:04:06.043148",
"beginAt" : "2024-11-01T19:14:09.910027",
"endAt" : "2024-11-01T22:14:09.910031",
"groupMembers" : [ {
"memberId" : 2,
"imgUrl" : "https://fakeimg",
Expand Down Expand Up @@ -914,7 +914,7 @@ <h4 id="_참여자의_모각코_참여_내역_query_parameters"><a class="link"
<h4 id="_참여자의_모각코_참여_내역_http_request"><a class="link" href="#_참여자의_모각코_참여_내역_http_request">HTTP request</a></h4>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">GET /participants/histories?page=0 HTTP/1.1
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">GET /participants/current-history?page=0 HTTP/1.1
Host: localhost:8080</code></pre>
</div>
</div>
Expand All @@ -928,52 +928,33 @@ <h4 id="_참여자의_모각코_참여_내역_http_response"><a class="link" hre
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json;charset=UTF-8
Content-Length: 1489
Content-Length: 813

{
"status" : "success",
"path" : "/participants/histories",
"path" : "/participants/current-history",
"data" : {
"page" : 0,
"elementSize" : 6,
"elementSize" : 3,
"hasNext" : false,
"activatedGroup" : [ {
"histories" : [ {
"groupId" : 4,
"name" : "AmorGakCo",
"address" : "서울특별시 종로구 신문로1가 23",
"beginAt" : "2024-10-31T22:04:11.825341",
"endAt" : "2024-11-01T01:04:11.825346"
"beginAt" : "2024-11-01T19:14:18.221664",
"endAt" : "2024-11-01T22:14:18.22167"
}, {
"groupId" : 5,
"name" : "AmorGakCo",
"address" : "서울특별시 종로구 신문로1가 23",
"beginAt" : "2024-10-31T22:04:11.825341",
"endAt" : "2024-11-01T01:04:11.825346"
"beginAt" : "2024-11-01T19:14:18.221664",
"endAt" : "2024-11-01T22:14:18.22167"
}, {
"groupId" : 6,
"name" : "AmorGakCo",
"address" : "서울특별시 종로구 신문로1가 23",
"beginAt" : "2024-10-31T22:04:11.825341",
"endAt" : "2024-11-01T01:04:11.825346"
} ],
"InactivatedGroup" : [ {
"groupId" : 1,
"name" : "AmorGakCo",
"address" : "서울특별시 종로구 신문로1가 23",
"beginAt" : "2024-10-31T22:04:11.825341",
"endAt" : "2024-11-01T01:04:11.825346"
}, {
"groupId" : 2,
"name" : "AmorGakCo",
"address" : "서울특별시 종로구 신문로1가 23",
"beginAt" : "2024-10-31T22:04:11.825341",
"endAt" : "2024-11-01T01:04:11.825346"
}, {
"groupId" : 3,
"name" : "AmorGakCo",
"address" : "서울특별시 종로구 신문로1가 23",
"beginAt" : "2024-10-31T22:04:11.825341",
"endAt" : "2024-11-01T01:04:11.825346"
"beginAt" : "2024-11-01T19:14:18.221664",
"endAt" : "2024-11-01T22:14:18.22167"
} ]
}
}</code></pre>
Expand Down
2 changes: 2 additions & 0 deletions main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ jacocoTestReport {
"com/amorgakco/backend/global/response/**",
"com/amorgakco/backend/global/properties/**",
"com/amorgakco/backend/global/rabbitmq/**",
"com/amorgakco/backend/oauth2/provider/**",
"com/amorgakco/backend/oauth2/service/**",
])
}))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public void verifyLocation(
participantService.verifyParticipantLocation(request, memberId);
}

@GetMapping("/active-history")
@GetMapping("/current-history")
public ParticipationHistoryPagingResponse getCurrentParticipationHistory
(@RequestParam final Integer page, @AuthMemberId final Long memberId) {
return participantService.getCurrentParticipationHistories(memberId, page);
}

@GetMapping("/inactive-history")
@GetMapping("/past-history")
public ParticipationHistoryPagingResponse getPastParticipationHistory
(@RequestParam final Integer page, @AuthMemberId final Long memberId) {
return participantService.getPastParticipationHistories(memberId, page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class TestGroupFactory {
private static final LocalDateTime BEGIN_AT = LocalDateTime.now();
private static final LocalDateTime END_AT = LocalDateTime.now().plusHours(3);

public static Group create(final Member host) {
public static Group createActiveGroup(final Member host) {
return Group.builder()
.host(host)
.groupCapacity(GROUP_CAPACITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class TestGroupParticipationFactory {

public static GroupApplication create(final Member host, final Long memberId) {
final Member member = TestMemberFactory.create(memberId);
final Group group = TestGroupFactory.create(host);
final Group group = TestGroupFactory.createActiveGroup(host);
return GroupApplication.builder().group(group).member(member).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,32 @@ public class TestParticipantFactory {
private static final LocalDateTime BEGIN_AT = LocalDateTime.now();
private static final LocalDateTime END_AT = LocalDateTime.now().plusHours(3);

public static ParticipationHistoryPagingResponse participationHistoryResponse() {
public static ParticipationHistoryPagingResponse currentParticipationHistoryResponse() {
List<ParticipationHistory> currentGroups = currentGroups();
return ParticipationHistoryPagingResponse.builder()
.page(0)
.hasNext(false)
.elementSize(inactivatedGroups().size() + activatedGroups().size())
.InactivatedGroup(inactivatedGroups())
.activatedGroup(activatedGroups())
.elementSize(currentGroups.size())
.histories(currentGroups)
.build();
}

private static List<ParticipationHistory> inactivatedGroups() {
public static ParticipationHistoryPagingResponse pastParticipationHistoryResponse() {
List<ParticipationHistory> pastGroups = pastGroups();
return ParticipationHistoryPagingResponse.builder()
.page(0)
.hasNext(false)
.elementSize(pastGroups.size())
.histories(pastGroups)
.build();
}

private static List<ParticipationHistory> currentGroups() {
return List.of(
participationHistory(1L), participationHistory(2L), participationHistory(3L));
}

private static List<ParticipationHistory> activatedGroups() {
private static List<ParticipationHistory> pastGroups() {
return List.of(
participationHistory(4L), participationHistory(5L), participationHistory(6L));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.amorgakco.backend.fixture.member.TestMemberFactory;
import com.amorgakco.backend.global.exception.DuplicatedRequestException;
import com.amorgakco.backend.global.exception.ErrorCode;
import com.amorgakco.backend.global.exception.GroupAuthorityException;
import com.amorgakco.backend.global.exception.LocationVerificationException;
import com.amorgakco.backend.global.exception.ParticipantException;
import com.amorgakco.backend.member.domain.Member;
import com.amorgakco.backend.participant.domain.Participant;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -23,7 +21,7 @@ class GroupTest {
void getCurrentGroupSize() {
// given
final Member host = TestMemberFactory.create(1L);
final Group group = TestGroupFactory.create(host);
final Group group = TestGroupFactory.createActiveGroup(host);
final Member member = TestMemberFactory.create(2L);
final int expectGroupSize = 2;
final Participant participant = TestParticipantsFactory.create(member);
Expand All @@ -39,7 +37,7 @@ void getCurrentGroupSize() {
void duplicateParticipation() {
// given
final Member host = TestMemberFactory.create(1L);
final Group group = TestGroupFactory.create(host);
final Group group = TestGroupFactory.createActiveGroup(host);
final Participant participant = new Participant(TestMemberFactory.create(2L));
group.addParticipants(participant);
final Participant newParticipant = new Participant(TestMemberFactory.create(2L));
Expand All @@ -54,7 +52,7 @@ void duplicateParticipation() {
void validateLocationException() {
// given
final Member host = TestMemberFactory.create(1L);
final Group group = TestGroupFactory.create(host);
final Group group = TestGroupFactory.createActiveGroup(host);
final Member member = TestMemberFactory.create(2L);
final Participant participant = TestParticipantsFactory.create(member);
group.addParticipants(participant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void register() {
void deleteGroup() {
// given
final Member host = TestMemberFactory.createEntity();
final Group group = TestGroupFactory.create(host);
final Group group = TestGroupFactory.createActiveGroup(host);
memberRepository.save(host);
groupRepository.save(group);
// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void requestParticipation() {
Member requestMember = TestMemberFactory.createEntity();
memberRepository.save(host);
memberRepository.save(requestMember);
Group group = TestGroupFactory.create(host);
Group group = TestGroupFactory.createActiveGroup(host);
groupRepository.save(group);
// when
doNothing().when(notificationPublisherFacade).send(any(NotificationRequest.class));
Expand All @@ -63,7 +63,7 @@ void approveParticipation() {
// given
Member host = TestMemberFactory.createEntity();
Member member = TestMemberFactory.createEntity();
Group group = TestGroupFactory.create(host);
Group group = TestGroupFactory.createActiveGroup(host);
memberRepository.save(host);
memberRepository.save(member);
groupRepository.save(group);
Expand All @@ -81,7 +81,7 @@ void rejectParticipation() {
// given
Member host = TestMemberFactory.createEntity();
Member member = TestMemberFactory.createEntity();
Group group = TestGroupFactory.create(host);
Group group = TestGroupFactory.createActiveGroup(host);
memberRepository.save(host);
memberRepository.save(member);
groupRepository.save(group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,45 @@ class ParticipantControllerTest extends RestDocsTest {
private ParticipantService participantService;

@Test
@DisplayName("회원의 그룹 참여 내역을 조회할 수 있다.")
@DisplayName("회원의 현재 참여중인 내역을 조회할 수 있다.")
@WithMockMember
void memberParticipationHistory() throws Exception {
void memberCurrentParticipationHistory() throws Exception {
// given
final Long memberId = 1L;
final Integer page = 0;
final ParticipationHistoryPagingResponse participationHistoryPagingResponse =
TestParticipantFactory.participationHistoryResponse();
given(participantService.getParticipationHistory(memberId, page))
TestParticipantFactory.pastParticipationHistoryResponse();
given(participantService.getCurrentParticipationHistories(memberId, page))
.willReturn(participationHistoryPagingResponse);
// when
final ResultActions actions =
mockMvc.perform(get("/participants/histories").queryParam("page", "0"));
mockMvc.perform(get("/participants/current-history").queryParam("page", "0"));
// then
actions.andExpect(status().isOk());
// docs
actions.andDo(print())
.andDo(
document(
"participation-history",
getDocumentRequest(),
getDocumentResponse(),
queryParameters(parameterWithName("page").description("페이지 번호"))));
}

@Test
@DisplayName("회원의 과거에 참여한 그룹 내역을 조회할 수 있다.")
@WithMockMember
void memberPastParticipationHistory() throws Exception {
// given
final Long memberId = 1L;
final Integer page = 0;
final ParticipationHistoryPagingResponse participationHistoryPagingResponse =
TestParticipantFactory.pastParticipationHistoryResponse();
given(participantService.getPastParticipationHistories(memberId, page))
.willReturn(participationHistoryPagingResponse);
// when
final ResultActions actions =
mockMvc.perform(get("/participants/past-history").queryParam("page", "0"));
// then
actions.andExpect(status().isOk());
// docs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.amorgakco.backend.fixture.group.TestParticipantsFactory;
import com.amorgakco.backend.fixture.member.TestMemberFactory;
import com.amorgakco.backend.global.exception.ErrorCode;
import com.amorgakco.backend.global.exception.GroupAuthorityException;
import com.amorgakco.backend.global.exception.LocationVerificationException;
import com.amorgakco.backend.group.domain.Group;
import com.amorgakco.backend.member.domain.Member;
Expand All @@ -21,7 +20,7 @@ class ParticipantTest {
void verifiedLocation() {
// given
final Member host = TestMemberFactory.create(1L);
final Group group = TestGroupFactory.create(host);
final Group group = TestGroupFactory.createActiveGroup(host);
final Member member = TestMemberFactory.create(2L);
final Participant participant = TestParticipantsFactory.create(member);
group.addParticipants(participant);
Expand All @@ -36,7 +35,7 @@ void verifiedLocation() {
void duplicatedVerification() {
// given
final Member host = TestMemberFactory.create(1L);
final Group group = TestGroupFactory.create(host);
final Group group = TestGroupFactory.createActiveGroup(host);
final Member member = TestMemberFactory.create(2L);
final Participant participant = TestParticipantsFactory.create(member);
group.addParticipants(participant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void increaseTemperatureConcurrencyTest() throws InterruptedException {
Member targetMember = TestMemberFactory.createEntity();
memberRepository.save(requestMember);
memberRepository.save(targetMember);
Group group = TestGroupFactory.create(requestMember);
Group group = TestGroupFactory.createActiveGroup(requestMember);
group.addParticipants(new Participant(targetMember));
groupRepository.save(group);
int threadCount = 15;
Expand Down Expand Up @@ -84,7 +84,7 @@ void decreaseTemperatureConcurrencyTest() throws InterruptedException {
Member targetMember = TestMemberFactory.createEntity();
memberRepository.save(requestMember);
memberRepository.save(targetMember);
Group group = TestGroupFactory.create(requestMember);
Group group = TestGroupFactory.createActiveGroup(requestMember);
group.addParticipants(new Participant(targetMember));
groupRepository.save(group);
int threadCount = 15;
Expand Down
Loading

0 comments on commit 0d95ef4

Please sign in to comment.