Skip to content

Commit

Permalink
[KAN-104] 음식점 통합테스트 추가 - 음식점 상세 조회 테스트코드
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok committed May 27, 2024
1 parent 9790154 commit 8bdaf4d
Showing 1 changed file with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,8 @@ class GetRestaurantControllerTest(
.andReturn()

val responseContent = result.response.getContentAsString(Charset.forName("UTF-8"))
val responseType = object : TypeReference<CommonResponse<GetRestaurantResponse>>() {}
val responseType =
object : TypeReference<CommonResponse<GetRestaurantResponse>>() {}
val actualResult: CommonResponse<GetRestaurantResponse> = objectMapper.readValue(
responseContent,
responseType
Expand All @@ -2109,7 +2110,8 @@ class GetRestaurantControllerTest(
.andReturn()

val responseContent = result.response.getContentAsString(Charset.forName("UTF-8"))
val responseType = object : TypeReference<CommonResponse<GetRestaurantResponse>>() {}
val responseType =
object : TypeReference<CommonResponse<GetRestaurantResponse>>() {}
val actualResult: CommonResponse<GetRestaurantResponse> = objectMapper.readValue(
responseContent,
responseType
Expand All @@ -2119,6 +2121,71 @@ class GetRestaurantControllerTest(
actualResult.data shouldBe null
actualResult.message shouldBe "해당 식당 정보가 존재하지 않습니다."
}

it("when liked restaurant should return liked true") {
// given
val user = userRepository.findByEmail("test@gmail.com")
val restaurantEntity = RestaurantUtil.generateRestaurantEntity(
name = "목구멍 율전점"
)
restaurantRepository.save(restaurantEntity)
restaurantLikeRepository.save(
RestaurantLike(
userId = user?.id ?: 0,
restaurantId = restaurantEntity.id
)
)

val result = mockMvc.perform(
get("$restaurantUrl/${restaurantEntity.id}")
)
.also {
println(it.andReturn().response.contentAsString)
}
.andExpect(status().isOk)
.andExpect(jsonPath("$.result").value("SUCCESS"))
.andReturn()

val responseContent = result.response.getContentAsString(Charset.forName("UTF-8"))
val responseType =
object : TypeReference<CommonResponse<GetRestaurantResponse>>() {}
val actualResult: CommonResponse<GetRestaurantResponse> = objectMapper.readValue(
responseContent,
responseType
)

// then
actualResult.data!!.restaurant.isLike shouldBe true
}

it("when not liked restaurant should return liked false") {
// given
val restaurantEntity = RestaurantUtil.generateRestaurantEntity(
name = "목구멍 율전점"
)
restaurantRepository.save(restaurantEntity)

val result = mockMvc.perform(
get("$restaurantUrl/${restaurantEntity.id}")
)
.also {
println(it.andReturn().response.contentAsString)
}
.andExpect(status().isOk)
.andExpect(jsonPath("$.result").value("SUCCESS"))
.andReturn()

val responseContent = result.response.getContentAsString(Charset.forName("UTF-8"))
val responseType =
object : TypeReference<CommonResponse<GetRestaurantResponse>>() {}
val actualResult: CommonResponse<GetRestaurantResponse> = objectMapper.readValue(
responseContent,
responseType
)

// then
actualResult.data!!.restaurant.isLike shouldBe false
}
}
}
}

0 comments on commit 8bdaf4d

Please sign in to comment.