Skip to content

Commit

Permalink
[KAN-104] 음식점 통합테스트 추가 - 음식점 상세 조회 테스트코드 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok authored May 27, 2024
1 parent 4e80762 commit 44be743
Showing 1 changed file with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.restaurant.be.common.util.setUpUser
import com.restaurant.be.restaurant.domain.entity.Category
import com.restaurant.be.restaurant.domain.entity.RestaurantCategory
import com.restaurant.be.restaurant.domain.entity.RestaurantLike
import com.restaurant.be.restaurant.presentation.controller.dto.GetRestaurantResponse
import com.restaurant.be.restaurant.presentation.controller.dto.GetRestaurantsResponse
import com.restaurant.be.restaurant.presentation.controller.dto.common.RestaurantDto
import com.restaurant.be.restaurant.repository.CategoryRepository
Expand Down Expand Up @@ -2057,5 +2058,134 @@ class GetRestaurantControllerTest(
actualResult.data!!.restaurants.content[1].name shouldBe "목구멍 율전점1"
}
}

describe("#get restaurant test") {
it("when restaurant exist should return restaurant") {
// given
val restaurantEntity = RestaurantUtil.generateRestaurantEntity(
name = "목구멍 율전점"
)
restaurantRepository.save(restaurantEntity)
val restaurantDocument = RestaurantUtil.generateRestaurantDocument(
id = restaurantEntity.id,
name = "목구멍 율전점"
)
elasticsearchTemplate.save(restaurantDocument)
elasticsearchTemplate.indexOps(RestaurantDocument::class.java).refresh()

// when
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.name shouldBe "목구멍 율전점"
}

it("when restaurant not exist should return empty") {
// given
// when
val result = mockMvc.perform(
get("$restaurantUrl/1")
)
.also {
println(it.andReturn().response.contentAsString)
}
.andExpect(status().isNotFound)
.andExpect(jsonPath("$.result").value("FAIL"))
.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 shouldBe null
actualResult.message shouldBe "해당 식당 정보가 존재하지 않습니다."
}

it("when liked restaurant should return liked true") {
// given
val user = userRepository.findByEmail("[email protected]")
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 44be743

Please sign in to comment.