feat: new tax api (#979)
* feat: add tax calculation strategy (#885) * feat: add tax calculation strategy * fix: adds strategy loader * fix: eslint ignore * chore: cleanup * fix: allow plugin overwrites * fix: allow plugin overwrites * fix: fake region * Update packages/medusa/src/loaders/strategies.ts Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * feat: adds tax related db entities + tax provider (#896) * feat: adds tax related db entities + tax provider * fix: add tax provider tests * fix: add tax service unit tests * fix: tests + migrations * fix: add inherited tax lines * chore: rm tax-line repo * fix: test * fix: pr comments * fix: unit test * feat: totals service to ts (#911) * feat: adds tax related db entities + tax provider * fix: add tax provider tests * fix: add tax service unit tests * fix: tests + migrations * feat: totals service to ts * fix: remove totals.js * fix: add shipping methods * fix: add inherited tax lines * chore: rm tax-line repo * fix: test * fix: tests * fix: tests * fix: unit test * fix: adds TotalsServiceProps * feat: adds integration tests for automatic tax calculation + shipping tax rates (#945) * feat: adds tax related db entities + tax provider * fix: add tax provider tests * fix: add tax service unit tests * fix: tests + migrations * feat: totals service to ts * fix: remove totals.js * fix: add shipping methods * fix: add inherited tax lines * chore: rm tax-line repo * fix: test * fix: tests * fix: tests * fix: unit test * fix: integration test helpers * fix: adds factories + tests automatic tax rates * fix: remove verbose * fix: adds TotalsServiceProps * fix: add shipping tax lines * fix: add migration for shipping taxes * fix: integration tests for shipping taxes * fix: integration tests for shipping taxes * fix: jsdoc types * Feat/manual taxes (#950) * feat: adds tax related db entities + tax provider * fix: add tax provider tests * fix: add tax service unit tests * fix: tests + migrations * feat: totals service to ts * fix: remove totals.js * fix: add shipping methods * fix: add inherited tax lines * chore: rm tax-line repo * fix: test * fix: tests * fix: tests * fix: unit test * fix: integration test helpers * fix: adds factories + tests automatic tax rates * fix: remove verbose * fix: adds TotalsServiceProps * fix: add shipping tax lines * fix: add migration for shipping taxes * fix: integration tests for shipping taxes * fix: integration tests for shipping taxes * fix: add integration tests for manual taxes * fix: cart service - cleanup jsdoc * feat: add /carts/id/taxes to manually calculate taxes * feat: add integration tests for order tax calculations * fix: unit tests * fix: merge * fix: rm verbose * fix: unit tests * fix: object -> cartOrOrder * fix: rounding * Feat/complete order w tax lines (#951) * feat: adds tax related db entities + tax provider * fix: add tax provider tests * fix: add tax service unit tests * fix: tests + migrations * feat: totals service to ts * fix: remove totals.js * fix: add shipping methods * fix: add inherited tax lines * chore: rm tax-line repo * fix: test * fix: tests * fix: tests * fix: unit test * fix: integration test helpers * fix: adds factories + tests automatic tax rates * fix: remove verbose * fix: adds TotalsServiceProps * fix: add shipping tax lines * fix: add migration for shipping taxes * fix: integration tests for shipping taxes * fix: integration tests for shipping taxes * fix: add integration tests for manual taxes * fix: cart service - cleanup jsdoc * feat: add /carts/id/taxes to manually calculate taxes * feat: add integration tests for order tax calculations * feat: adds cart completion strategy + create order w. tax lines * fix: unit tests * fix: merge * fix: rm verbose * fix: unit tests * fix: unit tests * fix: unit tests * fix: ensure calculation for list orders * fix: unit tests * fix: integration tests * fix: adds cart order type gaurds * Docs/tax api (#954) * feat: adds tax related db entities + tax provider * fix: add tax provider tests * fix: add tax service unit tests * fix: tests + migrations * feat: totals service to ts * fix: remove totals.js * fix: add shipping methods * fix: add inherited tax lines * chore: rm tax-line repo * fix: test * fix: tests * fix: tests * fix: unit test * fix: integration test helpers * fix: adds factories + tests automatic tax rates * fix: remove verbose * fix: adds TotalsServiceProps * fix: add shipping tax lines * fix: add migration for shipping taxes * fix: integration tests for shipping taxes * fix: integration tests for shipping taxes * fix: add integration tests for manual taxes * fix: cart service - cleanup jsdoc * feat: add /carts/id/taxes to manually calculate taxes * feat: add integration tests for order tax calculations * feat: adds cart completion strategy + create order w. tax lines * fix: unit tests * fix: merge * fix: rm verbose * fix: unit tests * fix: unit tests * fix: unit tests * fix: ensure calculation for list orders * fix: unit tests * fix: integration tests * docs: documents tax related methods and types * fix: require either item_id or shipping_method_id * feat: product type tax rate (#969) * feat: adds tax related db entities + tax provider * fix: add tax provider tests * fix: add tax service unit tests * fix: tests + migrations * feat: totals service to ts * fix: remove totals.js * fix: add shipping methods * fix: add inherited tax lines * chore: rm tax-line repo * fix: test * fix: tests * fix: tests * fix: unit test * fix: integration test helpers * fix: adds factories + tests automatic tax rates * fix: remove verbose * fix: adds TotalsServiceProps * fix: add shipping tax lines * fix: add migration for shipping taxes * fix: integration tests for shipping taxes * fix: integration tests for shipping taxes * fix: add integration tests for manual taxes * fix: cart service - cleanup jsdoc * feat: add /carts/id/taxes to manually calculate taxes * feat: add integration tests for order tax calculations * feat: adds cart completion strategy + create order w. tax lines * fix: unit tests * fix: merge * fix: rm verbose * fix: unit tests * fix: unit tests * fix: unit tests * fix: ensure calculation for list orders * fix: unit tests * fix: integration tests * docs: documents tax related methods and types * fix: require either item_id or shipping_method_id * feat: adds returns tests for new tax system * feat: adds return lines + integration tests for swaps * feat: return integration tests * feat: adds product type tax rates * feat: add tax management endpoints * fix: create single migration * fix: adds tax rates to js client * fix: strats * Fix/plugin tests (#998) * plugin testing setup * fix: test sendgrid plugin * fix: test sendgrid plugin * chore: clean * chore: clean * fix: clean up tests * fix: remove dirty import * fix: sendgrid + brightpearl * fix: plugin integration tests * fix: klarna * fix: shipping method tax * fix: remove taxrates * fix: unit tests * fix: integration * fix: integration * fix: plugins tests * fix: ignore plugins * fix: tests * fix: taxes (#1017) * fix: taxes * fix: taxes * fix: faulty ref * fix: create tax-lines with claim items * fix: snapshot tax-liens * fix: allows integration test teardown to force deleting tables * fix: tests * fix: merge * fix: adds tax-rates to client * fix: adds tax-rates to medusa-react * fix: tests * fix: tests * fix: add product types * fix: adds tax provider endpoint + cascaded deletes on tax rate relations * fix: move errors to service layer * fix: cleanup api * fix: unit tests * fix: error handler in base-service * fix: Add order region to swap on createFulfillment (#1110) Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
olivermrbl
parent
d80eaa172d
commit
47588e7a8d
434
integration-tests/plugins/helpers/swap-seeder.js
Normal file
434
integration-tests/plugins/helpers/swap-seeder.js
Normal file
@@ -0,0 +1,434 @@
|
||||
const {
|
||||
Discount,
|
||||
DiscountRule,
|
||||
LineItem,
|
||||
ShippingMethod,
|
||||
Order,
|
||||
Swap,
|
||||
Cart,
|
||||
Return,
|
||||
} = require("@medusajs/medusa")
|
||||
const {
|
||||
CustomShippingOption,
|
||||
} = require("@medusajs/medusa/dist/models/custom-shipping-option")
|
||||
|
||||
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-pay",
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
items: [],
|
||||
...data,
|
||||
})
|
||||
|
||||
orderWithSwap = await manager.save(orderWithSwap)
|
||||
|
||||
const cart = manager.create(Cart, {
|
||||
id: "test-cart-w-swap",
|
||||
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-w-swap",
|
||||
payment: {
|
||||
id: "test-payment-swap",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test-pay",
|
||||
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-w-swap",
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await manager.save(swap)
|
||||
|
||||
const cartWithCustomSo = manager.create(Cart, {
|
||||
id: "test-cart-rma",
|
||||
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(cartWithCustomSo)
|
||||
|
||||
const liRma = manager.create(LineItem, {
|
||||
id: "test-item-rma",
|
||||
title: "Line Item RMA",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
cart_id: "test-cart-rma",
|
||||
})
|
||||
await manager.save(liRma)
|
||||
|
||||
manager.insert(CustomShippingOption, {
|
||||
id: "cso-test",
|
||||
cart_id: cartWithCustomSo.id,
|
||||
price: 0,
|
||||
shipping_option_id: "test-option",
|
||||
})
|
||||
|
||||
const swapWithRMAMethod = manager.create(Swap, {
|
||||
id: "test-swap-rma",
|
||||
order_id: "order-with-swap",
|
||||
payment_status: "captured",
|
||||
fulfillment_status: "fulfilled",
|
||||
cart_id: cartWithCustomSo.id,
|
||||
payment: {
|
||||
id: "test-payment-swap",
|
||||
amount: 10000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test-pay",
|
||||
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(swapWithRMAMethod)
|
||||
|
||||
const cartTemplate = async (cartId) => {
|
||||
const cart = manager.create(Cart, {
|
||||
id: cartId,
|
||||
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: {},
|
||||
...data,
|
||||
})
|
||||
|
||||
await manager.save(cart)
|
||||
}
|
||||
|
||||
const swapTemplate = async (cartId) => {
|
||||
await cartTemplate(cartId)
|
||||
return {
|
||||
order_id: orderWithSwap.id,
|
||||
fulfillment_status: "fulfilled",
|
||||
payment_status: "not_paid",
|
||||
cart_id: cartId,
|
||||
payment: {
|
||||
amount: 5000,
|
||||
currency_code: "usd",
|
||||
amount_refunded: 0,
|
||||
provider_id: "test-pay",
|
||||
data: {},
|
||||
},
|
||||
...data,
|
||||
}
|
||||
}
|
||||
|
||||
const swapWithFulfillments = manager.create(Swap, {
|
||||
id: "swap-w-f",
|
||||
fulfillments: [
|
||||
{
|
||||
id: "fulfillment-1",
|
||||
data: {},
|
||||
provider_id: "test-ful",
|
||||
},
|
||||
{
|
||||
id: "fulfillment-2",
|
||||
data: {},
|
||||
provider_id: "test-ful",
|
||||
},
|
||||
],
|
||||
...(await swapTemplate("sc-w-f")),
|
||||
})
|
||||
|
||||
await manager.save(swapWithFulfillments)
|
||||
|
||||
const swapWithReturn = manager.create(Swap, {
|
||||
id: "swap-w-r",
|
||||
return_order: {
|
||||
id: "return-id",
|
||||
status: "requested",
|
||||
refund_amount: 0,
|
||||
},
|
||||
...(await swapTemplate("sc-w-r")),
|
||||
})
|
||||
|
||||
await manager.save(swapWithReturn)
|
||||
const li = manager.create(LineItem, {
|
||||
id: "return-item-1",
|
||||
fulfilled_quantity: 1,
|
||||
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)
|
||||
|
||||
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 swapReturn = await manager.create(Return, {
|
||||
swap_id: swap.id,
|
||||
order_id: orderWithSwap.id,
|
||||
item_id: li.id,
|
||||
refund_amount: li.quantity * li.unit_price,
|
||||
})
|
||||
|
||||
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-w-swap",
|
||||
price: 1000,
|
||||
data: {},
|
||||
})
|
||||
|
||||
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-pay",
|
||||
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: {},
|
||||
})
|
||||
|
||||
await createSwap({ id: "disc-swap" }, manager)
|
||||
}
|
||||
|
||||
const createSwap = async (options, manager) => {
|
||||
const swapId = options.id
|
||||
|
||||
const dRule = manager.create(DiscountRule, {
|
||||
id: `${swapId}-cart-discount-rule`,
|
||||
description: "Ten percent rule",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
})
|
||||
await manager.save(dRule)
|
||||
|
||||
const discount = manager.create(Discount, {
|
||||
code: `${swapId}`,
|
||||
is_dynamic: false,
|
||||
is_disabled: false,
|
||||
rule: dRule,
|
||||
})
|
||||
await manager.save(discount)
|
||||
|
||||
const cart = manager.create(Cart, {
|
||||
id: `${swapId}-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",
|
||||
discounts: [discount],
|
||||
metadata: {
|
||||
swap_id: swapId,
|
||||
parent_order_id: "order-with-swap",
|
||||
},
|
||||
})
|
||||
|
||||
await manager.save(cart)
|
||||
|
||||
const swapTemplate = async () => {
|
||||
return {
|
||||
order_id: `order-with-swap`,
|
||||
fulfillment_status: "fulfilled",
|
||||
payment_status: "not_paid",
|
||||
cart_id: cart.id,
|
||||
}
|
||||
}
|
||||
|
||||
const swapWithReturn = manager.create(Swap, {
|
||||
id: swapId,
|
||||
return_order: {
|
||||
id: `${swapId}-return-id`,
|
||||
status: "requested",
|
||||
refund_amount: 0,
|
||||
},
|
||||
...(await swapTemplate(swapId)),
|
||||
})
|
||||
|
||||
await manager.save(swapWithReturn)
|
||||
const li = manager.create(LineItem, {
|
||||
id: `${swapId}-return-item-1`,
|
||||
fulfilled_quantity: 1,
|
||||
title: "Return Line Item",
|
||||
description: "Line Item Desc",
|
||||
thumbnail: "https://test.js/1234",
|
||||
unit_price: 8000,
|
||||
quantity: 1,
|
||||
variant_id: "test-variant",
|
||||
order_id: "order-with-swap",
|
||||
cart_id: cart.id,
|
||||
})
|
||||
|
||||
await manager.save(li)
|
||||
|
||||
const li2 = manager.create(LineItem, {
|
||||
id: `${swapId}-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: "order-with-swap",
|
||||
})
|
||||
|
||||
await manager.save(li2)
|
||||
|
||||
const return_item1 = manager.create(LineItem, {
|
||||
...li,
|
||||
unit_price: -1 * li.unit_price,
|
||||
})
|
||||
|
||||
await manager.save(return_item1)
|
||||
|
||||
await manager.insert(ShippingMethod, {
|
||||
id: `${swapId}-test-method`,
|
||||
shipping_option_id: "test-option",
|
||||
cart_id: cart.id,
|
||||
price: 1000,
|
||||
data: {},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user