feat(core-flows): validate hook in cart workflows (#10967)

* feat(core-flows): validate hook

* rm only
This commit is contained in:
Carlos R. L. Rodrigues
2025-01-15 20:49:46 -03:00
committed by GitHub
parent 2a25b4d95f
commit 11f98f374c
14 changed files with 194 additions and 74 deletions

View File

@@ -845,6 +845,11 @@ medusaIntegrationTestRunner({
describe("UpdateCartWorkflow", () => {
it("should remove item with custom price when region is updated", async () => {
const hookCallback = jest.fn()
addToCartWorkflow.hooks.validate((data) => {
hookCallback(data)
})
const salesChannel = await scModuleService.createSalesChannels({
name: "Webshop",
})
@@ -926,35 +931,51 @@ medusaIntegrationTestRunner({
select: ["id", "region_id", "currency_code", "sales_channel_id"],
})
const wfInput = {
items: [
{
variant_id: product.variants[0].id,
quantity: 1,
},
{
title: "Test item",
subtitle: "Test subtitle",
thumbnail: "some-url",
requires_shipping: true,
is_discountable: false,
is_tax_inclusive: false,
unit_price: 1500,
metadata: {
foo: "bar",
},
quantity: 1,
},
],
cart_id: cart.id,
}
await addToCartWorkflow(appContainer).run({
input: {
items: [
{
variant_id: product.variants[0].id,
quantity: 1,
},
{
title: "Test item",
subtitle: "Test subtitle",
thumbnail: "some-url",
requires_shipping: true,
is_discountable: false,
is_tax_inclusive: false,
unit_price: 1500,
metadata: {
foo: "bar",
},
quantity: 1,
},
],
cart_id: cart.id,
},
input: wfInput,
})
cart = await cartModuleService.retrieveCart(cart.id, {
relations: ["items"],
})
expect(hookCallback).toHaveBeenCalledWith({
cart: {
completed_at: null,
id: expect.stringContaining("cart_"),
sales_channel_id: expect.stringContaining("sc_"),
currency_code: "usd",
region_id: expect.stringContaining("reg_"),
item_total: 0,
total: 0,
email: null,
customer_id: null,
},
input: wfInput,
})
expect(cart).toEqual(
expect.objectContaining({
id: cart.id,