-
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
6 changed files
with
79 additions
and
0 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
4 changes: 4 additions & 0 deletions
4
backend/src/main/java/net/pengcook/comment/dto/CreateCommentRequest.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,4 @@ | ||
package net.pengcook.comment.dto; | ||
|
||
public record CreateCommentRequest(long recipeId, String message) { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,17 @@ | |
import static com.epages.restdocs.apispec.RestAssuredRestDocumentationWrapper.document; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; | ||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; | ||
|
||
import io.restassured.RestAssured; | ||
import io.restassured.http.ContentType; | ||
import net.pengcook.RestDocsSetting; | ||
import net.pengcook.authentication.annotation.WithLoginUser; | ||
import net.pengcook.authentication.annotation.WithLoginUserTest; | ||
import net.pengcook.comment.dto.CreateCommentRequest; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
@@ -44,4 +47,26 @@ void readComments() { | |
.then().log().all() | ||
.body("size()", is(2)); | ||
} | ||
|
||
@Test | ||
@WithLoginUser(email = "[email protected]") | ||
@DisplayName("λκΈμ λ±λ‘νλ€.") | ||
void createComment() { | ||
CreateCommentRequest request = new CreateCommentRequest(1L, "thank you!"); | ||
|
||
RestAssured.given(spec).log().all() | ||
.filter(document(DEFAULT_RESTDOCS_PATH, | ||
"λ μνΌμ λκΈμ λ±λ‘ν©λλ€.", | ||
"λκΈ λ±λ‘ API", | ||
requestFields( | ||
fieldWithPath("recipeId").description("λ μνΌ μμ΄λ"), | ||
fieldWithPath("message").description("λκΈ λ΄μ©") | ||
) | ||
)) | ||
.contentType(ContentType.JSON) | ||
.body(request) | ||
.when().post("api/comments") | ||
.then().log().all() | ||
.statusCode(201); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import java.util.List; | ||
import net.pengcook.authentication.domain.UserInfo; | ||
import net.pengcook.comment.dto.CommentOfRecipeResponse; | ||
import net.pengcook.comment.dto.CreateCommentRequest; | ||
import net.pengcook.comment.repository.CommentRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
@@ -18,8 +20,12 @@ | |
@Sql(scripts = "/data/comment.sql") | ||
class CommentServiceTest { | ||
|
||
private static final int INITIAL_COMMENT_COUNT = 3; | ||
|
||
@Autowired | ||
private CommentService commentService; | ||
@Autowired | ||
private CommentRepository commentRepository; | ||
|
||
@Test | ||
@DisplayName("λ μνΌμ λκΈμ μ‘°ννλ€.") | ||
|
@@ -36,4 +42,15 @@ void readComments() { | |
|
||
assertThat(actual).containsExactlyInAnyOrderElementsOf(expect); | ||
} | ||
|
||
@Test | ||
@DisplayName("λκΈμ λ±λ‘νλ€.") | ||
void createComment() { | ||
CreateCommentRequest request = new CreateCommentRequest(2L, "thank you!"); | ||
UserInfo userInfo = new UserInfo(2L, "[email protected]"); | ||
|
||
commentService.createComment(request, userInfo); | ||
|
||
assertThat(commentRepository.count()).isEqualTo(INITIAL_COMMENT_COUNT + 1); | ||
} | ||
} |