From 71492f45fee9d6c0404607cf4822af3e174bd20f Mon Sep 17 00:00:00 2001 From: sinkyoungdeok Date: Tue, 28 May 2024 23:02:47 +0900 Subject: [PATCH] =?UTF-8?q?[KAN-104]=20=EC=9D=8C=EC=8B=9D=EC=A0=90=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20=EC=98=A4=EB=8A=98=EC=9D=98=ED=94=BD=20API=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20+=20?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecommendRestaurantControllerTest.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/kotlin/com/restaurant/be/restaurant/presentation/controller/RecommendRestaurantControllerTest.kt b/src/test/kotlin/com/restaurant/be/restaurant/presentation/controller/RecommendRestaurantControllerTest.kt index 11e3996..a5599e1 100644 --- a/src/test/kotlin/com/restaurant/be/restaurant/presentation/controller/RecommendRestaurantControllerTest.kt +++ b/src/test/kotlin/com/restaurant/be/restaurant/presentation/controller/RecommendRestaurantControllerTest.kt @@ -165,6 +165,44 @@ class RecommendRestaurantControllerTest( // then actualResult.data!!.restaurants.size shouldBe 3 } + + it("when no restaurant saved in redis should recommended 5 restaurants") { + // given + val restaurantIds = (1..5).map { i -> + val restaurant = restaurantRepository.save( + RestaurantUtil.generateRestaurantEntity( + name = "restaurant$i" + ) + ) + + restaurant.id + } + + val key = "RECOMMENDATION:0" + redisTemplate.opsForValue().set(key, restaurantIds.joinToString(",")) + + // when + val result = mockMvc.perform( + MockMvcRequestBuilders.get(baseUrl) + ).also { + println(it.andReturn().response.contentAsString) + } + .andExpect(MockMvcResultMatchers.status().isOk) + .andExpect(MockMvcResultMatchers.jsonPath("$.result").value("SUCCESS")) + .andReturn() + + val responseContent = result.response.getContentAsString(Charset.forName("UTF-8")) + val responseType = + object : TypeReference>() {} + val actualResult: CommonResponse = + objectMapper.readValue( + responseContent, + responseType + ) + + // then + actualResult.data!!.restaurants.size shouldBe 5 + } } } }