feat(medusa, medusa-js, medusa-react): Bulk add Products to a SalesChannel (#1833)

This commit is contained in:
Adrien de Peretti
2022-07-14 16:39:44 +02:00
committed by GitHub
parent cdd91974f9
commit f35ea5156a
12 changed files with 377 additions and 20 deletions

View File

@@ -6,7 +6,6 @@ const { useApi } = require("../../../helpers/use-api")
const { useDb } = require("../../../helpers/use-db")
const adminSeeder = require("../../helpers/admin-seeder")
const {
simpleSalesChannelFactory,
simpleProductFactory,
@@ -744,4 +743,72 @@ describe("sales channels", () => {
expect(attachedProduct.sales_channels.length).toBe(0)
})
})
describe("POST /admin/sales-channels/:id/products/batch", () => {
let salesChannel
let product
beforeEach(async() => {
try {
await adminSeeder(dbConnection)
salesChannel = await simpleSalesChannelFactory(dbConnection, {
name: "test name",
description: "test description",
})
product = await simpleProductFactory(dbConnection, {
id: "product_1",
title: "test title",
})
} catch (e) {
console.error(e)
}
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("should add products to a sales channel", async() => {
const api = useApi()
const payload = {
product_ids: [{ id: product.id }]
}
let response = await api.post(
`/admin/sales-channels/${salesChannel.id}/products/batch`,
payload,
adminReqConfig
)
expect(response.status).toEqual(200)
expect(response.data.sales_channel).toEqual({
id: expect.any(String),
name: "test name",
description: "test description",
is_disabled: false,
created_at: expect.any(String),
updated_at: expect.any(String),
deleted_at: null,
})
let attachedProduct = await dbConnection.manager.findOne(Product, {
where: { id: product.id },
relations: ["sales_channels"]
})
expect(attachedProduct.sales_channels.length).toBe(1)
expect(attachedProduct.sales_channels).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
name: "test name",
description: "test description",
is_disabled: false,
})
])
)
})
})
})