feat: add route for retrieving a swap (#326)
* feat: swap details * test: add get-swap and list-swaps route tests * test: add swaps integration tests * fix: use IdMap.getId in complete-cart unit test commit 289d191 uses the IdMap.getId in the SwapServiceMock retrieve method, so a unit test in complete-cart needs to be adjusted accordingly * fix: prefix default fields and totals with 'cart'
This commit is contained in:
@@ -11,6 +11,7 @@ const {
|
||||
Region,
|
||||
Order,
|
||||
Swap,
|
||||
Cart,
|
||||
Return,
|
||||
} = require("@medusajs/medusa");
|
||||
|
||||
@@ -52,16 +53,64 @@ module.exports = async (connection, data = {}) => {
|
||||
|
||||
orderWithSwap = await manager.save(orderWithSwap);
|
||||
|
||||
const cart = manager.create(Cart, {
|
||||
id: "test-cart",
|
||||
customer_id: "test-customer",
|
||||
email: "test-customer@email.com",
|
||||
shipping_address_id: "test-shipping-address",
|
||||
billing_address_id: "test-billing-address",
|
||||
region_id: "test-region",
|
||||
type: "swap",
|
||||
metadata: {
|
||||
swap_id: "test-swap",
|
||||
parent_order_id: orderWithSwap.id,
|
||||
},
|
||||
});
|
||||
|
||||
await manager.save(cart);
|
||||
|
||||
const swap = manager.create(Swap, {
|
||||
id: "test-swap",
|
||||
order_id: "order-with-swap",
|
||||
payment_status: "captured",
|
||||
fulfillment_status: "fulfilled",
|
||||
cart_id: "test-cart",
|
||||
payment: {
|
||||
id: "test-payment-swap",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test",
|
||||
data: {},
|
||||
},
|
||||
additional_items: [
|
||||
{
|
||||
id: "test-item-swapped",
|
||||
fulfilled_quantity: 1,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 9000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant-2",
|
||||
cart_id: "test-cart",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await manager.save(swap);
|
||||
|
||||
const li = manager.create(LineItem, {
|
||||
id: "test-item-2",
|
||||
id: "return-item-1",
|
||||
fulfilled_quantity: 1,
|
||||
title: "Line Item",
|
||||
title: "Return Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
order_id: orderWithSwap.id,
|
||||
cart_id: cart.id,
|
||||
});
|
||||
|
||||
await manager.save(li);
|
||||
@@ -80,34 +129,30 @@ module.exports = async (connection, data = {}) => {
|
||||
|
||||
await manager.save(li2);
|
||||
|
||||
const swap = manager.create(Swap, {
|
||||
id: "test-swap",
|
||||
order_id: "order-with-swap",
|
||||
payment_status: "captured",
|
||||
fulfillment_status: "fulfilled",
|
||||
payment: {
|
||||
id: "test-payment-swap",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test",
|
||||
data: {},
|
||||
},
|
||||
additional_items: [
|
||||
{
|
||||
id: "test-item-swapped",
|
||||
fulfilled_quantity: 1,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant-2",
|
||||
},
|
||||
],
|
||||
const swapReturn = await manager.create(Return, {
|
||||
swap_id: swap.id,
|
||||
order_id: orderWithSwap.id,
|
||||
item_id: li.id,
|
||||
refund_amount: li.quantity * li.unit_price,
|
||||
// shipping_method_id: ,
|
||||
});
|
||||
|
||||
await manager.save(swap);
|
||||
await manager.save(swapReturn);
|
||||
|
||||
const return_item1 = manager.create(LineItem, {
|
||||
...li,
|
||||
unit_price: -1 * li.unit_price,
|
||||
});
|
||||
|
||||
await manager.save(return_item1);
|
||||
|
||||
await manager.insert(ShippingMethod, {
|
||||
id: "another-test-method",
|
||||
shipping_option_id: "test-option",
|
||||
cart_id: "test-cart",
|
||||
price: 1000,
|
||||
data: {},
|
||||
});
|
||||
|
||||
const swapOnSwap = manager.create(Swap, {
|
||||
id: "swap-on-swap",
|
||||
|
||||
Reference in New Issue
Block a user