-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAN-104] 음식점 통합테스트 추가 - 카테고리 API 패키지 잘못된부분 수정 + 테스트코드 추가
- Loading branch information
1 parent
44be743
commit f12dc76
Showing
9 changed files
with
106 additions
and
21 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...t/be/restaurant/domain/entity/Category.kt → ...ant/be/category/domain/entity/Category.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...entation/controller/dto/GetCategoryDto.kt → ...entation/controller/dto/GetCategoryDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
@file:Suppress("ktlint", "MatchingDeclarationName") | ||
|
||
package com.restaurant.be.restaurant.presentation.controller.dto | ||
package com.restaurant.be.category.presentation.controller.dto | ||
|
||
import com.restaurant.be.restaurant.presentation.controller.dto.common.CategoryDto | ||
import com.restaurant.be.category.presentation.controller.dto.common.CategoryDto | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
data class GetCategoryResponse( | ||
data class GetCategoriesResponse( | ||
@Schema(description = "카테고리 리스트") | ||
val categories: List<CategoryDto> | ||
) |
2 changes: 1 addition & 1 deletion
2
...tion/controller/dto/common/CategoryDto.kt → ...tion/controller/dto/common/CategoryDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...staurant/repository/CategoryRepository.kt → ...category/repository/CategoryRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package com.restaurant.be.restaurant.repository | ||
package com.restaurant.be.category.repository | ||
|
||
import com.restaurant.be.restaurant.domain.entity.Category | ||
import com.restaurant.be.category.domain.entity.Category | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface CategoryRepository : JpaRepository<Category, Long> |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/com/restaurant/be/restaurant/repository/dto/RestaurantProjectionDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...st/kotlin/com/restaurant/be/category/presentation/controller/GetCategoryControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.restaurant.be.category.presentation.controller | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.module.SimpleModule | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import com.restaurant.be.category.domain.entity.Category | ||
import com.restaurant.be.category.presentation.controller.dto.GetCategoriesResponse | ||
import com.restaurant.be.category.repository.CategoryRepository | ||
import com.restaurant.be.common.CustomDescribeSpec | ||
import com.restaurant.be.common.IntegrationTest | ||
import com.restaurant.be.common.PageDeserializer | ||
import com.restaurant.be.common.response.CommonResponse | ||
import com.restaurant.be.common.util.setUpUser | ||
import com.restaurant.be.restaurant.presentation.controller.dto.common.RestaurantDto | ||
import com.restaurant.be.user.repository.UserRepository | ||
import io.kotest.matchers.shouldBe | ||
import org.springframework.data.domain.Page | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.nio.charset.Charset | ||
|
||
@IntegrationTest | ||
@Transactional | ||
class GetCategoryControllerTest( | ||
private val mockMvc: MockMvc, | ||
private val userRepository: UserRepository, | ||
private val categoryRepository: CategoryRepository | ||
) : CustomDescribeSpec() { | ||
private val baseUrl = "/v1/restaurants/category" | ||
private val objectMapper: ObjectMapper = ObjectMapper().registerModule(KotlinModule()).apply { | ||
val module = SimpleModule() | ||
module.addDeserializer(Page::class.java, PageDeserializer(RestaurantDto::class.java)) | ||
this.registerModule(module) | ||
} | ||
|
||
init { | ||
beforeEach { | ||
setUpUser("test@gmail.com", userRepository) | ||
} | ||
|
||
describe("#getCategories basic test") { | ||
it("when data saved should return categories") { | ||
// given | ||
categoryRepository.saveAll( | ||
listOf( | ||
Category(name = "한식"), | ||
Category(name = "중식"), | ||
Category(name = "일식"), | ||
Category(name = "양식"), | ||
Category(name = "분식") | ||
) | ||
) | ||
|
||
// when | ||
val result = mockMvc.perform( | ||
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<CommonResponse<GetCategoriesResponse>>() {} | ||
val actualResult: CommonResponse<GetCategoriesResponse> = objectMapper.readValue( | ||
responseContent, | ||
responseType | ||
) | ||
|
||
// then | ||
actualResult.data!!.categories.size shouldBe 5 | ||
actualResult.data!!.categories[0].name shouldBe "한식" | ||
actualResult.data!!.categories[1].name shouldBe "중식" | ||
actualResult.data!!.categories[2].name shouldBe "일식" | ||
actualResult.data!!.categories[3].name shouldBe "양식" | ||
actualResult.data!!.categories[4].name shouldBe "분식" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters