-
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.
Merge pull request #165 from DayByQuest/test/postService
[Test] 게시물 조회 서비스들을 테스트한다
- Loading branch information
Showing
26 changed files
with
769 additions
and
56 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
150 changes: 150 additions & 0 deletions
150
src/test/java/daybyquest/post/application/CheckPostServiceTest.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,150 @@ | ||
package daybyquest.post.application; | ||
|
||
import static daybyquest.global.error.ExceptionCode.ALREADY_JUDGED_POST; | ||
import static daybyquest.global.error.ExceptionCode.NOT_GROUP_MANAGER; | ||
import static daybyquest.global.error.ExceptionCode.NOT_LINKED_POST; | ||
import static daybyquest.post.domain.PostState.FAIL; | ||
import static daybyquest.post.domain.PostState.SUCCESS; | ||
import static daybyquest.support.fixture.GroupFixtures.GROUP_1; | ||
import static daybyquest.support.fixture.InterestFixtures.INTEREST; | ||
import static daybyquest.support.fixture.PostFixtures.POST_1; | ||
import static daybyquest.support.fixture.QuestFixtures.QUEST_1; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
import daybyquest.group.domain.Group; | ||
import daybyquest.group.domain.GroupUser; | ||
import daybyquest.post.domain.Post; | ||
import daybyquest.post.dto.request.CheckPostRequest; | ||
import daybyquest.quest.domain.Quest; | ||
import daybyquest.support.test.ServiceTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
public class CheckPostServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private CheckPostService checkPostService; | ||
|
||
@Test | ||
void 그룹장이_그룹_퀘스트를_성공_시킨다() { | ||
// given | ||
final Long aliceId = 중재자_권한으로_ALICE를_저장한다(); | ||
interests.save(INTEREST.생성()); | ||
|
||
final Group group = groups.save(aliceId, GROUP_1.생성()); | ||
final Quest quest = quests.save(QUEST_1.보상_없이_세부사항을_설정한다(QUEST_1.그룹_퀘스트_생성(group))); | ||
final Long questId = quest.getId(); | ||
participants.saveWithUserIdAndQuestId(aliceId, questId); | ||
|
||
final Post post = POST_1.생성(aliceId, questId); | ||
post.needCheck(); | ||
final Long postId = posts.save(post).getId(); | ||
|
||
final CheckPostRequest request = 게시물_판정_요청(true); | ||
|
||
// when | ||
checkPostService.invoke(aliceId, postId, request); | ||
|
||
// then | ||
final Post actual = posts.getById(postId); | ||
assertThat(actual.getState()).isEqualTo(SUCCESS); | ||
} | ||
|
||
@Test | ||
void 그룹장이_그룹_퀘스트를_실패_시킨다() { | ||
// given | ||
final Long aliceId = 중재자_권한으로_ALICE를_저장한다(); | ||
interests.save(INTEREST.생성()); | ||
|
||
final Group group = groups.save(aliceId, GROUP_1.생성()); | ||
final Quest quest = quests.save(QUEST_1.보상_없이_세부사항을_설정한다(QUEST_1.그룹_퀘스트_생성(group))); | ||
final Long questId = quest.getId(); | ||
participants.saveWithUserIdAndQuestId(aliceId, questId); | ||
|
||
final Post post = POST_1.생성(aliceId, questId); | ||
post.needCheck(); | ||
final Long postId = posts.save(post).getId(); | ||
|
||
final CheckPostRequest request = 게시물_판정_요청(false); | ||
|
||
// when | ||
checkPostService.invoke(aliceId, postId, request); | ||
|
||
// then | ||
final Post actual = posts.getById(postId); | ||
assertThat(actual.getState()).isEqualTo(FAIL); | ||
} | ||
|
||
@Test | ||
void 그룹장이_아니면_예외를_던진다() { | ||
// given | ||
final Long aliceId = 중재자_권한으로_ALICE를_저장한다(); | ||
final Long bobId = 중재자_권한으로_BOB을_저장한다(); | ||
interests.save(INTEREST.생성()); | ||
|
||
final Group group = groups.save(aliceId, GROUP_1.생성()); | ||
final Quest quest = quests.save(QUEST_1.보상_없이_세부사항을_설정한다(QUEST_1.그룹_퀘스트_생성(group))); | ||
final Long questId = quest.getId(); | ||
groupUsers.addUser(GroupUser.createGroupMember(bobId, group)); | ||
|
||
participants.saveWithUserIdAndQuestId(aliceId, questId); | ||
|
||
final Post post = POST_1.생성(aliceId, questId); | ||
post.needCheck(); | ||
final Long postId = posts.save(post).getId(); | ||
|
||
final CheckPostRequest request = 게시물_판정_요청(false); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> checkPostService.invoke(bobId, postId, request)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(NOT_GROUP_MANAGER.getMessage()); | ||
} | ||
|
||
@Test | ||
void 퀘스트가_링크되지_않은_게시물을_확인할_수_없다() { | ||
// given | ||
final Long aliceId = 중재자_권한으로_ALICE를_저장한다(); | ||
|
||
final Long postId = posts.save(POST_1.생성(aliceId)).getId(); | ||
|
||
final CheckPostRequest request = 게시물_판정_요청(true); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> checkPostService.invoke(aliceId, postId, request)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(NOT_LINKED_POST.getMessage()); | ||
} | ||
|
||
@Test | ||
void 이미_확인된_게시물은_확인할_수_없다() { | ||
// given | ||
final Long aliceId = 중재자_권한으로_ALICE를_저장한다(); | ||
interests.save(INTEREST.생성()); | ||
|
||
final Group group = groups.save(aliceId, GROUP_1.생성()); | ||
final Quest quest = quests.save(QUEST_1.보상_없이_세부사항을_설정한다(QUEST_1.그룹_퀘스트_생성(group))); | ||
final Long questId = quest.getId(); | ||
participants.saveWithUserIdAndQuestId(aliceId, questId); | ||
|
||
final Post post = POST_1.생성(aliceId, questId); | ||
post.success(); | ||
final Long postId = posts.save(post).getId(); | ||
|
||
final CheckPostRequest request = 게시물_판정_요청(true); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> checkPostService.invoke(aliceId, postId, request)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(ALREADY_JUDGED_POST.getMessage()); | ||
} | ||
|
||
private CheckPostRequest 게시물_판정_요청(final boolean approval) { | ||
final CheckPostRequest request = new CheckPostRequest(); | ||
ReflectionTestUtils.setField(request, "approval", approval); | ||
return request; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/test/java/daybyquest/post/application/GetNeedCheckPostServiceTest.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,78 @@ | ||
package daybyquest.post.application; | ||
|
||
import static daybyquest.global.error.ExceptionCode.NOT_GROUP_MANAGER; | ||
import static daybyquest.support.fixture.GroupFixtures.GROUP_1; | ||
import static daybyquest.support.fixture.InterestFixtures.INTEREST; | ||
import static daybyquest.support.fixture.PostFixtures.POST_1; | ||
import static daybyquest.support.fixture.QuestFixtures.QUEST_1; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import daybyquest.global.error.exception.InvalidDomainException; | ||
import daybyquest.group.domain.Group; | ||
import daybyquest.group.domain.GroupUser; | ||
import daybyquest.post.domain.Post; | ||
import daybyquest.post.dto.response.SimplePostResponse; | ||
import daybyquest.quest.domain.Quest; | ||
import daybyquest.support.test.ServiceTest; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class GetNeedCheckPostServiceTest extends ServiceTest { | ||
|
||
@Autowired | ||
private GetNeedCheckPostsService getNeedCheckPostsService; | ||
|
||
@Test | ||
void 확인이_필요한_게시물을_조회한다() { | ||
// given | ||
final Long aliceId = 중재자_권한으로_ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
interests.save(INTEREST.생성()); | ||
|
||
final Group group = groups.save(aliceId, GROUP_1.생성()); | ||
final Quest quest = quests.save(QUEST_1.보상_없이_세부사항을_설정한다(QUEST_1.그룹_퀘스트_생성(group))); | ||
final Long questId = quest.getId(); | ||
|
||
groupUsers.addUser(GroupUser.createGroupMember(bobId, group)); | ||
|
||
participants.saveWithUserIdAndQuestId(aliceId, questId); | ||
participants.saveWithUserIdAndQuestId(bobId, questId); | ||
|
||
final Post post1 = POST_1.생성(aliceId, questId); | ||
post1.needCheck(); | ||
final Post post2 = POST_1.생성(aliceId, questId); | ||
post2.needCheck(); | ||
|
||
final List<Long> actual = List.of(posts.save(post1).getId(), | ||
posts.save(post2).getId()); | ||
posts.save(POST_1.생성(bobId)); | ||
|
||
// when | ||
final List<Long> expected = getNeedCheckPostsService.invoke(aliceId, group.getId()).posts() | ||
.stream().map(SimplePostResponse::id).toList(); | ||
|
||
// then | ||
assertThat(actual).containsExactlyInAnyOrderElementsOf(expected); | ||
} | ||
|
||
@Test | ||
void 관리자가_아니라면_조회할_수_없다() { | ||
// given | ||
final Long aliceId = 중재자_권한으로_ALICE를_저장한다(); | ||
final Long bobId = BOB을_저장한다(); | ||
interests.save(INTEREST.생성()); | ||
|
||
final Group group = groups.save(aliceId, GROUP_1.생성()); | ||
final Quest quest = quests.save(QUEST_1.보상_없이_세부사항을_설정한다(QUEST_1.그룹_퀘스트_생성(group))); | ||
final Long questId = quest.getId(); | ||
|
||
groupUsers.addUser(GroupUser.createGroupMember(bobId, group)); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> getNeedCheckPostsService.invoke(bobId, questId)) | ||
.isInstanceOf(InvalidDomainException.class) | ||
.hasMessageContaining(NOT_GROUP_MANAGER.getMessage()); | ||
} | ||
} |
Oops, something went wrong.