read comments
This commit is contained in:
@@ -111,6 +111,7 @@ public class ArticlesApiTest extends TestWithCurrentUser {
|
||||
.body(param)
|
||||
.when()
|
||||
.post("/articles")
|
||||
.prettyPeek()
|
||||
.then()
|
||||
.statusCode(422)
|
||||
.body("errors.body[0]", equalTo("can't be empty"));
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -47,6 +48,7 @@ public class CommentsApiTest extends TestWithCurrentUser {
|
||||
private CommentQueryService commentQueryService;
|
||||
|
||||
private Article article;
|
||||
private CommentData commentData;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -58,6 +60,13 @@ public class CommentsApiTest extends TestWithCurrentUser {
|
||||
|
||||
article = new Article("title", "desc", "body", new String[]{"test", "java"}, user.getId());
|
||||
when(articleRepository.findBySlug(eq(article.getSlug()))).thenReturn(Optional.of(article));
|
||||
commentData = new CommentData(
|
||||
"123",
|
||||
"comment",
|
||||
article.getId(),
|
||||
new DateTime(),
|
||||
new DateTime(),
|
||||
new ProfileData(user.getId(), user.getUsername(), user.getBio(), user.getImage(), false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,14 +77,6 @@ public class CommentsApiTest extends TestWithCurrentUser {
|
||||
}});
|
||||
}};
|
||||
|
||||
CommentData commentData = new CommentData(
|
||||
"123",
|
||||
"comment",
|
||||
article.getId(),
|
||||
new DateTime(),
|
||||
new DateTime(),
|
||||
new ProfileData(user.getId(), user.getUsername(), user.getBio(), user.getImage(), false));
|
||||
|
||||
when(commentQueryService.findById(anyString(), eq(user))).thenReturn(Optional.of(commentData));
|
||||
|
||||
given()
|
||||
@@ -108,4 +109,15 @@ public class CommentsApiTest extends TestWithCurrentUser {
|
||||
.body("errors.body[0]", equalTo("can't be empty"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_get_comments_of_article_success() throws Exception {
|
||||
when(commentQueryService.findByArticleSlug(anyString(), eq(null))).thenReturn(Arrays.asList(commentData));
|
||||
RestAssured.when()
|
||||
.get("/articles/{slug}/comments", article.getSlug())
|
||||
.prettyPeek()
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("comments[0].id", equalTo(commentData.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user