diff --git a/backend/src/test/java/com/funeat/common/EventTest.java b/backend/src/test/java/com/funeat/common/EventTest.java index d7bc18d4..aeb72d41 100644 --- a/backend/src/test/java/com/funeat/common/EventTest.java +++ b/backend/src/test/java/com/funeat/common/EventTest.java @@ -52,15 +52,15 @@ void tearDown() { events.clear(); } - protected Product 단일_상품_저장(final Product product) { - return productRepository.save(product); + protected Long 단일_상품_저장(final Product product) { + return productRepository.save(product).getId(); } - protected Category 단일_카테고리_저장(final Category category) { - return categoryRepository.save(category); + protected Long 단일_카테고리_저장(final Category category) { + return categoryRepository.save(category).getId(); } - protected Member 단일_멤버_저장(final Member member) { - return memberRepository.save(member); + protected Long 단일_멤버_저장(final Member member) { + return memberRepository.save(member).getId(); } } diff --git a/backend/src/test/java/com/funeat/review/application/ReviewDeleteEventListenerTest.java b/backend/src/test/java/com/funeat/review/application/ReviewDeleteEventListenerTest.java index 92a6a0d4..ddfd6f9b 100644 --- a/backend/src/test/java/com/funeat/review/application/ReviewDeleteEventListenerTest.java +++ b/backend/src/test/java/com/funeat/review/application/ReviewDeleteEventListenerTest.java @@ -35,10 +35,14 @@ class 리뷰_삭제_이벤트_발행 { @Test void 리뷰_작성자가_리뷰_삭제_시도시_리뷰_삭제_이벤트가_발행된다() { // given - final var member = 단일_멤버_저장(멤버_멤버1_생성()); + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); - final var category = 단일_카테고리_저장(카테고리_즉석조리_생성()); - final var product = 단일_상품_저장(상품_삼각김밥_가격1000원_평점2점_생성(category)); + final var category = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); + 단일_상품_저장(product); final var review = reviewRepository.save(리뷰_이미지test1_평점1점_재구매O_생성(member, product, 0L)); @@ -53,11 +57,17 @@ class 리뷰_삭제_이벤트_발행 { @Test void 리뷰_작성자가_아닌_사람이_리뷰_삭제_시도시_리뷰_삭제_이벤트가_발행되지_않는다() { // given - final var author = 단일_멤버_저장(멤버_멤버2_생성()); - final var member = 단일_멤버_저장(멤버_멤버1_생성()); + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var author = 멤버_멤버2_생성(); + 단일_멤버_저장(author); + + final var category = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(category); - final var category = 단일_카테고리_저장(카테고리_즉석조리_생성()); - final var product = 단일_상품_저장(상품_삼각김밥_가격1000원_평점2점_생성(category)); + final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); + 단일_상품_저장(product); final var review = reviewRepository.save(리뷰_이미지test2_평점2점_재구매O_생성(author, product, 0L)); @@ -79,10 +89,14 @@ class 이미지_삭제_로직_작동 { @Test void 리뷰_삭제가_정상적으로_커밋되고_이미지가_존재하면_이미지_삭제_로직이_작동한다() { // given - final var member = 단일_멤버_저장(멤버_멤버1_생성()); + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); - final var category = 단일_카테고리_저장(카테고리_즉석조리_생성()); - final var product = 단일_상품_저장(상품_삼각김밥_가격1000원_평점2점_생성(category)); + final var category = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); + 단일_상품_저장(product); final var review = reviewRepository.save(리뷰_이미지test3_평점3점_재구매O_생성(member, product, 0L)); @@ -96,10 +110,14 @@ class 이미지_삭제_로직_작동 { @Test void 리뷰_삭제가_정상적으로_커밋되었지만_이미지가_존재하지_않으면_이미지_삭제_로직이_작동하지않는다() { // given - final var member = 단일_멤버_저장(멤버_멤버1_생성()); + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var category = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(category); - final var category = 단일_카테고리_저장(카테고리_즉석조리_생성()); - final var product = 단일_상품_저장(상품_삼각김밥_가격1000원_평점2점_생성(category)); + final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); + 단일_상품_저장(product); final var review = reviewRepository.save(리뷰_이미지없음_평점1점_재구매X_생성(member, product, 0L)); @@ -113,10 +131,14 @@ class 이미지_삭제_로직_작동 { @Test void 이미지_삭제_로직이_실패해도_메인로직까지_롤백되어서는_안된다() { // given - final var member = 단일_멤버_저장(멤버_멤버1_생성()); + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var category = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(category); - final var category = 단일_카테고리_저장(카테고리_즉석조리_생성()); - final var product = 단일_상품_저장(상품_삼각김밥_가격1000원_평점2점_생성(category)); + final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); + 단일_상품_저장(product); final var review = reviewRepository.save(리뷰_이미지test4_평점4점_재구매O_생성(member, product, 0L));