Skip to content

Commit

Permalink
refac: controller context 1개만 뜨도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
korECM committed Nov 5, 2022
1 parent b696939 commit 2086314
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 178 deletions.
17 changes: 4 additions & 13 deletions src/test/kotlin/zip/cafe/api/CafeControllerTest.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
package zip.cafe.api

import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import zip.cafe.api.utils.mockmvc.documentWithHandle
import zip.cafe.api.utils.mockmvc.getWithPathParameter
import zip.cafe.api.utils.restdocs.*
import zip.cafe.api.utils.spec.WebMvcTestSpec
import zip.cafe.entity.review.CafeKeyword
import zip.cafe.seeds.MOCK_MVC_USER_ID
import zip.cafe.seeds.createCafe
import zip.cafe.seeds.createMenu
import zip.cafe.seeds.createReviewImage
import zip.cafe.service.CafeService
import zip.cafe.service.dto.FollowerWhoLikeCafe
import zip.cafe.service.dto.FollowerWhoWriteReview
import zip.cafe.service.dto.ReviewSummary

@WebMvcTest(CafeController::class)
class CafeControllerTest : WebMvcTestSpec() {

@MockkBean
private lateinit var cafeService: CafeService
class CafeControllerTest : WebMvcTestAdapter() {

init {
"카페 id를 가지고 카페 기본 정보를 가져온다" {
Expand Down Expand Up @@ -68,7 +60,7 @@ class CafeControllerTest : WebMvcTestSpec() {
"menus" type ARRAY means "카페 메뉴",
"menus[].id" type NUMBER means "카페 메뉴 id" example "1L",
"menus[].name" type STRING means "카페 메뉴 이름" example "아이스 아메리카노",
"menus[].price" type NUMBER means "카페 메뉴 가격" example "5000L",
"menus[].price" type NUMBER means "카페 메뉴 가격" example "5000L"
)
)
}
Expand All @@ -95,13 +87,12 @@ class CafeControllerTest : WebMvcTestSpec() {
"body" beneathPathWithSubsectionId "body",
"followersWhoWriteReview" type ARRAY means "유저가 팔로우한 사람들의 리뷰 정보",
"followersWhoWriteReview[].id" type NUMBER means "그 사람의 id" example "1L",
"followersWhoWriteReview[].name" type STRING means "그 사람의 닉네임" example "홍길동",
"followersWhoWriteReview[].name" type STRING means "그 사람의 닉네임" example "홍길동"
)
)
}
}


"카페 id를 가지고 로그인한 유저의 팔로워 중 카페를 좋아요 한 유저만 반환한다" {
val cafe = createCafe(id = 5L)
every { cafeService.findFollowerWhoLikeCafe(MOCK_MVC_USER_ID, cafe.id) } returns listOf(
Expand All @@ -123,7 +114,7 @@ class CafeControllerTest : WebMvcTestSpec() {
"body" beneathPathWithSubsectionId "body",
"followersWhoLikeCafe" type ARRAY means "유저가 팔로우한 사람들의 카페 좋아요 정보",
"followersWhoLikeCafe[].id" type NUMBER means "그 사람의 id" example "3L",
"followersWhoLikeCafe[].name" type STRING means "그 사람의 닉네임" example "고길동",
"followersWhoLikeCafe[].name" type STRING means "그 사람의 닉네임" example "고길동"
)
)
}
Expand Down
10 changes: 3 additions & 7 deletions src/test/kotlin/zip/cafe/api/CommonResponseControllerTest.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package zip.cafe.api

import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.test.web.servlet.get
import zip.cafe.api.controller.CommonResponseController
import zip.cafe.api.utils.mockmvc.documentWithHandle
import zip.cafe.api.utils.restdocs.*
import zip.cafe.api.utils.spec.WebMvcTestSpec

@WebMvcTest(CommonResponseController::class)
class CommonResponseControllerTest : WebMvcTestSpec() {
class CommonResponseControllerTest : WebMvcTestAdapter() {
init {
"공통 응답 null" {
val response = mockMvc.get("/common/null")
Expand All @@ -21,7 +17,7 @@ class CommonResponseControllerTest : WebMvcTestSpec() {
"common-response-null",
responseBody(
"message" type STRING means "응답 메시지" example "",
"body" type NULL means "데이터" example "null",
"body" type NULL means "데이터" example "null"
)
)
}
Expand Down Expand Up @@ -75,7 +71,7 @@ class CommonResponseControllerTest : WebMvcTestSpec() {
"common-response-error",
responseBody(
"message" type STRING means "에러 메시지" example "해당 유저가 존재하지 않습니다",
"body" type NULL means "데이터" example "null",
"body" type NULL means "데이터" example "null"
)
)
}
Expand Down
45 changes: 20 additions & 25 deletions src/test/kotlin/zip/cafe/api/FeedControllerTest.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
package zip.cafe.api

import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import zip.cafe.api.dto.*
import zip.cafe.api.utils.restdocs.*
import zip.cafe.api.utils.spec.WebMvcTestSpec
import zip.cafe.seeds.*
import zip.cafe.service.FeedService

@WebMvcTest(FeedController::class)
class FeedControllerTest : WebMvcTestSpec() {

@MockkBean
private lateinit var feedService: FeedService
class FeedControllerTest : WebMvcTestAdapter() {

init {
"팔로워들의 최신 리뷰들을 가져온다" {
Expand Down Expand Up @@ -52,22 +44,25 @@ class FeedControllerTest : WebMvcTestSpec() {
review9.addImage(reviewImage9Of1)
val reviews = listOf(review1, review2, review3, review4, review5, review6, review7, review8, review9)

every { feedService.getReviewFeeds(MOCK_MVC_USER_ID, 7L, limit = 3L) } returns FeedWithPagination(feeds = reviews.map {
FeedInfo(
member = FeedMember(createMember()),
cafe = FeedCafe(createCafe()),
review = FeedReview(
id = it.id,
finalScore = it.finalScore.score,
images = it.images.map(::FeedImage),
keyword = it.cafeKeywords.map(::FeedKeyword),
likeCount = it.likeCount,
description = "친절한 카페",
commentCount = 0,
createdAt = it.createdAt
every { feedService.getReviewFeeds(MOCK_MVC_USER_ID, 7L, limit = 3L) } returns FeedWithPagination(
feeds = reviews.map {
FeedInfo(
member = FeedMember(createMember()),
cafe = FeedCafe(createCafe()),
review = FeedReview(
id = it.id,
finalScore = it.finalScore.score,
images = it.images.map(::FeedImage),
keyword = it.cafeKeywords.map(::FeedKeyword),
likeCount = it.likeCount,
description = "친절한 카페",
commentCount = 0,
createdAt = it.createdAt
)
)
)
}, isLastPage = true)
},
isLastPage = true
)

val response = mockMvc.perform(
get("/feeds/review")
Expand Down Expand Up @@ -105,7 +100,7 @@ class FeedControllerTest : WebMvcTestSpec() {
"feeds[].review.keyword" type ARRAY means "리뷰에 있는 키워드 목록" example "친절한 카페네요~ 커피도 맛있어요!",
"feeds[].review.description" type STRING means "리뷰 내용",
"feeds[].review.commentCount" type NUMBER means "리뷰 댓글 개수" example "3L",
"feeds[].review.createdAt" type DATETIME means "리뷰가 작성된 시간" formattedAs "yyyy-MM-dd HH:mm:ss" example "2022-02-12 13:52:12",
"feeds[].review.createdAt" type DATETIME means "리뷰가 작성된 시간" formattedAs "yyyy-MM-dd HH:mm:ss" example "2022-02-12 13:52:12"
)
)
)
Expand Down
13 changes: 3 additions & 10 deletions src/test/kotlin/zip/cafe/api/FootPrintControllerTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package zip.cafe.api

import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.test.web.servlet.post
import zip.cafe.api.dto.FootPrintRegisterRequest
Expand All @@ -11,18 +9,13 @@ import zip.cafe.api.dto.ReviewRegisterFromFootprintRequest.FoodInfo
import zip.cafe.api.utils.mockmvc.documentWithHandle
import zip.cafe.api.utils.mockmvc.postWithPathParameter
import zip.cafe.api.utils.restdocs.*
import zip.cafe.api.utils.spec.WebMvcTestSpec
import zip.cafe.config.formatAsDefault
import zip.cafe.entity.Food
import zip.cafe.entity.review.Purpose
import zip.cafe.seeds.MOCK_MVC_USER_ID
import zip.cafe.service.ReviewService
import java.time.LocalDate

@WebMvcTest(FootPrintController::class)
class FootPrintControllerTest : WebMvcTestSpec() {
@MockkBean
private lateinit var reviewService: ReviewService
class FootPrintControllerTest : WebMvcTestAdapter() {

init {
"발자국 등록" {
Expand Down Expand Up @@ -85,7 +78,7 @@ class FootPrintControllerTest : WebMvcTestSpec() {
keywords = keywords,
reviewImageIds = reviewImageIds,
description = description,
finalScore = finalScore,
finalScore = finalScore
)

every { reviewService.createReview(footprintId, memberId, request.toDto()) } returns reviewId
Expand All @@ -112,7 +105,7 @@ class FootPrintControllerTest : WebMvcTestSpec() {
"keywords" type ARRAY means "키워드 API에서 내려준 키워드 Id 리스트" example "[1, 2]",
"reviewImageIds" type ARRAY means "업로드한 리뷰 이미지 Id 리스트" example "[3, 5, 6]",
"description" type STRING means "리뷰 내용" example "커피도 맛있고 친절한 카페",
"finalScore" type NUMBER means "최종 리뷰 점수" example "4",
"finalScore" type NUMBER means "최종 리뷰 점수" example "4"
)
)
}
Expand Down
11 changes: 2 additions & 9 deletions src/test/kotlin/zip/cafe/api/KeywordControllerTest.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package zip.cafe.api

import com.ninjasquad.springmockk.MockkBean
import io.mockk.every
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.test.web.servlet.get
import zip.cafe.api.utils.mockmvc.documentWithHandle
import zip.cafe.api.utils.restdocs.*
import zip.cafe.api.utils.spec.WebMvcTestSpec
import zip.cafe.entity.review.CafeKeyword
import zip.cafe.service.KeywordService

@WebMvcTest(KeywordController::class)
class KeywordControllerTest : WebMvcTestSpec() {
@MockkBean
private lateinit var keywordService: KeywordService
class KeywordControllerTest : WebMvcTestAdapter() {

init {
"GET 키워드 목록" {
Expand All @@ -34,7 +27,7 @@ class KeywordControllerTest : WebMvcTestSpec() {
"body" beneathPathWithSubsectionId "body",
"id" type NUMBER means "키워드 id",
"keyword" type STRING means "키워드 이름" example "아늑한",
"emoji" type STRING means "키워드 이모지" example "🤷‍♂️",
"emoji" type STRING means "키워드 이모지" example "🤷‍♂️"
)
)
}
Expand Down
22 changes: 7 additions & 15 deletions src/test/kotlin/zip/cafe/api/MemberControllerTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package zip.cafe.api

import com.ninjasquad.springmockk.MockkBean
import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.http.MediaType
import org.springframework.mock.web.MockMultipartFile
import org.springframework.restdocs.request.RequestDocumentation
Expand All @@ -13,17 +11,11 @@ import org.springframework.test.web.servlet.post
import zip.cafe.api.profile.dto.InitProfileRequest
import zip.cafe.api.utils.mockmvc.documentWithHandle
import zip.cafe.api.utils.restdocs.*
import zip.cafe.api.utils.spec.WebMvcTestSpec
import zip.cafe.connector.dto.S3FileDto
import zip.cafe.seeds.MOCK_MVC_USER_ID
import zip.cafe.seeds.createProfileImage
import zip.cafe.service.MemberService

@WebMvcTest(MemberController::class)
class MemberControllerTest : WebMvcTestSpec() {

@MockkBean
private lateinit var memberService: MemberService
class MemberControllerTest : WebMvcTestAdapter() {

init {
"닉네임 중복 체크" {
Expand All @@ -41,7 +33,7 @@ class MemberControllerTest : WebMvcTestSpec() {
documentWithHandle(
"nickname-duplicate-check",
requestParameters(
"nickname" means "닉네임" example nickname,
"nickname" means "닉네임" example nickname
),
responseBody(
"body" beneathPathWithSubsectionId "body",
Expand Down Expand Up @@ -83,7 +75,7 @@ class MemberControllerTest : WebMvcTestSpec() {
responseBody(
"body" beneathPathWithSubsectionId "body",
"id" type NUMBER means "이미지 id" example "3",
"url" type STRING means "이미지 주소" example "https://techblog.woowahan.com/wp-content/uploads/img/2020-05-13/rest-docs-09.png",
"url" type STRING means "이미지 주소" example "https://techblog.woowahan.com/wp-content/uploads/img/2020-05-13/rest-docs-09.png"
)
)
}
Expand All @@ -109,10 +101,10 @@ class MemberControllerTest : WebMvcTestSpec() {
"init-profile",
requestFields(
"nickname" type STRING means "닉네임" example nickname,
"imageId" type NUMBER means "프로필 이미지 Id" example imageId,
"imageId" type NUMBER means "프로필 이미지 Id" example imageId
),
responseBody(
"body" beneathPathWithSubsectionId "body",
"body" beneathPathWithSubsectionId "body"
)
)
}
Expand All @@ -138,10 +130,10 @@ class MemberControllerTest : WebMvcTestSpec() {
"edit-profile",
requestFields(
"nickname" type STRING means "닉네임" example nickname,
"imageId" type NUMBER means "프로필 이미지 Id" example imageId,
"imageId" type NUMBER means "프로필 이미지 Id" example imageId
),
responseBody(
"body" beneathPathWithSubsectionId "body",
"body" beneathPathWithSubsectionId "body"
)
)
}
Expand Down
11 changes: 1 addition & 10 deletions src/test/kotlin/zip/cafe/api/MemberFollowControllerTest.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
package zip.cafe.api

import com.ninjasquad.springmockk.MockkBean
import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import zip.cafe.api.utils.mockmvc.documentWithHandle
import zip.cafe.api.utils.mockmvc.postWithPathParameter
import zip.cafe.api.utils.restdocs.means
import zip.cafe.api.utils.restdocs.pathParameters
import zip.cafe.api.utils.spec.WebMvcTestSpec
import zip.cafe.seeds.MOCK_MVC_USER_ID
import zip.cafe.service.MemberFollowService

@WebMvcTest(MemberFollowController::class)
class MemberFollowControllerTest : WebMvcTestSpec() {

@MockkBean
private lateinit var memberFollowService: MemberFollowService

class MemberFollowControllerTest : WebMvcTestAdapter() {
init {
"유저를 팔로우한다" {
val fromMemberId = MOCK_MVC_USER_ID
Expand Down
Loading

0 comments on commit 2086314

Please sign in to comment.