feat(medusa): Swaps on swaps (#229)
Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
This commit is contained in:
committed by
GitHub
parent
2f3e3fde80
commit
f8f1f57fa1
@@ -10,6 +10,7 @@ const {
|
||||
ProductVariant,
|
||||
Region,
|
||||
Order,
|
||||
Swap,
|
||||
} = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
@@ -39,6 +40,26 @@ module.exports = async (connection, data = {}) => {
|
||||
],
|
||||
});
|
||||
|
||||
await manager.insert(ProductVariant, {
|
||||
id: "test-variant-2",
|
||||
title: "Swap product",
|
||||
product_id: "test-product",
|
||||
inventory_quantity: 1,
|
||||
options: [
|
||||
{
|
||||
option_id: "test-option",
|
||||
value: "Large",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const ma2 = manager.create(MoneyAmount, {
|
||||
variant_id: "test-variant-2",
|
||||
currency_code: "usd",
|
||||
amount: 8000,
|
||||
});
|
||||
await manager.save(ma2);
|
||||
|
||||
const ma = manager.create(MoneyAmount, {
|
||||
variant_id: "test-variant",
|
||||
currency_code: "usd",
|
||||
@@ -77,6 +98,8 @@ module.exports = async (connection, data = {}) => {
|
||||
id: "test-order",
|
||||
customer_id: "test-customer",
|
||||
email: "test@email.com",
|
||||
payment_status: "captured",
|
||||
fulfillment_status: "fulfilled",
|
||||
billing_address: {
|
||||
id: "test-billing-address",
|
||||
first_name: "lebron",
|
||||
@@ -115,27 +138,31 @@ module.exports = async (connection, data = {}) => {
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test",
|
||||
provider_id: "test-pay",
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
items: [
|
||||
{
|
||||
id: "test-item",
|
||||
fulfilled_quantity: 1,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
],
|
||||
items: [],
|
||||
...data,
|
||||
});
|
||||
|
||||
await manager.save(order);
|
||||
|
||||
const li = manager.create(LineItem, {
|
||||
id: "test-item",
|
||||
fulfilled_quantity: 1,
|
||||
returned_quantity: 0,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
order_id: "test-order",
|
||||
});
|
||||
|
||||
await manager.save(li);
|
||||
|
||||
await manager.insert(ShippingMethod, {
|
||||
id: "test-method",
|
||||
order_id: "test-order",
|
||||
|
||||
159
integration-tests/api/helpers/swap-seeder.js
Normal file
159
integration-tests/api/helpers/swap-seeder.js
Normal file
@@ -0,0 +1,159 @@
|
||||
const {
|
||||
ShippingProfile,
|
||||
Customer,
|
||||
MoneyAmount,
|
||||
LineItem,
|
||||
Country,
|
||||
ShippingOption,
|
||||
ShippingMethod,
|
||||
Product,
|
||||
ProductVariant,
|
||||
Region,
|
||||
Order,
|
||||
Swap,
|
||||
Return,
|
||||
} = require("@medusajs/medusa");
|
||||
|
||||
module.exports = async (connection, data = {}) => {
|
||||
const manager = connection.manager;
|
||||
|
||||
let orderWithSwap = manager.create(Order, {
|
||||
id: "order-with-swap",
|
||||
customer_id: "test-customer",
|
||||
email: "test@email.com",
|
||||
payment_status: "captured",
|
||||
fulfillment_status: "fulfilled",
|
||||
billing_address: {
|
||||
id: "test-billing-address",
|
||||
first_name: "lebron",
|
||||
},
|
||||
shipping_address: {
|
||||
id: "test-shipping-address",
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
},
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
discounts: [],
|
||||
payments: [
|
||||
{
|
||||
id: "test-payment",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test",
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
items: [],
|
||||
...data,
|
||||
});
|
||||
|
||||
orderWithSwap = await manager.save(orderWithSwap);
|
||||
|
||||
const li = manager.create(LineItem, {
|
||||
id: "test-item-2",
|
||||
fulfilled_quantity: 1,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
order_id: orderWithSwap.id,
|
||||
});
|
||||
|
||||
await manager.save(li);
|
||||
|
||||
const li2 = manager.create(LineItem, {
|
||||
id: "test-item-many",
|
||||
fulfilled_quantity: 4,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 4,
|
||||
variant_id: "test-variant",
|
||||
order_id: orderWithSwap.id,
|
||||
});
|
||||
|
||||
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",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await manager.save(swap);
|
||||
|
||||
const swapOnSwap = manager.create(Swap, {
|
||||
id: "swap-on-swap",
|
||||
order_id: "order-with-swap",
|
||||
payment_status: "captured",
|
||||
fulfillment_status: "fulfilled",
|
||||
return_order: {
|
||||
id: "return-on-swap",
|
||||
refund_amount: 9000,
|
||||
items: [
|
||||
{
|
||||
return_id: "return-on-swap",
|
||||
item_id: "test-item-swapped",
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
payment: {
|
||||
id: "test-payment-swap-on-swap",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test",
|
||||
data: {},
|
||||
},
|
||||
additional_items: [
|
||||
{
|
||||
id: "test-item-swap-on-swap",
|
||||
fulfilled_quantity: 1,
|
||||
title: "Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await manager.save(swapOnSwap);
|
||||
|
||||
await manager.insert(ShippingMethod, {
|
||||
id: "test-method-swap-order",
|
||||
shipping_option_id: "test-option",
|
||||
order_id: "order-with-swap",
|
||||
price: 1000,
|
||||
data: {},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user