chore(integration): throw errors on catch blocks (#2091)
Why: Suppressing errors and not failing the execution will lead to misleading errors of the following tests. Fixes CORE-461
This commit is contained in:
@@ -6,7 +6,9 @@ const { useDb } = require("../../../helpers/use-db")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const {
|
||||
simpleSalesChannelFactory,
|
||||
simpleCartFactory, simpleRegionFactory, simpleProductFactory,
|
||||
simpleCartFactory,
|
||||
simpleRegionFactory,
|
||||
simpleProductFactory,
|
||||
} = require("../../factories")
|
||||
|
||||
const startServerWithEnvironment =
|
||||
@@ -47,29 +49,25 @@ describe("sales channels", () => {
|
||||
let disabledSalesChannel
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
name: "Test region",
|
||||
tax_rate: 0,
|
||||
})
|
||||
await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "Default Sales Channel",
|
||||
description: "Created by Medusa",
|
||||
is_default: true
|
||||
})
|
||||
disabledSalesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "disabled cart sales channel",
|
||||
description: "disabled cart sales channel description",
|
||||
is_disabled: true,
|
||||
})
|
||||
salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "cart sales channel",
|
||||
description: "cart sales channel description",
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
await adminSeeder(dbConnection)
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
name: "Test region",
|
||||
tax_rate: 0,
|
||||
})
|
||||
await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "Default Sales Channel",
|
||||
description: "Created by Medusa",
|
||||
is_default: true,
|
||||
})
|
||||
disabledSalesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "disabled cart sales channel",
|
||||
description: "disabled cart sales channel description",
|
||||
is_disabled: true,
|
||||
})
|
||||
salesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "cart sales channel",
|
||||
description: "cart sales channel description",
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -94,7 +92,11 @@ describe("sales channels", () => {
|
||||
it("returns a cart with the given sales channel", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api.post(`/store/carts`, { sales_channel_id: salesChannel.id }, adminReqConfig)
|
||||
const response = await api.post(
|
||||
`/store/carts`,
|
||||
{ sales_channel_id: salesChannel.id },
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.data.cart.sales_channel).toBeTruthy()
|
||||
expect(response.data.cart.sales_channel).toEqual(
|
||||
@@ -108,14 +110,18 @@ describe("sales channels", () => {
|
||||
it("throw if the given sales channel is disabled", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const err = await api.post(
|
||||
`/store/carts`,
|
||||
{ sales_channel_id: disabledSalesChannel.id },
|
||||
adminReqConfig
|
||||
).catch(err => err)
|
||||
const err = await api
|
||||
.post(
|
||||
`/store/carts`,
|
||||
{ sales_channel_id: disabledSalesChannel.id },
|
||||
adminReqConfig
|
||||
)
|
||||
.catch((err) => err)
|
||||
|
||||
expect(err.response.status).toEqual(400)
|
||||
expect(err.response.data.message).toBe(`Unable to assign the cart to a disabled Sales Channel "disabled cart sales channel"`)
|
||||
expect(err.response.data.message).toBe(
|
||||
`Unable to assign the cart to a disabled Sales Channel "disabled cart sales channel"`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -125,81 +131,68 @@ describe("sales channels", () => {
|
||||
let cart
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
name: "Test region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
})
|
||||
await adminSeeder(dbConnection)
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
name: "Test region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
})
|
||||
|
||||
salesChannel1 = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "salesChannel1",
|
||||
description: "salesChannel1",
|
||||
})
|
||||
salesChannel2 = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "salesChannel2",
|
||||
description: "salesChannel2",
|
||||
})
|
||||
disabledSalesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "disabled cart sales channel",
|
||||
description: "disabled cart sales channel description",
|
||||
is_disabled: true,
|
||||
})
|
||||
salesChannel1 = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "salesChannel1",
|
||||
description: "salesChannel1",
|
||||
})
|
||||
salesChannel2 = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "salesChannel2",
|
||||
description: "salesChannel2",
|
||||
})
|
||||
disabledSalesChannel = await simpleSalesChannelFactory(dbConnection, {
|
||||
name: "disabled cart sales channel",
|
||||
description: "disabled cart sales channel description",
|
||||
is_disabled: true,
|
||||
})
|
||||
|
||||
product1 = await simpleProductFactory(
|
||||
dbConnection,
|
||||
product1 = await simpleProductFactory(dbConnection, {
|
||||
title: "prod 1",
|
||||
sales_channels: [salesChannel1],
|
||||
variants: [
|
||||
{
|
||||
title: "prod 1",
|
||||
sales_channels: [salesChannel1],
|
||||
variants: [
|
||||
{
|
||||
id: "test-variant",
|
||||
prices: [
|
||||
{
|
||||
amount: 50,
|
||||
currency: "usd",
|
||||
variant_id: "test-variant",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
product2 = await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
sales_channels: [salesChannel2],
|
||||
variants: [
|
||||
{
|
||||
id: "test-variant-2",
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency: "usd",
|
||||
variant_id: "test-variant-2",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
cart = await simpleCartFactory(
|
||||
dbConnection,
|
||||
{
|
||||
sales_channel: salesChannel1,
|
||||
line_items: [
|
||||
id: "test-variant",
|
||||
prices: [
|
||||
{
|
||||
amount: 50,
|
||||
currency: "usd",
|
||||
variant_id: "test-variant",
|
||||
unit_price: 50,
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
],
|
||||
})
|
||||
product2 = await simpleProductFactory(dbConnection, {
|
||||
sales_channels: [salesChannel2],
|
||||
variants: [
|
||||
{
|
||||
id: "test-variant-2",
|
||||
prices: [
|
||||
{
|
||||
amount: 100,
|
||||
currency: "usd",
|
||||
variant_id: "test-variant-2",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
cart = await simpleCartFactory(dbConnection, {
|
||||
sales_channel: salesChannel1,
|
||||
line_items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
unit_price: 50,
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -207,52 +200,57 @@ describe("sales channels", () => {
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it(
|
||||
"updates a cart sales channels should remove the items that does not belongs to the new sales channel",
|
||||
async () => {
|
||||
const api = useApi()
|
||||
it("updates a cart sales channels should remove the items that does not belongs to the new sales channel", async () => {
|
||||
const api = useApi()
|
||||
|
||||
let response = await api.get(`/store/carts/${cart.id}`, adminReqConfig)
|
||||
let response = await api.get(`/store/carts/${cart.id}`, adminReqConfig)
|
||||
|
||||
expect(response.data.cart.sales_channel).toBeTruthy()
|
||||
expect(response.data.cart.sales_channel).toEqual(
|
||||
expect.objectContaining({
|
||||
name: salesChannel1.name,
|
||||
description: salesChannel1.description,
|
||||
})
|
||||
)
|
||||
expect(response.data.cart.items.length).toBe(1)
|
||||
expect(response.data.cart.items[0].variant.product).toEqual(
|
||||
expect.objectContaining({
|
||||
id: product1.id,
|
||||
title: product1.title,
|
||||
})
|
||||
)
|
||||
expect(response.data.cart.sales_channel).toBeTruthy()
|
||||
expect(response.data.cart.sales_channel).toEqual(
|
||||
expect.objectContaining({
|
||||
name: salesChannel1.name,
|
||||
description: salesChannel1.description,
|
||||
})
|
||||
)
|
||||
expect(response.data.cart.items.length).toBe(1)
|
||||
expect(response.data.cart.items[0].variant.product).toEqual(
|
||||
expect.objectContaining({
|
||||
id: product1.id,
|
||||
title: product1.title,
|
||||
})
|
||||
)
|
||||
|
||||
response = await api.post(`/store/carts/${cart.id}`, { sales_channel_id: salesChannel2.id }, adminReqConfig)
|
||||
response = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ sales_channel_id: salesChannel2.id },
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.data.cart.sales_channel).toBeTruthy()
|
||||
expect(response.data.cart.sales_channel).toEqual(
|
||||
expect.objectContaining({
|
||||
name: salesChannel2.name,
|
||||
description: salesChannel2.description,
|
||||
})
|
||||
)
|
||||
expect(response.data.cart.items.length).toBe(0)
|
||||
}
|
||||
)
|
||||
expect(response.data.cart.sales_channel).toBeTruthy()
|
||||
expect(response.data.cart.sales_channel).toEqual(
|
||||
expect.objectContaining({
|
||||
name: salesChannel2.name,
|
||||
description: salesChannel2.description,
|
||||
})
|
||||
)
|
||||
expect(response.data.cart.items.length).toBe(0)
|
||||
})
|
||||
|
||||
it("throw if the given sales channel is disabled", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const err = await api.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ sales_channel_id: disabledSalesChannel.id },
|
||||
adminReqConfig
|
||||
).catch(err => err)
|
||||
const err = await api
|
||||
.post(
|
||||
`/store/carts/${cart.id}`,
|
||||
{ sales_channel_id: disabledSalesChannel.id },
|
||||
adminReqConfig
|
||||
)
|
||||
.catch((err) => err)
|
||||
|
||||
expect(err.response.status).toEqual(400)
|
||||
expect(err.response.data.message).toBe("Unable to assign the cart to a disabled Sales Channel \"disabled cart sales channel\"")
|
||||
expect(err.response.data.message).toBe(
|
||||
`Unable to assign the cart to a disabled Sales Channel "disabled cart sales channel"`
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -260,18 +258,14 @@ describe("sales channels", () => {
|
||||
let cart
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
cart = await simpleCartFactory(dbConnection, {
|
||||
sales_channel: {
|
||||
name: "test name",
|
||||
description: "test description",
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
cart = await simpleCartFactory(dbConnection, {
|
||||
sales_channel: {
|
||||
name: "test name",
|
||||
description: "test description",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
Reference in New Issue
Block a user