Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 레시피 저장 리팩터링 #80

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public enum MemberErrorCode {
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다. 회원 id를 확인하세요.", "5001"),
MEMBER_UPDATE_ERROR(HttpStatus.BAD_REQUEST, "닉네임 또는 이미지를 확인하세요.", "5002"),
MEMBER_DUPLICATE_FAVORITE(HttpStatus.CONFLICT, "이미 좋아요를 누른 상태입니다.", "5003"),
MEMBER_DUPLICATE_BOOKMARK(HttpStatus.CONFLICT, "이미 북마크를 누른 상태입니다.", "5004"),
MEMBER_DUPLICATE_BOOKMARK(HttpStatus.CONFLICT, "이미 저장을 누른 상태입니다.", "5004"),
;

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jakarta.validation.constraints.NotNull;

public record RecipeBookmarkRequest (
@NotNull(message = "북마크를 확인해주세요")
@NotNull(message = "레시피 저장 기능을 확인해주세요")
Boolean bookmark
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import static com.funeat.acceptance.member.MemberSteps.리뷰_삭제_요청;
import static com.funeat.acceptance.member.MemberSteps.사용자_꿀조합_조회_요청;
import static com.funeat.acceptance.member.MemberSteps.사용자_리뷰_조회_요청;
import static com.funeat.acceptance.member.MemberSteps.사용자_북마크한_꿀조합_조회_요청;
import static com.funeat.acceptance.member.MemberSteps.사용자_저장한_꿀조합_조회_요청;
import static com.funeat.acceptance.member.MemberSteps.사용자_정보_수정_요청;
import static com.funeat.acceptance.member.MemberSteps.사용자_정보_조회_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_북마크_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_저장_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_작성_요청;
import static com.funeat.acceptance.review.ReviewSteps.리뷰_작성_요청;
import static com.funeat.auth.exception.AuthErrorCode.LOGIN_MEMBER_NOT_FOUND;
Expand All @@ -43,10 +43,10 @@
import static com.funeat.fixture.RecipeFixture.레시피1;
import static com.funeat.fixture.RecipeFixture.레시피2;
import static com.funeat.fixture.RecipeFixture.레시피3;
import static com.funeat.fixture.RecipeFixture.레시피북마크요청_생성;
import static com.funeat.fixture.RecipeFixture.레시피저장요청_생성;
import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성;
import static com.funeat.fixture.RecipeFixture.북마크O;
import static com.funeat.fixture.RecipeFixture.북마크X;
import static com.funeat.fixture.RecipeFixture.저장O;
import static com.funeat.fixture.RecipeFixture.저장X;
import static com.funeat.fixture.ReviewFixture.리뷰1;
import static com.funeat.fixture.ReviewFixture.리뷰2;
import static com.funeat.fixture.ReviewFixture.리뷰추가요청_재구매O_생성;
Expand Down Expand Up @@ -416,12 +416,12 @@ class getMemberBookmarkRecipe_성공_테스트 {
final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(0L), 총_페이지(0L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE);

// when
final var 응답 = 사용자_북마크한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);
final var 응답 = 사용자_저장한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
페이지를_검증한다(응답, 예상_응답_페이지);
사용자_북마크한_꿀조합_조회_결과를_검증한다(응답, Collections.emptyList());
사용자_저장한_꿀조합_조회_결과를_검증한다(응답, Collections.emptyList());
}

@Test
Expand All @@ -435,18 +435,18 @@ class getMemberBookmarkRecipe_성공_테스트 {
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품));
레시피_작성_요청(로그인_쿠키_획득(멤버2), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품));

레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피북마크요청_생성(북마크O));
레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피3, 레시피북마크요청_생성(북마크O));
레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피저장요청_생성(저장O));
레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피3, 레시피저장요청_생성(저장O));

final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(2L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE);

// when
final var 응답 = 사용자_북마크한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);
final var 응답 = 사용자_저장한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
페이지를_검증한다(응답, 예상_응답_페이지);
사용자_북마크한_꿀조합_조회_결과를_검증한다(응답, List.of(레시피3, 레시피1));
사용자_저장한_꿀조합_조회_결과를_검증한다(응답, List.of(레시피3, 레시피1));
}

@Test
Expand All @@ -459,20 +459,20 @@ class getMemberBookmarkRecipe_성공_테스트 {
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품));
레시피_작성_요청(로그인_쿠키_획득(멤버2), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품));

레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피북마크요청_생성(북마크O));
레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피2, 레시피북마크요청_생성(북마크O));
레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피저장요청_생성(저장O));
레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피2, 레시피저장요청_생성(저장O));

레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피북마크요청_생성(북마크X));
레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피저장요청_생성(저장X));

final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(1L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE);

// when
final var 응답 = 사용자_북마크한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);
final var 응답 = 사용자_저장한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
페이지를_검증한다(응답, 예상_응답_페이지);
사용자_북마크한_꿀조합_조회_결과를_검증한다(응답, List.of(레시피2));
사용자_저장한_꿀조합_조회_결과를_검증한다(응답, List.of(레시피2));
}

@Test
Expand All @@ -483,17 +483,17 @@ class getMemberBookmarkRecipe_성공_테스트 {
final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리));

레시피_작성_요청(로그인_쿠키_획득(멤버1), null, 레시피추가요청_생성(상품));
레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피북마크요청_생성(북마크O));
레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피1, 레시피저장요청_생성(저장O));

final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(1L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE);

// when
final var 응답 = 사용자_북마크한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);
final var 응답 = 사용자_저장한_꿀조합_조회_요청(로그인_쿠키_획득(멤버1), FIRST_PAGE);

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
페이지를_검증한다(응답, 예상_응답_페이지);
사용자_북마크한_꿀조합_조회_결과를_검증한다(응답, List.of(레시피));
사용자_저장한_꿀조합_조회_결과를_검증한다(응답, List.of(레시피));
조회한_꿀조합의_이미지가_없는지_확인한다(응답);
}
}
Expand All @@ -505,7 +505,7 @@ class getMemberBookmarkRecipe_실패_테스트 {
@NullAndEmptySource
void 로그인하지_않은_사용자가_저장한_꿀조합을_조회할때_예외가_발생한다(final String cookie) {
// given & when
final var 응답 = 사용자_북마크한_꿀조합_조회_요청(cookie, FIRST_PAGE);
final var 응답 = 사용자_저장한_꿀조합_조회_요청(cookie, FIRST_PAGE);

// then
STATUS_CODE를_검증한다(응답, 인증되지_않음);
Expand Down Expand Up @@ -570,8 +570,8 @@ class getMemberBookmarkRecipe_실패_테스트 {
assertThat(actual).isNull();
}

private void 사용자_북마크한_꿀조합_조회_결과를_검증한다(final ExtractableResponse<Response> response,
final List<Long> recipeIds) {
private void 사용자_저장한_꿀조합_조회_결과를_검증한다(final ExtractableResponse<Response> response,
final List<Long> recipeIds) {
final var actual = response.jsonPath()
.getList("recipes", MemberBookmarkRecipeDto.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class MemberSteps {
.extract();
}

public static ExtractableResponse<Response> 사용자_북마크한_꿀조합_조회_요청(final String loginCookie, final Long page) {
public static ExtractableResponse<Response> 사용자_저장한_꿀조합_조회_요청(final String loginCookie, final Long page) {
return given()
.when()
.cookie("SESSION", loginCookie)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_댓글_조회_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_랭킹_조회_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_목록_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_북마크_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_저장_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_상세_정보_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_작성_요청;
import static com.funeat.acceptance.recipe.RecipeSteps.레시피_좋아요_요청;
Expand Down Expand Up @@ -59,9 +59,11 @@
import static com.funeat.fixture.RecipeFixture.레시피9;
import static com.funeat.fixture.RecipeFixture.레시피_본문;
import static com.funeat.fixture.RecipeFixture.레시피_제목;
import static com.funeat.fixture.RecipeFixture.레시피북마크요청_생성;
import static com.funeat.fixture.RecipeFixture.레시피저장요청_생성;
import static com.funeat.fixture.RecipeFixture.레시피좋아요요청_생성;
import static com.funeat.fixture.RecipeFixture.레시피추가요청_생성;
import static com.funeat.fixture.RecipeFixture.저장O;
import static com.funeat.fixture.RecipeFixture.저장X;
import static com.funeat.fixture.RecipeFixture.존재하지_않는_레시피;
import static com.funeat.fixture.RecipeFixture.좋아요O;
import static com.funeat.fixture.RecipeFixture.좋아요X;
Expand Down Expand Up @@ -379,7 +381,7 @@ class likeRecipe_실패_테스트 {
class bookmarkRecipe_성공_테스트 {

@Test
void 레시피에_북마크를_할_수_있다() {
void 레시피_저장을_할_수_있다() {
// given
final var 카테고리 = 카테고리_간편식사_생성();
단일_카테고리_저장(카테고리);
Expand All @@ -388,24 +390,24 @@ class bookmarkRecipe_성공_테스트 {
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품));

// when
final var 응답 = 레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피북마크요청_생성(좋아요O));
final var 응답 = 레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피저장요청_생성(저장O));

// then
STATUS_CODE를_검증한다(응답, 정상_처리_NO_CONTENT);
}

@Test
void 레시피예_북마크를_취소할_수_있다() {
void 레시피_저장을_취소할_수_있다() {
// given
final var 카테고리 = 카테고리_간편식사_생성();
단일_카테고리_저장(카테고리);
final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점1점_생성(카테고리));

레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품));
레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피북마크요청_생성(좋아요O));
레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피저장요청_생성(저장O));

// when
final var 응답 = 레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피북마크요청_생성(좋아요X));
final var 응답 = 레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피저장요청_생성(저장X));

// then
STATUS_CODE를_검증한다(응답, 정상_처리_NO_CONTENT);
Expand All @@ -426,7 +428,7 @@ class bookmarkRecipe_실패_테스트 {
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품));

// when
final var 응답 = 레시피_북마크_요청(cookie, 레시피, 레시피북마크요청_생성(좋아요O));
final var 응답 = 레시피_저장_요청(cookie, 레시피, 레시피저장요청_생성(저장O));

// then
STATUS_CODE를_검증한다(응답, 인증되지_않음);
Expand All @@ -444,18 +446,18 @@ class bookmarkRecipe_실패_테스트 {
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품));

// when
final var 응답 = 레시피_북마크_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피북마크요청_생성(null));
final var 응답 = 레시피_저장_요청(로그인_쿠키_획득(멤버1), 레시피, 레시피저장요청_생성(null));

// then
STATUS_CODE를_검증한다(응답, 잘못된_요청);
RESPONSE_CODE와_MESSAGE를_검증한다(응답, REQUEST_VALID_ERROR_CODE.getCode(),
"북마크를 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage());
"레시피 저장 기능을 확인해주세요. " + REQUEST_VALID_ERROR_CODE.getMessage());
}

@Test
void 존재하지_않는_레시피에_사용자가_저장할_때_예외가_발생한다() {
// given & when
final var 응답 = 레시피_북마크_요청(로그인_쿠키_획득(멤버1), 존재하지_않는_레시피, 레시피북마크요청_생성(좋아요O));
final var 응답 = 레시피_저장_요청(로그인_쿠키_획득(멤버1), 존재하지_않는_레시피, 레시피저장요청_생성(저장O));

// then
STATUS_CODE를_검증한다(응답, 찾을수_없음);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public class RecipeSteps {
}
}

public static ExtractableResponse<Response> 레시피_북마크_요청(final String loginCookie, final Long recipeId,
final RecipeBookmarkRequest request) {
public static ExtractableResponse<Response> 레시피_저장_요청(final String loginCookie, final Long recipeId,
final RecipeBookmarkRequest request) {
return given()
.cookie("SESSION", loginCookie)
.contentType("application/json")
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/funeat/common/RepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public abstract class RepositoryTest {
recipeFavoriteRepository.save(recipeFavorite);
}

protected void 복수_레시피_북마크_저장(final RecipeBookmark... recipeBookmarksToSave) {
protected void 복수_저장한_레시피_저장(final RecipeBookmark... recipeBookmarksToSave) {
final var recipeBookmarks = List.of(recipeBookmarksToSave);

recipeBookmarkRepository.saveAll(recipeBookmarks);
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/funeat/fixture/RecipeFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class RecipeFixture {

public static final boolean 좋아요O = true;
public static final boolean 좋아요X = false;
public static final boolean 북마크O = true;
public static final boolean 북마크X = false;
public static final boolean 저장O = true;
public static final boolean 저장X = false;

public static final String 레시피_제목 = "The most delicious recipes";
public static final String 레시피_본문 = "More rice, more rice, more rice.. Done!!";
Expand All @@ -54,7 +54,7 @@ public class RecipeFixture {
return new RecipeFavorite(member, recipe, favorite);
}

public static RecipeBookmark 레시피_북마크_생성(final Member member, final Recipe recipe, final Boolean bookmark) {
public static RecipeBookmark 레시피_저장_생성(final Member member, final Recipe recipe, final Boolean bookmark) {
return new RecipeBookmark(member, recipe, bookmark);
}

Expand All @@ -74,8 +74,8 @@ public class RecipeFixture {
return new RecipeFavoriteRequest(favorite);
}

public static RecipeBookmarkRequest 레시피북마크요청_생성(final Boolean favorite) {
return new RecipeBookmarkRequest(favorite);
public static RecipeBookmarkRequest 레시피저장요청_생성(final Boolean bookmark) {
return new RecipeBookmarkRequest(bookmark);
}

public static RecipeImage 레시피이미지_생성(final Recipe recipe) {
Expand Down
Loading