Skip to content

Commit

Permalink
refactor: 판매자 주문 승인/취소 테스트코드 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
axhtl committed Aug 5, 2024
1 parent 86f4a13 commit d5bc505
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/main/resources/order.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ INSERT INTO orders (order_id, member_id, address_id, created_at, status, total_s
VALUES ('14241232', '242', '334', CURRENT_TIMESTAMP, 'WAITING', '3000', '50000', 'CARD', '53000');

select *
from orders
from orders;

select o1_0.order_id,
o1_0.address_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.mockk.verify
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.data.repository.findByIdOrNull
import org.store.clothstar.order.domain.Order
import org.store.clothstar.order.domain.vo.Status
import org.store.clothstar.order.exception.InvalidOrderStatusException
Expand All @@ -34,14 +35,16 @@ class OrderSellerServiceTest {
//given
val orderId = 1L
every { order.status } returns Status.WAITING
every { orderRepository.findByOrderId(orderId) } returns order
every { orderRepository.findByIdOrNull(orderId) } returns order
justRun { order.validateForStatus(Status.WAITING) }
justRun { order.updateStatus(Status.APPROVE) }

//when
orderSellerService.approveOrder(orderId)

//then
verify(exactly = 1) { orderRepository.findByOrderId(orderId) }
verify(exactly = 1) { orderRepository.findByIdOrNull(orderId) }
verify(exactly = 1) { order.validateForStatus(Status.WAITING) }
verify(exactly = 1) { order.updateStatus(Status.APPROVE) }
}

Expand All @@ -51,43 +54,31 @@ class OrderSellerServiceTest {
//given
val orderId = 1L
every { order.status } returns Status.WAITING
every { orderRepository.findByOrderId(orderId) } returns null
every { orderRepository.findByIdOrNull(orderId) } returns null

//when & then
assertThrows<OrderNotFoundException> {
orderSellerService.approveOrder(orderId)
}
}

@Test
@DisplayName("판매자 주문 승인 - 주문이 '승인대기' 상태가 아닐 때 예외처리 테스트")
fun approveOrder_invalidOrderStatus_exception_test() {
//given
val orderId = 1L
every { order.status } returns Status.CONFIRM
every { orderRepository.findByOrderId(orderId) } returns order

//when & then
assertThrows<InvalidOrderStatusException> {
orderSellerService.approveOrder(orderId)
}
}

// 판매자 주문 취소 - cancelOrder
@Test
@DisplayName("판매자 주문 취소 - 메서드 호출 테스트")
fun cancelOrder_verify_test() {
//given
val orderId = 1L
every { order.status } returns Status.WAITING
every { orderRepository.findByOrderId(orderId) } returns order
every { orderRepository.findByIdOrNull(orderId) } returns order
justRun { order.validateForStatus(Status.WAITING) }
justRun { order.updateStatus(Status.CANCEL) }

//when
orderSellerService.cancelOrder(orderId)

//then
verify(exactly = 1) { orderRepository.findByOrderId(orderId) }
verify(exactly = 1) { orderRepository.findByIdOrNull(orderId) }
verify(exactly = 1) { order.validateForStatus(Status.WAITING) }
verify(exactly = 1) { order.updateStatus(Status.CANCEL) }
}

Expand All @@ -97,25 +88,11 @@ class OrderSellerServiceTest {
//given
val orderId = 1L
every { order.status } returns Status.WAITING
every { orderRepository.findByOrderId(orderId) } returns null
every { orderRepository.findByIdOrNull(orderId) } returns null

//when & then
assertThrows<OrderNotFoundException> {
orderSellerService.cancelOrder(orderId)
}
}

@Test
@DisplayName("판매자 주문 취소 - 주문이 '승인대기' 상태가 아닐 때 예외처리 테스트")
fun cancelOrder_invalidOrderStatus_exception_test() {
//given
val orderId = 1L
every { order.status } returns Status.CONFIRM
every { orderRepository.findByOrderId(orderId) } returns order

//when & then
assertThrows<InvalidOrderStatusException> {
orderSellerService.cancelOrder(orderId)
}
}
}

0 comments on commit d5bc505

Please sign in to comment.