Skip to content

Commit

Permalink
[KAN-000] 음식점 중복 데이터 발생 해소 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkyoungdeok authored Jun 3, 2024
1 parent 1fe411b commit 3e3da97
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class RestaurantRepositoryCustomImpl(
.where(restaurantCategory.restaurantId.`in`(restaurantIds))
.fetch()

val restaurantDtos = restaurantInfos.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 = "test2@gmail.com",
profileImageUrl = "test"
)
)
val originalUser = userRepository.findByEmail("test@gmail.com")!!

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 3e3da97

Please sign in to comment.