Skip to content

Commit e6ed44e

Browse files
committed
test: 롤백 관련 테스트 코드 추가
1 parent 35022a4 commit e6ed44e

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

apps/commerce-api/src/test/java/com/loopers/application/order/OrderFacadeIntegrationTest.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
import org.junit.jupiter.api.Test;
2424
import org.springframework.beans.factory.annotation.Autowired;
2525
import org.springframework.boot.test.context.SpringBootTest;
26-
import org.springframework.transaction.annotation.Transactional;
2726

2827
@SpringBootTest
29-
@Transactional
3028
class OrderFacadeIntegrationTest {
3129

3230
@Autowired
@@ -54,14 +52,14 @@ class PlaceOrder {
5452
void placeOrder_success() {
5553
// arrange
5654
User user = new User("userA", "a@email.com", "2025-11-11", Gender.MALE, new Point(100000L));
57-
userRepository.save(user);
55+
User savedUser = userRepository.save(user);
5856

5957
Long brandId = 1L;
6058
Product product = new Product(brandId, "Product A", "설명", new Money(20000L), 10);
6159
Product saveProduct = productRepository.save(product);
6260

6361
Item itemCommand = new Item(saveProduct.getId(), 3);
64-
OrderCommand.PlaceOrder command = new OrderCommand.PlaceOrder(user.getId(), List.of(itemCommand));
62+
OrderCommand.PlaceOrder command = new OrderCommand.PlaceOrder(savedUser.getId(), List.of(itemCommand));
6563

6664
// act
6765
OrderInfo result = orderFacade.placeOrder(command);
@@ -122,5 +120,33 @@ void placeOrder_fail_insufficient_point() {
122120

123121
assertThat(exception.getErrorType()).isEqualTo(ErrorType.BAD_REQUEST);
124122
}
123+
124+
@DisplayName("포인트 잔액 부족으로 주문이 실패하면, 차감되었던 재고는 롤백되어 원상복구된다.")
125+
@Test
126+
void placeOrder_transaction_rollback_test() {
127+
// arrange
128+
Product product = productRepository.save(
129+
new Product(1L, "Product A", "설명", new Money(20000L), 10)
130+
);
131+
132+
User user = userRepository.save(
133+
new User("userRollback", "rollback@email.com", "2025-11-11", Gender.MALE, new Point(0L))
134+
);
135+
136+
Item itemCommand = new Item(product.getId(), 1); // 1개 주문 시도
137+
OrderCommand.PlaceOrder command = new OrderCommand.PlaceOrder(user.getId(), List.of(itemCommand));
138+
139+
// act
140+
assertThrows(CoreException.class, () -> {
141+
orderFacade.placeOrder(command);
142+
});
143+
144+
// assert
145+
Product rollbackedProduct = productRepository.findById(product.getId()).orElseThrow();
146+
147+
assertThat(rollbackedProduct.getStock()).isEqualTo(10);
148+
}
125149
}
150+
151+
126152
}

0 commit comments

Comments
 (0)