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:
committed by
GitHub
parent
5a964e6439
commit
ffd6234356
@@ -46,12 +46,8 @@ describe("/store/carts", () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
try {
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd, verbose: false })
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd, verbose: false })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -207,13 +203,8 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("POST /store/carts/:id/line-items", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -495,57 +486,49 @@ describe("/store/carts", () => {
|
||||
let discountCart
|
||||
let discount
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
discount = await simpleDiscountFactory(
|
||||
dbConnection,
|
||||
discountData,
|
||||
100
|
||||
)
|
||||
discountCart = await simpleCartFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: "discount-cart",
|
||||
customer: "test-customer",
|
||||
region: "test-region",
|
||||
shipping_address: {
|
||||
address_1: "next door",
|
||||
first_name: "lebron",
|
||||
last_name: "james",
|
||||
country_code: "dk",
|
||||
postal_code: "100",
|
||||
},
|
||||
line_items: [
|
||||
{
|
||||
id: "test-li",
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
unit_price: 100,
|
||||
adjustments: [
|
||||
{
|
||||
amount: 185,
|
||||
description: "discount",
|
||||
discount_id: "medusa-185",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
shipping_methods: [
|
||||
{
|
||||
shipping_option: "test-option",
|
||||
price: 1000,
|
||||
},
|
||||
],
|
||||
discount = await simpleDiscountFactory(dbConnection, discountData, 100)
|
||||
discountCart = await simpleCartFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: "discount-cart",
|
||||
customer: "test-customer",
|
||||
region: "test-region",
|
||||
shipping_address: {
|
||||
address_1: "next door",
|
||||
first_name: "lebron",
|
||||
last_name: "james",
|
||||
country_code: "dk",
|
||||
postal_code: "100",
|
||||
},
|
||||
100
|
||||
)
|
||||
await dbConnection.manager
|
||||
.createQueryBuilder()
|
||||
.relation(Cart, "discounts")
|
||||
.of(discountCart)
|
||||
.add(discount)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
line_items: [
|
||||
{
|
||||
id: "test-li",
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
unit_price: 100,
|
||||
adjustments: [
|
||||
{
|
||||
amount: 185,
|
||||
description: "discount",
|
||||
discount_id: "medusa-185",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
shipping_methods: [
|
||||
{
|
||||
shipping_option: "test-option",
|
||||
price: 1000,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
await dbConnection.manager
|
||||
.createQueryBuilder()
|
||||
.relation(Cart, "discounts")
|
||||
.of(discountCart)
|
||||
.add(discount)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -699,13 +682,8 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("POST /store/carts/:id/line-items/:line_id", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -901,13 +879,8 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("POST /store/carts/:id", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await cartSeeder(dbConnection)
|
||||
await swapSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -1738,11 +1711,7 @@ describe("/store/carts", () => {
|
||||
|
||||
const api = useApi()
|
||||
|
||||
try {
|
||||
await api.post(`/store/carts/swap-cart/complete-cart`)
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
await api.post(`/store/carts/swap-cart/complete-cart`)
|
||||
|
||||
// check to see if payment is authorized and cart is completed
|
||||
const res = await api.get(`/store/carts/swap-cart`)
|
||||
@@ -1753,35 +1722,31 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("POST /store/carts/:id/shipping-methods", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
const manager = dbConnection.manager
|
||||
await cartSeeder(dbConnection)
|
||||
const manager = dbConnection.manager
|
||||
|
||||
const _cart = await manager.create(Cart, {
|
||||
id: "test-cart-with-cso",
|
||||
customer_id: "some-customer",
|
||||
email: "some-customer@email.com",
|
||||
shipping_address: {
|
||||
id: "test-shipping-address",
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
},
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
type: "swap",
|
||||
})
|
||||
const _cart = await manager.create(Cart, {
|
||||
id: "test-cart-with-cso",
|
||||
customer_id: "some-customer",
|
||||
email: "some-customer@email.com",
|
||||
shipping_address: {
|
||||
id: "test-shipping-address",
|
||||
first_name: "lebron",
|
||||
country_code: "us",
|
||||
},
|
||||
region_id: "test-region",
|
||||
currency_code: "usd",
|
||||
type: "swap",
|
||||
})
|
||||
|
||||
const cartWithCustomSo = await manager.save(_cart)
|
||||
const cartWithCustomSo = await manager.save(_cart)
|
||||
|
||||
await manager.insert(CustomShippingOption, {
|
||||
id: "another-cso-test",
|
||||
cart_id: "test-cart-with-cso",
|
||||
shipping_option_id: "test-option",
|
||||
price: 5,
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
await manager.insert(CustomShippingOption, {
|
||||
id: "another-cso-test",
|
||||
cart_id: "test-cart-with-cso",
|
||||
shipping_option_id: "test-option",
|
||||
price: 5,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -2059,12 +2024,7 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("shipping address + region updates", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await cartSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await cartSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -25,12 +25,7 @@ describe("/store/collections", () => {
|
||||
|
||||
describe("/store/collections/:id", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await productSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -55,12 +50,7 @@ describe("/store/collections", () => {
|
||||
|
||||
describe("/store/collections", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await productSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -27,12 +27,7 @@ describe("/store/carts (draft-orders)", () => {
|
||||
|
||||
describe("POST /admin/draft-order", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await draftOrderSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await draftOrderSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -26,30 +26,25 @@ describe("/store/variants", () => {
|
||||
|
||||
describe("GET /store/variants", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
await productSeeder(dbConnection)
|
||||
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "prod",
|
||||
variants: [
|
||||
{
|
||||
title: "test1",
|
||||
inventory_quantity: 10,
|
||||
},
|
||||
{
|
||||
title: "test2",
|
||||
inventory_quantity: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "prod",
|
||||
variants: [
|
||||
{
|
||||
title: "test1",
|
||||
inventory_quantity: 10,
|
||||
},
|
||||
{
|
||||
title: "test2",
|
||||
inventory_quantity: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -169,30 +164,25 @@ describe("/store/variants", () => {
|
||||
|
||||
describe("GET /store/variants advanced pricing", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await storeProductSeeder(dbConnection)
|
||||
await storeProductSeeder(dbConnection)
|
||||
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "prod",
|
||||
variants: [
|
||||
{
|
||||
title: "test1",
|
||||
inventory_quantity: 10,
|
||||
},
|
||||
{
|
||||
title: "test2",
|
||||
inventory_quantity: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "prod",
|
||||
variants: [
|
||||
{
|
||||
title: "test1",
|
||||
inventory_quantity: 10,
|
||||
},
|
||||
{
|
||||
title: "test2",
|
||||
inventory_quantity: 12,
|
||||
},
|
||||
],
|
||||
},
|
||||
100
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -26,13 +26,8 @@ describe("/store/products", () => {
|
||||
|
||||
describe("GET /store/products", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -233,13 +228,8 @@ describe("/store/products", () => {
|
||||
|
||||
describe("list params", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -332,32 +322,27 @@ describe("/store/products", () => {
|
||||
|
||||
describe("list params", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "testprod",
|
||||
status: "published",
|
||||
variants: [{ title: "test-variant" }],
|
||||
},
|
||||
11
|
||||
)
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "testprod",
|
||||
status: "published",
|
||||
variants: [{ title: "test-variant" }],
|
||||
},
|
||||
11
|
||||
)
|
||||
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "testprod3",
|
||||
status: "published",
|
||||
variants: [{ title: "test-variant1" }],
|
||||
},
|
||||
12
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await simpleProductFactory(
|
||||
dbConnection,
|
||||
{
|
||||
title: "testprod3",
|
||||
status: "published",
|
||||
variants: [{ title: "test-variant1" }],
|
||||
},
|
||||
12
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -400,13 +385,8 @@ describe("/store/products", () => {
|
||||
|
||||
describe("/store/products/:id", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
await productSeeder(dbConnection)
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -28,18 +28,13 @@ describe("/store/return-reasons", () => {
|
||||
let rrId
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "wrong_size",
|
||||
label: "Wrong size",
|
||||
})
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "wrong_size",
|
||||
label: "Wrong size",
|
||||
})
|
||||
|
||||
const result = await dbConnection.manager.save(created)
|
||||
rrId = result.id
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
const result = await dbConnection.manager.save(created)
|
||||
rrId = result.id
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -73,35 +68,30 @@ describe("/store/return-reasons", () => {
|
||||
let rrId_2
|
||||
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "wrong_size",
|
||||
label: "Wrong size",
|
||||
})
|
||||
const created = dbConnection.manager.create(ReturnReason, {
|
||||
value: "wrong_size",
|
||||
label: "Wrong size",
|
||||
})
|
||||
|
||||
const result = await dbConnection.manager.save(created)
|
||||
rrId = result.id
|
||||
const result = await dbConnection.manager.save(created)
|
||||
rrId = result.id
|
||||
|
||||
const created_child = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
parent_return_reason_id: rrId,
|
||||
})
|
||||
const created_child = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big",
|
||||
label: "Too Big",
|
||||
parent_return_reason_id: rrId,
|
||||
})
|
||||
|
||||
const result_child = await dbConnection.manager.save(created_child)
|
||||
rrId_1 = result_child.id
|
||||
const result_child = await dbConnection.manager.save(created_child)
|
||||
rrId_1 = result_child.id
|
||||
|
||||
const created_2 = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big_1",
|
||||
label: "Too Big 1",
|
||||
})
|
||||
const created_2 = dbConnection.manager.create(ReturnReason, {
|
||||
value: "too_big_1",
|
||||
label: "Too Big 1",
|
||||
})
|
||||
|
||||
const result_2 = await dbConnection.manager.save(created_2)
|
||||
rrId_2 = result_2.id
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
const result_2 = await dbConnection.manager.save(created_2)
|
||||
rrId_2 = result_2.id
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
const path = require("path")
|
||||
const {
|
||||
ShippingProfile,
|
||||
ShippingOption,
|
||||
} = require("@medusajs/medusa")
|
||||
const { ShippingProfile, ShippingOption } = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../helpers/use-api")
|
||||
@@ -30,35 +27,30 @@ describe("/store/carts", () => {
|
||||
|
||||
describe("/store/swaps", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await orderSeeder(dbConnection)
|
||||
await orderSeeder(dbConnection)
|
||||
|
||||
const manager = dbConnection.manager
|
||||
await manager.query(
|
||||
`UPDATE "swap" SET cart_id='test-cart-2' WHERE id = 'test-swap'`
|
||||
)
|
||||
await manager.query(
|
||||
`UPDATE "payment" SET swap_id=NULL WHERE id = 'test-payment-swap'`
|
||||
)
|
||||
const manager = dbConnection.manager
|
||||
await manager.query(
|
||||
`UPDATE "swap" SET cart_id='test-cart-2' WHERE id = 'test-swap'`
|
||||
)
|
||||
await manager.query(
|
||||
`UPDATE "payment" SET swap_id=NULL WHERE id = 'test-payment-swap'`
|
||||
)
|
||||
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
})
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "return-option",
|
||||
name: "Test ret",
|
||||
profile_id: defaultProfile.id,
|
||||
region_id: "test-region",
|
||||
provider_id: "test-ful",
|
||||
data: {},
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
is_return: true,
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
const defaultProfile = await manager.findOne(ShippingProfile, {
|
||||
type: "default",
|
||||
})
|
||||
await manager.insert(ShippingOption, {
|
||||
id: "return-option",
|
||||
name: "Test ret",
|
||||
profile_id: defaultProfile.id,
|
||||
region_id: "test-region",
|
||||
provider_id: "test-ful",
|
||||
data: {},
|
||||
price_type: "flat_rate",
|
||||
amount: 1000,
|
||||
is_return: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
|
||||
Reference in New Issue
Block a user