diff --git a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt index 18302c2..48b5d81 100644 --- a/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt +++ b/src/test/kotlin/org/store/clothstar/order/OrderIntegrationTest.kt @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.MediaType -import org.springframework.test.annotation.DirtiesContext import org.springframework.test.context.ActiveProfiles import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.ResultActions @@ -26,12 +25,12 @@ import org.store.clothstar.order.repository.OrderRepository import org.store.clothstar.order.util.CreateOrderObject import org.store.clothstar.product.repository.ItemRepository import org.store.clothstar.product.repository.ProductRepository +import org.store.clothstar.member.domain.Member @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles("test") @Transactional -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) class OrderIntegrationTest( @Autowired private val mockMvc: MockMvc, @@ -65,31 +64,30 @@ class OrderIntegrationTest( @DisplayName("단일 주문 조회 통합테스트") @Test fun testGetOrder() { - //given - memberRepository.save(CreateOrderObject.getMember()) - addressRepository.save(CreateOrderObject.getAddress()) - categoryRepository.save(CreateOrderObject.getCategory()) - sellerRepository.save(CreateOrderObject.getSeller()) - productRepository.save(CreateOrderObject.getProduct()) - itemRepository.save(CreateOrderObject.getItem()) + //given + val member: Member = memberRepository.save(CreateOrderObject.getMember()) + val address = addressRepository.save(CreateOrderObject.getAddress(member)) + val category = categoryRepository.save(CreateOrderObject.getCategory()) + sellerRepository.save(CreateOrderObject.getSeller(member)) + val product = productRepository.save(CreateOrderObject.getProduct(member, category)) + val item = itemRepository.save(CreateOrderObject.getItem(product)) - val order: Order = CreateOrderObject.getOrder() - orderRepository.save(order) - val orderDetail: OrderDetail = orderDetailRepository.save(CreateOrderObject.getOrderDetail()) - order.addOrderDetail(orderDetail) - orderRepository.save(order) + val order: Order = orderRepository.save(CreateOrderObject.getOrder(member, address)) + val orderDetail: OrderDetail = orderDetailRepository.save(CreateOrderObject.getOrderDetail(product, item, order)) + order.addOrderDetail(orderDetail) - val orderId: String = order.orderId - val getOrderURL: String = ORDER_URL + "/" + orderId + val orderId: String = order.orderId + val getOrderURL: String = ORDER_URL + "/" + orderId - //when - val actions: ResultActions = mockMvc.perform( - MockMvcRequestBuilders.get(getOrderURL) - .contentType(MediaType.APPLICATION_JSON) - ) + //when + val actions: ResultActions = mockMvc.perform( + MockMvcRequestBuilders.get(getOrderURL) + .contentType(MediaType.APPLICATION_JSON) + ) - //then - actions.andExpect(status().isOk) - .andExpect(jsonPath("$.orderId").value(orderId)) + //then + actions + .andExpect(status().isOk) + .andExpect(jsonPath("$.orderId").value(orderId)) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/org/store/clothstar/order/util/CreateOrderObject.kt b/src/test/kotlin/org/store/clothstar/order/util/CreateOrderObject.kt index 5a0e711..98b7305 100644 --- a/src/test/kotlin/org/store/clothstar/order/util/CreateOrderObject.kt +++ b/src/test/kotlin/org/store/clothstar/order/util/CreateOrderObject.kt @@ -21,27 +21,25 @@ class CreateOrderObject { companion object { fun getMember(): Member { return Member( - memberId = 1L, telNo = "010-1234-4444", name = "현수", memberShoppingActivity = MemberShoppingActivity.init() ) } - fun getAddress(): Address { + fun getAddress(member: Member): Address { return Address( - addressId = 1L, receiverName = "현수", telNo = "010-1234-4444", - memberId = this.getMember().memberId!!, + memberId = member.memberId!!, deliveryRequest = "문 앞에 놔주세요", addressInfo = AddressInfo.init() ) } - fun getSeller(): Seller { + fun getSeller(member: Member): Seller { return Seller( - memberId = this.getMember().memberId!!, + memberId = member.memberId!!, brandName = "나이키", bizNo = "123-123", totalSellPrice = 1000 @@ -50,16 +48,14 @@ class CreateOrderObject { fun getCategory(): Category { return Category( - categoryId = 1L, categoryType = "상의", ) } - fun getProduct(): Product { + fun getProduct(member: Member,category: Category): Product { return Product( - productId = 1L, - memberId = this.getMember().memberId!!, - categoryId = getCategory().categoryId!!, + memberId = member.memberId!!, + categoryId = category.categoryId!!, name = "상품", content = "상품내용", price = 1000, @@ -69,40 +65,38 @@ class CreateOrderObject { ) } - fun getItem(): Item { + fun getItem(product: Product): Item { return Item( - itemId = 1L, name = "상품 옵션 이름", finalPrice = 2000, stock = 10, saleStatus = SaleStatus.ALL, displayStatus = DisplayStatus.HIDDEN, - product = getProduct() + product = product ) } - fun getOrder(): Order { + fun getOrder(member: Member,address: Address): Order { return Order( orderId = "0eb44b79-6b9a-4ca9-8984-761e18101511", - memberId = this.getMember().memberId!!, - addressId = this.getAddress().addressId!!, + memberId = member.memberId!!, + addressId = address.addressId!!, status = Status.CONFIRMED, paymentMethod = PaymentMethod.CARD, totalPrice = TotalPrice(shipping = 0, products = 0, payment = 0) ) } - fun getOrderDetail(): OrderDetail { + fun getOrderDetail(product: Product,item: Item,order: Order): OrderDetail { return OrderDetail( - orderDetailId = 1L, - productId = getProduct().productId!!, - itemId = getItem().itemId!!, + productId = product.productId!!, + itemId = item.itemId!!, quantity = 1, price = Price( - fixedPrice = getProduct().price, + fixedPrice = product.price, oneKindTotalPrice = 10000 ), - order = getOrder() + order = order ) } }