-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from le2sky/develop
[๋ฐฐํฌ] v0.3.0(PR#55, PR#57)
- Loading branch information
Showing
18 changed files
with
365 additions
and
13 deletions.
There are no files selected for viewing
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
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
19 changes: 19 additions & 0 deletions
19
.../src/main/kotlin/com/mealkitary/reservation/adapter/input/web/GetReservationController.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,19 @@ | ||
package com.mealkitary.reservation.adapter.input.web | ||
|
||
import com.mealkitary.common.utils.UUIDUtils | ||
import com.mealkitary.reservation.application.port.input.GetReservationQuery | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/reservations") | ||
class GetReservationController( | ||
private val getReservationQuery: GetReservationQuery | ||
) { | ||
|
||
@GetMapping("/{reservationId}") | ||
fun getOneReservation(@PathVariable("reservationId") reservationId: String) = | ||
getReservationQuery.loadOneReservationById(UUIDUtils.fromString(reservationId)) | ||
} |
88 changes: 88 additions & 0 deletions
88
mealkitary-api/src/test/kotlin/com/docs/reservation/GetReservationControllerDocsTest.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,88 @@ | ||
package com.docs.reservation | ||
|
||
import com.docs.RestDocsSupport | ||
import com.mealkitary.reservation.adapter.input.web.GetReservationController | ||
import com.mealkitary.reservation.application.port.input.GetReservationQuery | ||
import com.mealkitary.reservation.application.port.input.ReservationResponse | ||
import com.mealkitary.reservation.application.port.input.ReservedProduct | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.springframework.http.MediaType | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document | ||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders | ||
import org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest | ||
import org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse | ||
import org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint | ||
import org.springframework.restdocs.payload.JsonFieldType | ||
import org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath | ||
import org.springframework.restdocs.payload.PayloadDocumentation.responseFields | ||
import org.springframework.restdocs.request.RequestDocumentation.parameterWithName | ||
import org.springframework.restdocs.request.RequestDocumentation.pathParameters | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
class GetReservationControllerDocsTest : RestDocsSupport() { | ||
|
||
private val getReservationQuery = mockk<GetReservationQuery>() | ||
|
||
@Test | ||
fun `api docs test - getOneReservation`() { | ||
val reservationId = UUID.randomUUID() | ||
val reserveAt = LocalDateTime.now() | ||
every { getReservationQuery.loadOneReservationById(reservationId) } answers { | ||
ReservationResponse( | ||
reservationId, | ||
"์ง๋ฐฅ๋๋ฑ ์์์ ", | ||
"๋ถ๋์ฐ๊ฐ ์ธ 1๊ฑด", | ||
reserveAt, | ||
"PAID", | ||
listOf( | ||
ReservedProduct( | ||
1L, | ||
"๋ถ๋์ฐ๊ฐ", | ||
20000, | ||
2 | ||
), | ||
ReservedProduct( | ||
2L, | ||
"๊น์น์ฐ๊ฐ", | ||
20000, | ||
1 | ||
) | ||
) | ||
) | ||
} | ||
|
||
mvc.perform(RestDocumentationRequestBuilders.get("/reservations/{reservationId}", reservationId)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andDo( | ||
document( | ||
"reservation-get", | ||
preprocessRequest(prettyPrint()), | ||
preprocessResponse(prettyPrint()), | ||
pathParameters( | ||
parameterWithName("reservationId").description("์กฐํ ๋์ ์์ฝ์ ์๋ณ์") | ||
), | ||
responseFields( | ||
fieldWithPath("reservationId").type(JsonFieldType.STRING).description("์์ฝ ์๋ณ์"), | ||
fieldWithPath("shopName").type(JsonFieldType.STRING).description("์์ฝ ๋์ ๊ฐ๊ฒ์ ์ด๋ฆ"), | ||
fieldWithPath("description").type(JsonFieldType.STRING).description("์์ฝ ๊ฐ์"), | ||
fieldWithPath("reserveAt").type(JsonFieldType.STRING).description("์์ฝ ์๊ฐ(yyyy-mm-ddThh:mm:ss)"), | ||
fieldWithPath("status").type(JsonFieldType.STRING).description("์์ฝ ์ํ"), | ||
fieldWithPath("reservedProduct.[].productId").type(JsonFieldType.NUMBER) | ||
.description("์์ฝ ์ํ ์๋ณ์"), | ||
fieldWithPath("reservedProduct.[].name").type(JsonFieldType.STRING) | ||
.description("์์ฝ ์ํ๋ช "), | ||
fieldWithPath("reservedProduct.[].price").type(JsonFieldType.NUMBER) | ||
.description("์์ฝ ์ํ ๊ฐ๊ฒฉ"), | ||
fieldWithPath("reservedProduct.[].count").type(JsonFieldType.NUMBER).description("์์ฝ ์๋") | ||
) | ||
) | ||
) | ||
} | ||
|
||
override fun initController() = GetReservationController(getReservationQuery) | ||
} |
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
84 changes: 84 additions & 0 deletions
84
.../test/kotlin/com/mealkitary/reservation/adapter/input/web/GetReservationControllerTest.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,84 @@ | ||
package com.mealkitary.reservation.adapter.input.web | ||
|
||
import com.mealkitary.WebIntegrationTestSupport | ||
import com.mealkitary.common.exception.EntityNotFoundException | ||
import com.mealkitary.reservation.application.port.input.ReservationResponse | ||
import com.mealkitary.reservation.application.port.input.ReservedProduct | ||
import io.mockk.every | ||
import org.springframework.http.MediaType | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
class GetReservationControllerTest : WebIntegrationTestSupport() { | ||
|
||
@Test | ||
fun `api integration test - getOneReservation`() { | ||
val reservationId = UUID.randomUUID() | ||
val reserveAt = LocalDateTime.now() | ||
every { getReservationQuery.loadOneReservationById(reservationId) } answers { | ||
ReservationResponse( | ||
reservationId, | ||
"์ง๋ฐฅ๋๋ฑ ์์์ ", | ||
"๋ถ๋์ฐ๊ฐ ์ธ 1๊ฑด", | ||
reserveAt, | ||
"PAID", | ||
listOf( | ||
ReservedProduct( | ||
1L, | ||
"๋ถ๋์ฐ๊ฐ", | ||
20000, | ||
2 | ||
), | ||
ReservedProduct( | ||
2L, | ||
"๊น์น์ฐ๊ฐ", | ||
20000, | ||
1 | ||
) | ||
) | ||
) | ||
} | ||
|
||
mvc.perform(get("/reservations/{reservationId}", reservationId)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.reservationId").value(reservationId.toString())) | ||
.andExpect(jsonPath("$.shopName").value("์ง๋ฐฅ๋๋ฑ ์์์ ")) | ||
.andExpect(jsonPath("$.reserveAt").value(reserveAt.toString())) | ||
.andExpect(jsonPath("$.status").value("PAID")) | ||
.andExpect(jsonPath("$.reservedProduct[0].productId").value(1L)) | ||
.andExpect(jsonPath("$.reservedProduct[0].name").value("๋ถ๋์ฐ๊ฐ")) | ||
.andExpect(jsonPath("$.reservedProduct[0].price").value(20000)) | ||
.andExpect(jsonPath("$.reservedProduct[0].count").value(2)) | ||
.andExpect(jsonPath("$.reservedProduct[1].productId").value(2L)) | ||
.andExpect(jsonPath("$.reservedProduct[1].name").value("๊น์น์ฐ๊ฐ")) | ||
.andExpect(jsonPath("$.reservedProduct[1].price").value(20000)) | ||
.andExpect(jsonPath("$.reservedProduct[1].count").value(1)) | ||
} | ||
|
||
@Test | ||
fun `api integration test - ์์ฝ ์๋ณ์๊ฐ UUID ํํ๊ฐ ์๋๋ผ๋ฉด 400 ์๋ฌ๋ฅผ ๋ฐ์ํ๋ค`() { | ||
mvc.perform( | ||
get("/reservations/{reservationId}", "invalid-uuid-test") | ||
) | ||
.andExpect(status().isBadRequest) | ||
.andExpect(jsonPath("$.status").value("400")) | ||
.andExpect(jsonPath("$.message").value("์๋ชป๋ UUID ํ์์ ๋๋ค.")) | ||
} | ||
|
||
@Test | ||
fun `api integration test - ๋ด๋ถ์์ EntityNotFound ์๋ฌ๊ฐ ๋ฐ์ํ๋ฉด 404 ์๋ฌ๋ฅผ ๋ฐ์ํ๋ค`() { | ||
every { getReservationQuery.loadOneReservationById(any()) } | ||
.throws(EntityNotFoundException("์กด์ฌํ์ง ์๋ ์์ฝ์ ๋๋ค.")) | ||
|
||
mvc.perform(get("/reservations/{reservationId}", UUID.randomUUID())) | ||
.andExpect(status().isNotFound()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.status").value(404)) | ||
.andExpect(jsonPath("$.message").value("์กด์ฌํ์ง ์๋ ์์ฝ์ ๋๋ค.")) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
.../src/main/kotlin/com/mealkitary/reservation/application/port/input/GetReservationQuery.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,8 @@ | ||
package com.mealkitary.reservation.application.port.input | ||
|
||
import java.util.UUID | ||
|
||
interface GetReservationQuery { | ||
|
||
fun loadOneReservationById(reservationId: UUID): ReservationResponse | ||
} |
13 changes: 13 additions & 0 deletions
13
.../src/main/kotlin/com/mealkitary/reservation/application/port/input/ReservationResponse.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,13 @@ | ||
package com.mealkitary.reservation.application.port.input | ||
|
||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
data class ReservationResponse( | ||
val reservationId: UUID, | ||
val shopName: String, | ||
val description: String, | ||
val reserveAt: LocalDateTime, | ||
val status: String, | ||
val reservedProduct: List<ReservedProduct> | ||
) |
3 changes: 3 additions & 0 deletions
3
...src/main/kotlin/com/mealkitary/reservation/application/port/output/LoadReservationPort.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,9 +1,12 @@ | ||
package com.mealkitary.reservation.application.port.output | ||
|
||
import com.mealkitary.reservation.application.port.input.ReservationResponse | ||
import com.mealkitary.reservation.domain.reservation.Reservation | ||
import java.util.UUID | ||
|
||
interface LoadReservationPort { | ||
|
||
fun loadOneReservationById(reservationId: UUID): Reservation | ||
|
||
fun queryOneReservationById(reservationId: UUID): ReservationResponse | ||
} |
17 changes: 17 additions & 0 deletions
17
...n/src/main/kotlin/com/mealkitary/reservation/application/service/GetReservationService.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,17 @@ | ||
package com.mealkitary.reservation.application.service | ||
|
||
import com.mealkitary.reservation.application.port.input.GetReservationQuery | ||
import com.mealkitary.reservation.application.port.output.LoadReservationPort | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.util.UUID | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class GetReservationService( | ||
private val loadReservationPort: LoadReservationPort | ||
) : GetReservationQuery { | ||
|
||
override fun loadOneReservationById(reservationId: UUID) = | ||
loadReservationPort.queryOneReservationById(reservationId) | ||
} |
39 changes: 39 additions & 0 deletions
39
...c/test/kotlin/com/mealkitary/reservation/application/service/GetReservationServiceTest.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,39 @@ | ||
package com.mealkitary.reservation.application.service | ||
|
||
import com.mealkitary.reservation.application.port.input.ReservationResponse | ||
import com.mealkitary.reservation.application.port.output.LoadReservationPort | ||
import io.kotest.core.spec.style.AnnotationSpec | ||
import io.kotest.matchers.booleans.shouldBeTrue | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
|
||
class GetReservationServiceTest : AnnotationSpec() { | ||
|
||
private val loadReservationPort = mockk<LoadReservationPort>() | ||
private val getReservationService = GetReservationService(loadReservationPort) | ||
|
||
@Test | ||
fun `service unit test - ์์ฝ์ ์์ธ ์ ๋ณด๋ฅผ ์กฐํํ๋ค`() { | ||
val reservationId = UUID.randomUUID() | ||
every { loadReservationPort.queryOneReservationById(any()) } answers { | ||
ReservationResponse( | ||
reservationId, | ||
"์ง๋ฐฅ๋๋ฑ ์์์ ", | ||
"๋ถ๋์ฐ๊ฐ ์ธ 1๊ฑด", | ||
LocalDateTime.now(), | ||
"PAID", | ||
emptyList() | ||
) | ||
} | ||
|
||
val result = getReservationService.loadOneReservationById(reservationId) | ||
|
||
result.reservationId shouldBe reservationId | ||
result.shopName shouldBe "์ง๋ฐฅ๋๋ฑ ์์์ " | ||
result.status shouldBe "PAID" | ||
result.reservedProduct.isEmpty().shouldBeTrue() | ||
} | ||
} |
Oops, something went wrong.