forked from prgrms-be-devcourse/BE-04-NaBMart
-
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 #1 from pushedrumex/refactor
refactor: 주문 스케줄러 리팩토링
- Loading branch information
Showing
6 changed files
with
89 additions
and
17 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/main/java/com/prgrms/nabmart/domain/order/service/OrderCancelService.java
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,26 @@ | ||
package com.prgrms.nabmart.domain.order.service; | ||
|
||
import com.prgrms.nabmart.domain.item.repository.ItemRepository; | ||
import com.prgrms.nabmart.domain.order.Order; | ||
import com.prgrms.nabmart.domain.order.OrderStatus; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class OrderCancelService { | ||
|
||
private final ItemRepository itemRepository; | ||
|
||
@Transactional | ||
public void cancelOrder(Order order) { | ||
order.updateOrderStatus(OrderStatus.CANCELED); | ||
order.unUseCoupon(); | ||
order.getOrderItems().forEach( | ||
orderItem -> itemRepository.increaseQuantity(orderItem.getItem().getItemId(), | ||
orderItem.getQuantity()) | ||
); | ||
} | ||
|
||
} |
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
51 changes: 51 additions & 0 deletions
51
src/test/java/com/prgrms/nabmart/domain/order/service/OrderCancelServiceTest.java
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,51 @@ | ||
package com.prgrms.nabmart.domain.order.service; | ||
|
||
import static com.prgrms.nabmart.domain.order.support.OrderFixture.pendingOrder; | ||
import static com.prgrms.nabmart.domain.user.support.UserFixture.user; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import com.prgrms.nabmart.domain.item.repository.ItemRepository; | ||
import com.prgrms.nabmart.domain.order.Order; | ||
import com.prgrms.nabmart.domain.order.OrderItem; | ||
import com.prgrms.nabmart.domain.order.OrderStatus; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class OrderCancelServiceTest { | ||
|
||
@InjectMocks | ||
OrderCancelService orderCancelService; | ||
|
||
@Mock | ||
ItemRepository itemRepository; | ||
|
||
@Nested | ||
@DisplayName("cancelOrder 메서드 실행 시") | ||
class CancelOrderTest { | ||
|
||
@Test | ||
@DisplayName("성공") | ||
void success() { | ||
// given | ||
Order order = pendingOrder(1L, user()); | ||
OrderItem orderItem = order.getOrderItems().get(0); | ||
|
||
// when | ||
orderCancelService.cancelOrder(order); | ||
|
||
// then | ||
assertThat(order.getStatus()).isEqualTo(OrderStatus.CANCELED); | ||
verify(itemRepository, times(1)).increaseQuantity(orderItem.getItem().getItemId(), | ||
orderItem.getQuantity()); | ||
} | ||
} | ||
|
||
} |
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