Skip to content

Commit

Permalink
Merge pull request #158 from team-offonoff/topic_a-response
Browse files Browse the repository at this point in the history
토픽A/토픽B 별 투표 성공 테스트 케이스 분류
  • Loading branch information
melonturtle authored Feb 6, 2024
2 parents 4cc08de + d0aeb36 commit 86b926d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/docs/asciidoc/topic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ E2. 작성자가 아닌 유저가 상태 변경 시도
[source.html]
POST /topics/{topicId}/vote

OK
OK. 토픽A

operation::topic-controller-test/vote-for-topic-a_by-non-author_success[snippets="http-request,http-response"]

OK. 토픽B

operation::topic-controller-test/vote-for-topic_by-non-author_success[snippets="http-request,http-response"]
operation::topic-controller-test/vote-for-topic-b_by-non-author_success[snippets="http-request,http-response"]

E1. 토픽 작성자가 투표

Expand Down
28 changes: 27 additions & 1 deletion src/test/java/life/offonoff/ab/web/TopicControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import life.offonoff.ab.restdocs.RestDocsTest;
import life.offonoff.ab.util.token.JwtProvider;
import life.offonoff.ab.web.common.aspect.auth.AuthorizedArgumentResolver;
import life.offonoff.ab.web.response.ChoiceCountResponse;
import life.offonoff.ab.web.response.CommentResponse;
import life.offonoff.ab.web.response.VoteResponse;
import life.offonoff.ab.web.response.VoteResponseWithCount;
import life.offonoff.ab.web.response.topic.TopicResponse;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -39,6 +41,7 @@

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -192,7 +195,30 @@ void deleteTopic() throws Exception {
}

@Test
void voteForTopic_byNonAuthor_success() throws Exception {
void voteForTopicA_byNonAuthor_success() throws Exception {
CommentResponse commentResponse = CommentResponse.from(new Comment(createRandomMember(),
createRandomTopic(),
ChoiceOption.CHOICE_A,
"content"));
List<ChoiceCountResponse> choiceCounts = List.of(new ChoiceCountResponse(ChoiceOption.CHOICE_A, 0L),
new ChoiceCountResponse(ChoiceOption.CHOICE_B, 0L));

when(topicService.voteForTopicByMember(any(), any(), any()))
.thenReturn(VoteResponseWithCount.from(choiceCounts, commentResponse));

VoteRequest request = new VoteRequest(
ChoiceOption.CHOICE_A, LocalDateTime.now().atZone(ZoneId.systemDefault()).toEpochSecond());

mvc.perform(post(TopicUri.VOTE, 1).with(csrf().asHeader())
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().registerModule(new JavaTimeModule()) // For serializing localdatetime
.writeValueAsString(request)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.latestComment.content").value("content"));
}

@Test
void voteForTopicB_byNonAuthor_success() throws Exception {
when(topicService.voteForTopicByMember(any(), any(), any()))
.thenReturn(VoteResponse.from(CommentResponse.from(new Comment(createRandomMember(),
createRandomTopic(),
Expand Down

0 comments on commit 86b926d

Please sign in to comment.