feat(medusa): Attach or update cart sales channel (#1873)

What

Allow to create a cart with a sales channel, otherwise the default one is attached.
Also allow to update the sales channel on an existing cart and in that case the line items that does not belongs to the new sales channel attached are removed

How

Updating existing end points and service method to integrate the new requirements

Tests

Add new integration tests

Fixes CORE-270
Fixes CORE-272

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2022-07-27 16:54:05 +00:00
committed by GitHub
co-authored by Oliver Windall Juhl
parent 8dd85e5f03
commit df66378535
17 changed files with 595 additions and 169 deletions
@@ -110,18 +110,6 @@ Object {
}
`;
exports[`sales channels GET /store/cart/:id with saleschannel returns cart with sales channel for single cart 1`] = `
Object {
"created_at": Any<String>,
"deleted_at": null,
"description": "test description",
"id": Any<String>,
"is_disabled": false,
"name": "test name",
"updated_at": Any<String>,
}
`;
exports[`sales channels POST /admin/sales-channels successfully creates a sales channel 1`] = `
Object {
"sales_channel": ObjectContaining {
@@ -311,11 +311,8 @@ describe("sales channels", () => {
await simpleSalesChannelFactory(dbConnection, {
name: "Default channel",
id: "test-channel",
is_default: true,
})
await dbConnection.manager.query(
`UPDATE store SET default_sales_channel_id = 'test-channel'`
)
} catch (e) {
console.error(e)
}
@@ -620,45 +617,6 @@ describe("sales channels", () => {
})
})
describe("GET /store/cart/:id with saleschannel", () => {
let cart
beforeEach(async () => {
try {
await adminSeeder(dbConnection)
cart = await simpleCartFactory(dbConnection, {
sales_channel: {
name: "test name",
description: "test description",
},
})
} catch (err) {
console.log(err)
}
})
afterEach(async () => {
const db = useDb()
await db.teardown()
})
it("returns cart with sales channel for single cart", async () => {
const api = useApi()
const response = await api.get(`/store/carts/${cart.id}`, adminReqConfig)
expect(response.data.cart.sales_channel).toBeTruthy()
expect(response.data.cart.sales_channel).toMatchSnapshot({
id: expect.any(String),
name: "test name",
description: "test description",
is_disabled: false,
created_at: expect.any(String),
updated_at: expect.any(String),
})
})
})
describe("DELETE /admin/sales-channels/:id/products/batch", () => {
let salesChannel
let product