Skip to content

Commit

Permalink
[KAN-000] 상황 재현 및 테스트코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok committed Jun 3, 2024
1 parent fff813f commit b8aab0b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class RestaurantRepositoryCustomImpl(
.where(restaurant.id.`in`(restaurantIds))
.leftJoin(restaurantLike).on(restaurant.id.eq(restaurantLike.restaurantId))
.orderBy(*orderSpecifier.toTypedArray())
.fetchJoin()
.offset(pageable.offset)
.limit(pageable.pageSize.toLong())
.fetch()
Expand All @@ -176,9 +177,7 @@ class RestaurantRepositoryCustomImpl(
.where(restaurantCategory.restaurantId.`in`(restaurantIds))
.fetch()

val uniqueRestaurantInfos = restaurantInfos.distinctBy { it.id }

val restaurantDtos = uniqueRestaurantInfos.map { restaurantInfo ->
val restaurantDtos = restaurantInfos.distinctBy { it.id }.map { restaurantInfo ->
val likedUserIds = restaurantIds.map { true }
val menuList = menus.filter { it.restaurantId == restaurantInfo.id }
val review = reviews.firstOrNull { it.restaurantId == restaurantInfo.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,57 @@ class LikeRestaurantControllerTest(
}
}

describe("#getMyLikeRestaurants cartesian product bug test") {
it("when two user like same restaurant should return only one") {
// given
val newUser = userRepository.save(
User(
email = "[email protected]",
profileImageUrl = "test",
)
)
val originalUser = userRepository.findByEmail("[email protected]")!!

val restaurantEntity = RestaurantUtil.generateRestaurantEntity(
name = "목구멍 율전점"
)
restaurantRepository.save(restaurantEntity)
restaurantLikeRepository.save(
RestaurantLike(
userId = originalUser.id ?: 0,
restaurantId = restaurantEntity.id
)
)
restaurantLikeRepository.save(
RestaurantLike(
userId = newUser.id ?: 0,
restaurantId = restaurantEntity.id
)
)

// when
val result = mockMvc.perform(
get("$baseUrl/my-like")
).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<GetRestaurantsResponse>>() {}
val actualResult: CommonResponse<GetRestaurantsResponse> = objectMapper.readValue(
responseContent,
responseType
)

// then
actualResult.data!!.restaurants.content.size shouldBe 1
}
}

describe("#likeRestaurant basic test") {
it("when like restaurant should success like") {
// given
Expand Down

0 comments on commit b8aab0b

Please sign in to comment.