Skip to content

Commit

Permalink
[BE] Feed Member 인수테스트 적용 (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
devbattery authored Nov 14, 2023
2 parents 95891fd + 04ae00b commit b9190f3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public ResponseEntity<Slice<FeedReadAllResponse>> readAll(Pageable pageable) {
* Feed 등록
*/
@PostMapping("/api/feeds")
public ResponseEntity<FeedRegisterResponse> register(@RequestBody FeedRegisterRequest feedRegisterRequest) {
// TODO: 회원 기능 완료되면 "@MemberId String memberId" 추가
public ResponseEntity<FeedRegisterResponse> register(@RequestBody FeedRegisterRequest feedRegisterRequest,
@MemberId String memberId) {
FeedRegisterResponse feedRegisterResponse = feedService.register(
FeedMapper.toServiceRegisterRequest(feedRegisterRequest, "2"));
FeedMapper.toServiceRegisterRequest(feedRegisterRequest, memberId));
return ResponseEntity.ok().body(feedRegisterResponse);
}

Expand All @@ -59,9 +59,9 @@ public ResponseEntity<FeedReadResponse> read(@PathVariable String id) {
* Feed 수정
*/
@PutMapping("/api/feeds/{id}")
public ResponseEntity<Void> update(@PathVariable String id, @RequestBody FeedUpdateRequest feedUpdateRequest) {
// TODO: 회원 기능 완료되면 "@MemberId String memberId" 추가
feedService.update(id, FeedMapper.toServiceUpdateRequest(feedUpdateRequest, "2"));
public ResponseEntity<Void> update(@PathVariable String id, @RequestBody FeedUpdateRequest feedUpdateRequest,
@MemberId String memberId) {
feedService.update(id, FeedMapper.toServiceUpdateRequest(feedUpdateRequest, memberId));
return ResponseEntity.noContent().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static com.foodymoody.be.acceptance.comment.CommentSteps.피드에_댓글을_등록한다;
import static com.foodymoody.be.acceptance.comment.CommentSteps.피드에_여러_공백댓글_등록한다;
import static com.foodymoody.be.acceptance.comment.CommentSteps.피드에서_200자_넘는_댓글을_등록한다;
import static com.foodymoody.be.feed.FeedSteps.피드를_등록하고_아이디를_받는다;
import static com.foodymoody.be.acceptance.feed.FeedSteps.피드를_등록하고_아이디를_받는다;

import com.foodymoody.be.acceptance.AcceptanceTest;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -39,7 +39,7 @@ class RegisterCommentTest {

@BeforeEach
void setFeedId() {
feedId = 피드를_등록하고_아이디를_받는다();
feedId = 피드를_등록하고_아이디를_받는다(회원아티_액세스토큰);
}

@DisplayName("댓글 등록 요청시 성공하면, 응답코드 200을 응답한다")
Expand Down Expand Up @@ -160,7 +160,7 @@ class UpdateCommentTest {

@BeforeEach
void setUp() {
feedId = 피드를_등록하고_아이디를_받는다();
feedId = 피드를_등록하고_아이디를_받는다(회원아티_액세스토큰);
commentId = 피드에_댓글을_등록하고_아이디를_받는다(feedId, 회원아티_액세스토큰);
}

Expand Down Expand Up @@ -271,7 +271,7 @@ class DeleteComment {

@BeforeEach
void setUp() {
feedId = 피드를_등록하고_아이디를_받는다();
feedId = 피드를_등록하고_아이디를_받는다(회원아티_액세스토큰);
commentId = 피드에_댓글을_등록하고_아이디를_받는다(feedId, 회원아티_액세스토큰);
}

Expand Down Expand Up @@ -327,7 +327,7 @@ class FetchComments {

@BeforeEach
void setUp() {
feedId = 피드를_등록하고_아이디를_받는다();
feedId = 피드를_등록하고_아이디를_받는다(회원아티_액세스토큰);
for (int i = 0; i < 20; i++) {
피드에_댓글을_등록한다(feedId, 회원아티_액세스토큰);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.foodymoody.be.feed;

import static com.foodymoody.be.feed.FeedSteps.개별_피드를_조회한다;
import static com.foodymoody.be.feed.FeedSteps.응답코드가_200이고_id가_존재하면_정상적으로_등록된_피드;
import static com.foodymoody.be.feed.FeedSteps.응답코드가_200이고_개별_피드가_조회되면_정상적으로_등록된_피드;
import static com.foodymoody.be.feed.FeedSteps.응답코드가_200이고_전체_피드가_조회되면_정상적으로_조회_가능한_전체_페이지;
import static com.foodymoody.be.feed.FeedSteps.응답코드가_204라면_정상적으로_수정_삭제된_피드;
import static com.foodymoody.be.feed.FeedSteps.전체_피드를_조회한다;
import static com.foodymoody.be.feed.FeedSteps.피드를_등록한다;
import static com.foodymoody.be.feed.FeedSteps.피드를_삭제한다;
import static com.foodymoody.be.feed.FeedSteps.피드를_수정한다;

package com.foodymoody.be.acceptance.feed;

import static com.foodymoody.be.acceptance.feed.FeedSteps.개별_피드를_조회한다;
import static com.foodymoody.be.acceptance.feed.FeedSteps.응답코드가_200이고_id가_존재하면_정상적으로_등록된_피드;
import static com.foodymoody.be.acceptance.feed.FeedSteps.응답코드가_200이고_개별_피드가_조회되면_정상적으로_등록된_피드;
import static com.foodymoody.be.acceptance.feed.FeedSteps.응답코드가_200이고_전체_피드가_조회되면_정상적으로_조회_가능한_전체_페이지;
import static com.foodymoody.be.acceptance.feed.FeedSteps.응답코드가_204라면_정상적으로_수정_삭제된_피드;
import static com.foodymoody.be.acceptance.feed.FeedSteps.전체_피드를_조회한다;
import static com.foodymoody.be.acceptance.feed.FeedSteps.피드를_등록한다;
import static com.foodymoody.be.acceptance.feed.FeedSteps.피드를_삭제한다;
import static com.foodymoody.be.acceptance.feed.FeedSteps.피드를_수정한다;

import com.foodymoody.be.acceptance.AcceptanceTest;
import com.foodymoody.be.docs.Document;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class FeedTest extends Document {
class FeedAcceptanceTest extends AcceptanceTest {

@DisplayName("전체 피드 조회에 성공하면 응답코드 200을 반환한다")
@Test
Expand All @@ -36,7 +37,7 @@ void when_register_feed_then_response200() {
api_문서_타이틀("registerFeed", spec);

// given,when
var response = 피드를_등록한다(spec);
var response = 피드를_등록한다(회원아티_액세스토큰, spec);

// then
응답코드가_200이고_id가_존재하면_정상적으로_등록된_피드(response);
Expand All @@ -49,7 +50,7 @@ void when_read_feed_then_response200() {
api_문서_타이틀("readFeed", spec);

// given
var registerResponse = 피드를_등록한다();
var registerResponse = 피드를_등록한다(회원아티_액세스토큰);
String registeredId = registerResponse.jsonPath().getString("id");

// when
Expand All @@ -66,11 +67,11 @@ void when_update_feed_then_response204() {
api_문서_타이틀("updateFeed", spec);

// given
var registerResponse = 피드를_등록한다();
var registerResponse = 피드를_등록한다(회원아티_액세스토큰);
String registeredId = registerResponse.jsonPath().getString("id");

// when
var updateResponse = 피드를_수정한다(registeredId, spec);
var updateResponse = 피드를_수정한다(회원아티_액세스토큰, registeredId, spec);

// then
응답코드가_204라면_정상적으로_수정_삭제된_피드(updateResponse);
Expand All @@ -83,11 +84,11 @@ void when_delete_feed_then_response204() {
api_문서_타이틀("deleteFeed", spec);

// given
var registerResponse = 피드를_등록한다();
var registerResponse = 피드를_등록한다(회원아티_액세스토큰);
String registeredId = registerResponse.jsonPath().getString("id");

// when
var deleteResponse = 피드를_삭제한다(registeredId, spec);
var deleteResponse = 피드를_삭제한다(회원아티_액세스토큰, registeredId, spec);

// then
응답코드가_204라면_정상적으로_수정_삭제된_피드(deleteResponse);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.foodymoody.be.feed;
package com.foodymoody.be.acceptance.feed;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down Expand Up @@ -88,15 +88,15 @@ public class FeedSteps {
}


public static ExtractableResponse<Response> 피드를_등록한다() {
return 피드를_등록한다(new RequestSpecBuilder().build());
public static ExtractableResponse<Response> 피드를_등록한다(String accessToken) {
return 피드를_등록한다(accessToken, new RequestSpecBuilder().build());
}

public static String 피드를_등록하고_아이디를_받는다() {
return 피드를_등록한다(new RequestSpecBuilder().build()).jsonPath().getString("id");
public static String 피드를_등록하고_아이디를_받는다(String accessToken) {
return 피드를_등록한다(accessToken, new RequestSpecBuilder().build()).jsonPath().getString("id");
}

public static ExtractableResponse<Response> 피드를_등록한다(RequestSpecification spec) {
public static ExtractableResponse<Response> 피드를_등록한다(String accessToken, RequestSpecification spec) {
Map<String, Object> body = Map.of(
"location", "역삼동",
"review", "맛있어요!",
Expand Down Expand Up @@ -124,6 +124,8 @@ public class FeedSteps {
.contentType(MediaType.APPLICATION_JSON_VALUE)
.spec(spec)
.log().all()
.auth()
.oauth2(accessToken)
.body(body)
.when()
.post("/api/feeds")
Expand Down Expand Up @@ -198,7 +200,7 @@ public class FeedSteps {
);
}

public static ExtractableResponse<Response> 피드를_수정한다(String id, RequestSpecification spec) {
public static ExtractableResponse<Response> 피드를_수정한다(String accessToken, String id, RequestSpecification spec) {
Map<String, Object> body = Map.of(
"location", "맛있게 매운 콩볼 범계점2",
"review", "맛있게 먹었습니다.2",
Expand Down Expand Up @@ -226,6 +228,8 @@ public class FeedSteps {
.contentType(MediaType.APPLICATION_JSON_VALUE)
.spec(spec)
.log().all()
.auth()
.oauth2(accessToken)
.body(body)
.when()
.put("/api/feeds/" + id)
Expand All @@ -234,12 +238,14 @@ public class FeedSteps {
.extract();
}

public static ExtractableResponse<Response> 피드를_삭제한다(String id, RequestSpecification spec) {
public static ExtractableResponse<Response> 피드를_삭제한다(String accessToken, String id, RequestSpecification spec) {
return RestAssured
.given()
.contentType(MediaType.APPLICATION_JSON_VALUE)
.spec(spec)
.log().all()
.auth()
.oauth2(accessToken)
.when()
.delete("/api/feeds/" + id)
.then()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.foodymoody.be.member.util;

public enum MemberFixture {
회원_알버트(null,"albert@albert.com", "testtest123!", "알버트", "베지테리안", "https://www.image.com"),
회원_설리(null,"sully@sully.com", "testtest123!", "설리", "베지테리안", "https://www.image.com"),
회원_보노(null,"bono@bono.com", "testtest123!", "보노", "베지테리안", "https://www.image.com"),
회원_알버트(null,"albert@albert.com", "testtest123!", "알버트", "베지테리언", "https://www.image.com"),
회원_설리(null,"sully@sully.com", "testtest123!", "설리", "베지테리언", "https://www.image.com"),
회원_보노(null,"bono@bono.com", "testtest123!", "보노", "베지테리언", "https://www.image.com"),
회원_아티("1", "ati@ati.com", "ati123!", "아티", "베지테리언", null),
회원_푸반("2", "puban@puban.com", "puban123!", "푸반", "베지테리언", null);

Expand Down

0 comments on commit b9190f3

Please sign in to comment.