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

[BE] refactor: 인수 테스트 리팩터링 #653

Merged
merged 33 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e5a3f6d
refactor: 멤버 생성 Fixture를 사용하게 변경
70825 Sep 14, 2023
54da4cb
refactor: 로그인 쿠키를 얻는 방식 변경
70825 Sep 14, 2023
4597818
refactor: ReviewSteps 수정, 리뷰 인수테스트 리팩터링
70825 Sep 14, 2023
1b21615
refactor: MemberAcceptanceTest, AuthAcceptanceTest 리팩터링
70825 Sep 14, 2023
47ca122
refactor: CategoryAcceptanceTest 리팩터링
70825 Sep 14, 2023
abe8c99
refactor: TagAcceptanceTest 리팩터링
70825 Sep 14, 2023
a363a2a
refactor: MemberAcceptanceTst 꿀조합 리팩터링
70825 Sep 15, 2023
4fa8013
refactor: 데이터를 순차적으로 저장하도록 saveAll 대신 save 사용하는걸로 변경
70825 Sep 15, 2023
0083dc4
refactor: ProductAcceptanceTest 리팩터링
70825 Sep 15, 2023
1f7b556
refactor: 페이지 요청 생성 방식 변경
70825 Sep 15, 2023
a526998
refactor: 레시피 요청 로직 리팩터링
70825 Sep 15, 2023
e946713
refactor: 인수 테스트 코드 리팩터링
70825 Sep 15, 2023
10913de
fix: PageRequest 생성 메서드의 파라미터 타입 변경
70825 Sep 16, 2023
ab43ea8
refactor: 로그인 쿠키를 얻는 메서드명 이름 변경
70825 Sep 16, 2023
fc47c32
refactor: 유저 닉네임 생성 요청을 공통 메서드로 분리
70825 Sep 16, 2023
5319165
style: 코드 포맷 적용
70825 Sep 16, 2023
0b6bc01
refactor: softAssertions -> soft 네이밍 변경
70825 Sep 16, 2023
958d8b2
refactor: 인수테스트에 API가 없는 저장 메서드만 남기고, 리포지토리 저C장 메서드 삭제,레시피 이미지 메서드 생성
70825 Sep 16, 2023
accfb1d
refactor: 페이지를_검증하다_메서드를 공통 메서드로 적용
70825 Sep 16, 2023
97d71ec
refactor: 리뷰 인수 테스트에 페이지 검증, 결과 검증 분리
70825 Sep 16, 2023
b8f4e85
refactor: 여러명이 리뷰와 레시피에 좋아요 누르는 기능 공통 메서드화
70825 Sep 16, 2023
4bc6544
refactor: 로그인 쿠키가 멤버를 생성하므로 필요없는 로직 제거
70825 Sep 16, 2023
556cc07
refactor: 태그 인수테스트 검증 값을 숫자에서 이름으로 변경
70825 Sep 18, 2023
f3a39ae
feat: Fixture 데이터 추가
70825 Sep 18, 2023
5e9ad93
refactor: ReviewAcceptanceTest 변수명 최대한 한글로 설정
70825 Sep 18, 2023
535aca2
refactor: TagAcceptanceTest 변수명 최대한 한글로 작성
70825 Sep 18, 2023
cd82c62
refactor: RecipeAcceptanceTest 변수명 최대한 한글로 작성
70825 Sep 18, 2023
a44c4bd
refactor: CategoryAcceptanceTest 변수명 최대한 한글로 작성
70825 Sep 18, 2023
059354f
refactor: ProductAcceptanceTest 변수명 최대한 한글로 작성
70825 Sep 18, 2023
92286f6
refactor: MemberAcceptanceTest 변수명 최대한 한글로 작성
70825 Sep 18, 2023
59a9efc
refactor: 통과하지 않는 테스트 수정
70825 Sep 18, 2023
eebe417
refactor: AuthAcceptanceTest 변수 한글로 작성
70825 Sep 19, 2023
00bd399
refactor: 카카오 로그인이 아닌 OAUTH 로그인으로 테스트 메서드 네이밍 수정
70825 Sep 19, 2023
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 @@ -2,15 +2,15 @@

import static com.funeat.acceptance.auth.LoginSteps.로그아웃_요청;
import static com.funeat.acceptance.auth.LoginSteps.로그인_시도_요청;
import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키를_얻는다;
import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득;
import static com.funeat.acceptance.auth.LoginSteps.카카오_로그인_버튼_클릭;
import static com.funeat.acceptance.common.CommonSteps.LOCATION_헤더에서_리다이렉트_주소_추출;
import static com.funeat.acceptance.common.CommonSteps.REDIRECT_URL을_검증한다;
import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다;
import static com.funeat.acceptance.common.CommonSteps.리다이렉션_영구_이동;
import static com.funeat.acceptance.common.CommonSteps.인증되지_않음;
import static com.funeat.acceptance.common.CommonSteps.정상_처리;
import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성;
import static com.funeat.fixture.MemberFixture.멤버1;
import static org.assertj.core.api.Assertions.assertThat;

import com.funeat.acceptance.common.AcceptanceTest;
Expand All @@ -26,23 +26,26 @@
@SuppressWarnings("NonAsciiCharacters")
public class AuthAcceptanceTest extends AcceptanceTest {

private static final String 마이페이지 = "/members";
private static final String 메인페이지 = "/";

@Autowired
private AuthService authService;

@Nested
class kakaoLogin_성공_테스트 {
class login_성공_테스트 {

@Test
void 멤버가_카카오_로그인_버튼을_누르면_카카오_로그인_페이지로_리다이렉트할_수_있다() {
void 멤버가_로그인_버튼을_누르면_OAUTH_로그인_페이지로_리다이렉트할_수_있다() {
// given
final var expected = authService.getLoginRedirectUri();
final var OAUTH_로그인_페이지 = authService.getLoginRedirectUri();

// when
final var response = 카카오_로그인_버튼_클릭();
final var 응답 = 카카오_로그인_버튼_클릭();

// then
STATUS_CODE를_검증한다(response, 리다이렉션_영구_이동);
REDIRECT_URL을_검증한다(response, expected);
STATUS_CODE를_검증한다(응답, 리다이렉션_영구_이동);
REDIRECT_URL을_검증한다(응답, OAUTH_로그인_페이지);
}
}

Expand All @@ -51,33 +54,25 @@ class loginAuthorizeUser_성공_테스트 {

@Test
void 신규_유저라면_마이페이지_경로를_헤더에_담아_응답을_보낸다() {
// given
final var code = "member1";
final var loginCookie = "12345";

// when
final var response = 로그인_시도_요청(code, loginCookie);
// given && when
final var 응답 = 로그인_시도_요청(멤버1);

// then
STATUS_CODE를_검증한다(response, 정상_처리);
헤더에_리다이렉트가_존재하는지_검증한다(response, "/members");
STATUS_CODE를_검증한다(응답, 정상_처리);
헤더에_리다이렉트가_존재하는지_검증한다(응답, 마이페이지);
}

@Test
void 기존_유저라면_메인페이지_경로를_헤더에_담아_응답을_보낸다() {
// given
final var member = 멤버_멤버1_생성();
단일_멤버_저장(member);

final var code = "member1";
final var loginCookie = 로그인_쿠키를_얻는다();
로그인_쿠키_획득(멤버1);

// when
final var response = 로그인_시도_요청(code, loginCookie);
final var 응답 = 로그인_시도_요청(멤버1);

// then
STATUS_CODE를_검증한다(response, 정상_처리);
헤더에_리다이렉트가_존재하는지_검증한다(response, "/");
STATUS_CODE를_검증한다(응답, 정상_처리);
헤더에_리다이렉트가_존재하는지_검증한다(응답, 메인페이지);
}
}

Expand All @@ -86,16 +81,12 @@ class logout_성공_테스트 {

@Test
void 로그아웃을_하다() {
// given
final var loginCookie = 로그인_쿠키를_얻는다();
final var expected = "/";

// when
final var response = 로그아웃_요청(loginCookie);
// given && when
final var 응답 = 로그아웃_요청(로그인_쿠키_획득(멤버1));

// then
STATUS_CODE를_검증한다(response, 리다이렉션_영구_이동);
REDIRECT_URL을_검증한다(response, expected);
STATUS_CODE를_검증한다(응답, 리다이렉션_영구_이동);
REDIRECT_URL을_검증한다(응답, 메인페이지);
}
}

Expand All @@ -106,10 +97,10 @@ class logout_실패_테스트 {
@NullAndEmptySource
void 쿠키가_존재하지_않을_때_로그아웃을_하면_예외가_발생한다(final String cookie) {
// given & when
final var response = 로그아웃_요청(cookie);
final var 응답 = 로그아웃_요청(cookie);

// then
STATUS_CODE를_검증한다(response, 인증되지_않음);
STATUS_CODE를_검증한다(응답, 인증되지_않음);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ public class LoginSteps {
.extract();
}

public static ExtractableResponse<Response> 로그인_시도_요청(final String code, final String loginCookie) {
public static ExtractableResponse<Response> 로그인_시도_요청(final Long memberId) {
return given()
.cookie("FUNEAT", loginCookie)
.param("code", code)
.param("code", String.valueOf(memberId))
.when()
.get("/api/login/oauth2/code/kakao")
.then()
Expand All @@ -37,9 +36,9 @@ public class LoginSteps {
.extract();
}

public static String 로그인_쿠키를_얻는다() {
public static String 로그인_쿠키_획득(final Long memberId) {
return RestAssured.given()
.queryParam("code", "test")
.queryParam("code", String.valueOf(memberId))
.when()
.get("/api/login/oauth2/code/kakao")
.then()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@

import com.funeat.common.DataClearExtension;
import com.funeat.member.domain.Member;
import com.funeat.member.domain.favorite.ReviewFavorite;
import com.funeat.member.persistence.MemberRepository;
import com.funeat.member.persistence.RecipeFavoriteRepository;
import com.funeat.member.persistence.ReviewFavoriteRepository;
import com.funeat.product.domain.Category;
import com.funeat.product.domain.Product;
import com.funeat.product.domain.ProductRecipe;
import com.funeat.product.persistence.CategoryRepository;
import com.funeat.product.persistence.ProductRecipeRepository;
import com.funeat.product.persistence.ProductRepository;
import com.funeat.recipe.domain.Recipe;
import com.funeat.recipe.domain.RecipeImage;
import com.funeat.recipe.persistence.RecipeImageRepository;
import com.funeat.recipe.persistence.RecipeRepository;
import com.funeat.review.domain.Review;
import com.funeat.review.domain.ReviewTag;
import com.funeat.review.persistence.ReviewRepository;
import com.funeat.review.persistence.ReviewTagRepository;
import com.funeat.tag.domain.Tag;
import com.funeat.tag.persistence.TagRepository;
import io.restassured.RestAssured;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
Expand Down Expand Up @@ -84,91 +77,15 @@ void setUp() {
return productRepository.save(product).getId();
}

protected void 복수_상품_저장(final Product... productsToSave) {
final var products = List.of(productsToSave);

productRepository.saveAll(products);
}

protected Long 단일_카테고리_저장(final Category category) {
return categoryRepository.save(category).getId();
}

protected void 복수_카테고리_저장(final Category... categoriesToSave) {
final var categories = List.of(categoriesToSave);

categoryRepository.saveAll(categories);
}

protected Long 단일_멤버_저장(final Member member) {
return memberRepository.save(member).getId();
}

protected void 복수_멤버_저장(final Member... membersToSave) {
final var members = List.of(membersToSave);

memberRepository.saveAll(members);
}

protected Long 단일_리뷰_저장(final Review review) {
return reviewRepository.save(review).getId();
}

protected void 복수_리뷰_저장(final Review... reviewsToSave) {
final var reviews = List.of(reviewsToSave);

reviewRepository.saveAll(reviews);
}

protected Long 단일_태그_저장(final Tag tag) {
return tagRepository.save(tag).getId();
}

protected void 복수_태그_저장(final Tag... tagsToSave) {
final var tags = List.of(tagsToSave);

tagRepository.saveAll(tags);
}

protected Long 단일_리뷰_태그_저장(final ReviewTag reviewTag) {
return reviewTagRepository.save(reviewTag).getId();
}

protected void 복수_리뷰_태그_저장(final ReviewTag... reviewTagsToSave) {
final var reviewTags = List.of(reviewTagsToSave);

reviewTagRepository.saveAll(reviewTags);
}

protected Long 단일_리뷰_좋아요_저장(final ReviewFavorite reviewFavorite) {
return reviewFavoriteRepository.save(reviewFavorite).getId();
}

protected void 복수_리뷰_좋아요_저장(final ReviewFavorite... reviewFavoritesToSave) {
final var reviewFavorites = List.of(reviewFavoritesToSave);

reviewFavoriteRepository.saveAll(reviewFavorites);
}

protected void 단일_꿀조합_저장(final Recipe recipe) {
recipeRepository.save(recipe);
}

protected void 복수_꿀조합_저장(final Recipe... recipesToSave) {
final var recipeFavorites = List.of(recipesToSave);

recipeRepository.saveAll(recipeFavorites);
}

protected void 복수_꿀조합_이미지_저장(final RecipeImage... recipeImageToSave) {
final var recipeFavorites = List.of(recipeImageToSave);

recipeImageRepository.saveAll(recipeFavorites);
}

protected void 복수_꿀조합_상품_저장(final ProductRecipe... productRecipeImageToSave) {
final var productRecipes = List.of(productRecipeImageToSave);

productRecipeRepository.saveAll(productRecipes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.funeat.common.dto.PageDto;
import io.restassured.builder.MultiPartSpecBuilder;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import io.restassured.specification.MultiPartSpecification;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.HttpStatus;

@SuppressWarnings("NonAsciiCharacters")
Expand Down Expand Up @@ -42,19 +45,33 @@ public class CommonSteps {
assertThat(actual).isEqualTo(expected);
}

public static MultiPartSpecification 사진_명세_요청() {
return new MultiPartSpecBuilder("image".getBytes())
.fileName("testImage.png")
.controlName("image")
.mimeType("image/png")
.build();
}

public static MultiPartSpecification 사진_명세_요청(final String name) {
return new MultiPartSpecBuilder("image".getBytes())
.fileName(String.format("%s.png", name))
.controlName("image")
.mimeType("image/png")
.build();
}

public static List<MultiPartSpecification> 여러개_사진_명세_요청(final String... names) {
final var images = new ArrayList<MultiPartSpecification>();

for (final String name : names) {
images.add(new MultiPartSpecBuilder("image".getBytes())
.fileName(String.format("%s.png", name))
.controlName("image")
.mimeType("image/png")
.build()
);
}

return images;
}

public static void 페이지를_검증한다(final ExtractableResponse<Response> response, final PageDto expected) {
final var actual = response.jsonPath().getObject("page", PageDto.class);

assertThat(actual).usingRecursiveComparison()
.isEqualTo(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class TestPlatformUserProvider implements PlatformUserProvider {

@Override
public UserInfoDto getPlatformUser(final String code) {
return new UserInfoDto(1L, code, String.format("www.%s.com", code));
return new UserInfoDto(Long.valueOf(code), String.format("member%s", code),
String.format("www.member%s.com", code));
}

@Override
Expand Down
Loading
Loading