feat(cart): Add line items in cart-creation (#6114)

This commit is contained in:
Oli Juhl authored and GitHub committed 2024-01-18 14:39:40 +01:00
1 parent 7f7cb2a263
commit b132ff7669
4 files changed
+120 -9

No files matched your search

@@ -124,6 +124,91 @@ describe("Cart Module Service", () => {
})
)
})
it("should create a cart with items", async () => {
const createdCart = await service.create({
currency_code: "eur",
items: [
{
title: "test",
quantity: 1,
unit_price: 100,
},
],
})
const cart = await service.retrieve(createdCart.id, {
relations: ["items"],
})
expect(cart).toEqual(
expect.objectContaining({
id: createdCart.id,
currency_code: "eur",
items: expect.arrayContaining([
expect.objectContaining({
title: "test",
unit_price: 100,
}),
]),
})
)
})
it("should create multiple carts with items", async () => {
const createdCarts = await service.create([
{
currency_code: "eur",
items: [
{
title: "test",
quantity: 1,
unit_price: 100,
},
],
},
{
currency_code: "usd",
items: [
{
title: "test-2",
quantity: 2,
unit_price: 200,
},
],
},
])
const carts = await service.list(
{ id: createdCarts.map((c) => c.id) },
{
relations: ["items"],
}
)
expect(carts).toEqual(
expect.arrayContaining([
expect.objectContaining({
currency_code: "eur",
items: expect.arrayContaining([
expect.objectContaining({
title: "test",
unit_price: 100,
}),
]),
}),
expect.objectContaining({
currency_code: "usd",
items: expect.arrayContaining([
expect.objectContaining({
title: "test-2",
unit_price: 200,
}),
]),
}),
])
)
})
})
describe("update", () => {