chore(feature-flags): Sales Channels enabled by default (#2966)
This commit is contained in:
@@ -185,7 +185,7 @@ Object {
|
||||
"metadata": null,
|
||||
"option_id": Any<String>,
|
||||
"updated_at": Any<String>,
|
||||
"value": "Handcrafted",
|
||||
"value": "Practical",
|
||||
"variant_id": Any<String>,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -98,6 +98,7 @@ Object {
|
||||
"payment_authorized_at": null,
|
||||
"payment_id": null,
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": Any<String>,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"type": "swap",
|
||||
"updated_at": Any<String>,
|
||||
@@ -131,6 +132,7 @@ Object {
|
||||
"object": "order",
|
||||
"payment_status": "captured",
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": null,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"status": "pending",
|
||||
"tax_rate": 0,
|
||||
@@ -275,6 +277,7 @@ Object {
|
||||
"payment_authorized_at": null,
|
||||
"payment_id": null,
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": Any<String>,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"type": "swap",
|
||||
"updated_at": Any<String>,
|
||||
@@ -308,6 +311,7 @@ Object {
|
||||
"object": "order",
|
||||
"payment_status": "captured",
|
||||
"region_id": "test-region",
|
||||
"sales_channel_id": null,
|
||||
"shipping_address_id": "test-shipping-address",
|
||||
"status": "pending",
|
||||
"tax_rate": 0,
|
||||
|
||||
@@ -22,6 +22,7 @@ const {
|
||||
simpleProductFactory,
|
||||
simpleShippingOptionFactory,
|
||||
simpleLineItemFactory,
|
||||
simpleSalesChannelFactory,
|
||||
} = require("../../../factories")
|
||||
const {
|
||||
simpleDiscountFactory,
|
||||
@@ -57,6 +58,9 @@ describe("/store/carts", () => {
|
||||
})
|
||||
|
||||
describe("POST /store/carts", () => {
|
||||
let prod1
|
||||
let prodSale
|
||||
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager
|
||||
await manager.insert(Region, {
|
||||
@@ -70,6 +74,21 @@ describe("/store/carts", () => {
|
||||
SET region_id='region'
|
||||
WHERE iso_2 = 'us'`
|
||||
)
|
||||
|
||||
prod1 = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product",
|
||||
variants: [{ id: "test-variant_1" }],
|
||||
})
|
||||
|
||||
prodSale = await simpleProductFactory(dbConnection, {
|
||||
id: "test-product-sale",
|
||||
variants: [
|
||||
{
|
||||
id: "test-variant-sale",
|
||||
prices: [{ amount: 1000, currency: "usd" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -108,8 +127,6 @@ describe("/store/carts", () => {
|
||||
})
|
||||
|
||||
it("creates a cart with items", async () => {
|
||||
await productSeeder(dbConnection)
|
||||
|
||||
const yesterday = ((today) =>
|
||||
new Date(today.setDate(today.getDate() - 1)))(new Date())
|
||||
const tomorrow = ((today) =>
|
||||
@@ -128,7 +145,7 @@ describe("/store/carts", () => {
|
||||
await dbConnection.manager.save(priceList1)
|
||||
|
||||
const ma_sale_1 = dbConnection.manager.create(MoneyAmount, {
|
||||
variant_id: "test-variant-sale",
|
||||
variant_id: prodSale.variants[0].id,
|
||||
currency_code: "usd",
|
||||
amount: 800,
|
||||
price_list_id: "pl_current",
|
||||
@@ -142,11 +159,11 @@ describe("/store/carts", () => {
|
||||
.post("/store/carts", {
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant_1",
|
||||
variant_id: prod1.variants[0].id,
|
||||
quantity: 1,
|
||||
},
|
||||
{
|
||||
variant_id: "test-variant-sale",
|
||||
variant_id: prodSale.variants[0].id,
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
@@ -160,11 +177,11 @@ describe("/store/carts", () => {
|
||||
expect(response.data.cart.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant_1",
|
||||
variant_id: prod1.variants[0].id,
|
||||
quantity: 1,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant-sale",
|
||||
variant_id: prodSale.variants[0].id,
|
||||
quantity: 2,
|
||||
unit_price: 800,
|
||||
}),
|
||||
@@ -931,6 +948,11 @@ describe("/store/carts", () => {
|
||||
beforeEach(async () => {
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
|
||||
await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -2263,6 +2285,10 @@ describe("/store/carts", () => {
|
||||
describe("get-cart with session customer", () => {
|
||||
beforeEach(async () => {
|
||||
await cartSeeder(dbConnection)
|
||||
await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -13,6 +13,7 @@ const {
|
||||
simpleProductFactory,
|
||||
simplePriceListFactory,
|
||||
simpleDiscountFactory,
|
||||
simpleSalesChannelFactory,
|
||||
} = require("../../../factories")
|
||||
const { IdMap } = require("medusa-test-utils")
|
||||
|
||||
@@ -155,9 +156,11 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
tax_rate: 20,
|
||||
name: "region test",
|
||||
}
|
||||
const buildProductData = (productId, variantId) => {
|
||||
|
||||
const buildProductData = (productId, variantId, salesChannelId) => {
|
||||
return {
|
||||
id: productId,
|
||||
sales_channels: [{ id: salesChannelId }],
|
||||
variants: [
|
||||
{
|
||||
id: variantId,
|
||||
@@ -203,10 +206,14 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
|
||||
describe("with a cart with full tax exclusive variant pricing", () => {
|
||||
beforeEach(async () => {
|
||||
const salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
await simpleRegionFactory(dbConnection, regionData)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId1, variantId1)
|
||||
buildProductData(productId1, variantId1, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -214,7 +221,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId2, variantId2)
|
||||
buildProductData(productId2, variantId2, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -280,10 +287,15 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
|
||||
await simpleRegionFactory(dbConnection, regionData)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId1, variantId1)
|
||||
buildProductData(productId1, variantId1, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -291,7 +303,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId2, variantId2)
|
||||
buildProductData(productId2, variantId2, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -357,10 +369,15 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
id: "test-channel",
|
||||
is_default: true,
|
||||
})
|
||||
|
||||
await simpleRegionFactory(dbConnection, regionData)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId1, variantId1)
|
||||
buildProductData(productId1, variantId1, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
@@ -368,7 +385,7 @@ describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /store/carts", () => {
|
||||
)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
buildProductData(productId2, variantId2)
|
||||
buildProductData(productId2, variantId2, salesChannel.id)
|
||||
)
|
||||
await simplePriceListFactory(
|
||||
dbConnection,
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("Gift Card - Tax calculations", () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", "..", ".."))
|
||||
const [process, connection] = await startServerWithEnvironment({
|
||||
cwd,
|
||||
env: {}
|
||||
env: {},
|
||||
})
|
||||
dbConnection = connection
|
||||
medusaProcess = process
|
||||
@@ -51,7 +51,9 @@ describe("Gift Card - Tax calculations", () => {
|
||||
name: "region test",
|
||||
})
|
||||
|
||||
customer = await simpleCustomerFactory(dbConnection, { password: 'medusatest' })
|
||||
customer = await simpleCustomerFactory(dbConnection, {
|
||||
password: "medusatest",
|
||||
})
|
||||
|
||||
customerData = {
|
||||
email: customer.email,
|
||||
@@ -64,19 +66,25 @@ describe("Gift Card - Tax calculations", () => {
|
||||
is_giftcard: true,
|
||||
discountable: false,
|
||||
options: [{ id: "denom", title: "Denomination" }],
|
||||
variants: [{
|
||||
title: "Gift Card",
|
||||
prices: [{ currency: "usd", amount: 30000, region_id: region.id }],
|
||||
options: [{ option_id: "denom", value: "Denomination" }],
|
||||
}]
|
||||
variants: [
|
||||
{
|
||||
title: "Gift Card",
|
||||
prices: [{ currency: "usd", amount: 30000, region_id: region.id }],
|
||||
options: [{ option_id: "denom", value: "Denomination" }],
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
it("adding a gift card purchase to cart treats it like buying a product", async () => {
|
||||
const api = useApi()
|
||||
const customerResponse = await api.post("/store/customers", customerData, {
|
||||
withCredentials: true,
|
||||
})
|
||||
const customerResponse = await api.post(
|
||||
"/store/customers",
|
||||
customerData,
|
||||
{
|
||||
withCredentials: true,
|
||||
}
|
||||
)
|
||||
|
||||
const createCartResponse = await api.post("/store/carts", {
|
||||
region_id: region.id,
|
||||
@@ -110,8 +118,8 @@ describe("Gift Card - Tax calculations", () => {
|
||||
id: product.variants[0].id,
|
||||
product: expect.objectContaining({
|
||||
is_giftcard: true,
|
||||
})
|
||||
})
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
])
|
||||
)
|
||||
@@ -119,11 +127,18 @@ describe("Gift Card - Tax calculations", () => {
|
||||
|
||||
it("purchasing a gift card via an order creates a gift card entity", async () => {
|
||||
const api = useApi()
|
||||
const customerResponse = await api.post("/store/customers", customerData, {
|
||||
withCredentials: true,
|
||||
})
|
||||
const customerResponse = await api.post(
|
||||
"/store/customers",
|
||||
customerData,
|
||||
{
|
||||
withCredentials: true,
|
||||
}
|
||||
)
|
||||
|
||||
const cartFactory = await simpleCartFactory(dbConnection, { customer, region })
|
||||
const cartFactory = await simpleCartFactory(dbConnection, {
|
||||
customer,
|
||||
region,
|
||||
})
|
||||
|
||||
const response = await api.post(
|
||||
`/store/carts/${cartFactory.id}/line-items`,
|
||||
@@ -140,9 +155,11 @@ describe("Gift Card - Tax calculations", () => {
|
||||
|
||||
await api.post(`/store/carts/${cart.id}/payment-sessions`)
|
||||
|
||||
const createdOrderResponse = await api.post(`/store/carts/${cart.id}/complete-cart`)
|
||||
const createdOrderResponse = await api.post(
|
||||
`/store/carts/${cart.id}/complete-cart`
|
||||
)
|
||||
const createdGiftCards = await dbConnection.manager.find(GiftCard, {
|
||||
where: { order_id: createdOrderResponse.data.data.id }
|
||||
where: { order_id: createdOrderResponse.data.data.id },
|
||||
})
|
||||
const createdGiftCard = createdGiftCards[0]
|
||||
|
||||
@@ -163,14 +180,18 @@ describe("Gift Card - Tax calculations", () => {
|
||||
tax_rate: region.tax_rate,
|
||||
})
|
||||
const expensiveProduct = await simpleProductFactory(dbConnection, {
|
||||
variants: [{
|
||||
title: "Product cost higher than gift card balance",
|
||||
prices: [{
|
||||
amount: 50000,
|
||||
currency: "usd",
|
||||
region_id: region.id,
|
||||
}],
|
||||
}]
|
||||
variants: [
|
||||
{
|
||||
title: "Product cost higher than gift card balance",
|
||||
prices: [
|
||||
{
|
||||
amount: 50000,
|
||||
currency: "usd",
|
||||
region_id: region.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const customerRes = await api.post("/store/customers", customerData, {
|
||||
@@ -200,7 +221,9 @@ describe("Gift Card - Tax calculations", () => {
|
||||
const getCartResponse = await api.get(`/store/carts/${cartFactory.id}`)
|
||||
const cart = getCartResponse.data.cart
|
||||
await api.post(`/store/carts/${cart.id}/payment-sessions`)
|
||||
const createdOrder = await api.post(`/store/carts/${cart.id}/complete-cart`)
|
||||
const createdOrder = await api.post(
|
||||
`/store/carts/${cart.id}/complete-cart`
|
||||
)
|
||||
|
||||
expect(createdOrder.data.data).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -228,12 +251,12 @@ describe("Gift Card - Tax calculations", () => {
|
||||
refundable: 59500,
|
||||
tax_lines: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
rate: 19
|
||||
})
|
||||
rate: 19,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -114,6 +114,7 @@ describe("/store/carts", () => {
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
cart: {
|
||||
id: expect.stringMatching(/^cart_*/),
|
||||
sales_channel_id: expect.any(String),
|
||||
billing_address_id: "test-billing-address",
|
||||
type: "swap",
|
||||
created_at: expect.any(String),
|
||||
@@ -201,6 +202,7 @@ describe("/store/carts", () => {
|
||||
cart_id: expect.stringMatching(/^cart_*/),
|
||||
cart: {
|
||||
id: expect.stringMatching(/^cart_*/),
|
||||
sales_channel_id: expect.any(String),
|
||||
billing_address_id: "test-billing-address",
|
||||
shipping_address_id: "test-shipping-address",
|
||||
type: "swap",
|
||||
|
||||
Reference in New Issue
Block a user