feat(fulfillment): Events management (#6730)
**What** This pr includes some cleanup and refactoring around the abstract event emitter method for the module service to not rely on a named class property but instead on resolution naming. Includes fulfillment set events on creation. The idea is that if that pr allows us to align and agreed on the approach as well as including the cleanup for other pr to use, If this gets merged I ll continue with another pr to do the rest of the event management partially fix CORE-1735
This commit is contained in:
1 parent
06f22bb48a
commit
c658bd0233
12 files changed
+356
-19
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import { EventBusTypes } from "@medusajs/types"
|
||||
|
||||
export function buildExpectedEventMessageShape(options: {
|
||||
eventName: string
|
||||
action: string
|
||||
object: string
|
||||
eventGroupId?: string
|
||||
data: any
|
||||
options?: Record<string, unknown>
|
||||
}): EventBusTypes.Message {
|
||||
return {
|
||||
eventName: options.eventName,
|
||||
body: {
|
||||
metadata: {
|
||||
action: options.action,
|
||||
eventGroupId: options.eventGroupId,
|
||||
service: "fulfillment",
|
||||
object: options.object,
|
||||
},
|
||||
data: options.data,
|
||||
},
|
||||
options: options.options,
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { IFulfillmentModuleService } from "@medusajs/types"
|
||||
|
||||
export * from "./shipping-options"
|
||||
export * from "./fulfillment"
|
||||
export * from "./events"
|
||||
|
||||
export async function createFullDataStructure(
|
||||
service: IFulfillmentModuleService,
|
||||
|
||||
+114
-1
@@ -6,14 +6,26 @@ import {
|
||||
ServiceZoneDTO,
|
||||
UpdateFulfillmentSetDTO,
|
||||
} from "@medusajs/types"
|
||||
import { GeoZoneType } from "@medusajs/utils"
|
||||
import { FulfillmentEvents, GeoZoneType } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { MockEventBusService } from "medusa-test-utils/dist"
|
||||
import { buildExpectedEventMessageShape } from "../../__fixtures__"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleName: Modules.FULFILLMENT,
|
||||
testSuite: ({ service }: SuiteOptions<IFulfillmentModuleService>) => {
|
||||
let eventBusEmitSpy
|
||||
|
||||
beforeEach(() => {
|
||||
eventBusEmitSpy = jest.spyOn(MockEventBusService.prototype, "emit")
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
describe("Fulfillment Module Service", () => {
|
||||
describe("read", () => {
|
||||
it("should list fulfillment sets with a filter", async function () {
|
||||
@@ -153,6 +165,15 @@ moduleIntegrationTestRunner({
|
||||
type: data.type,
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.created,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should create a collection of fulfillment sets", async function () {
|
||||
@@ -180,6 +201,18 @@ moduleIntegrationTestRunner({
|
||||
type: data_.type,
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
expect.arrayContaining([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.created,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSets[i].id },
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
++i
|
||||
}
|
||||
})
|
||||
@@ -210,6 +243,21 @@ moduleIntegrationTestRunner({
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.created,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.service_zone_created,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].id },
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should create a collection of fulfillment sets with new service zones", async function () {
|
||||
@@ -262,6 +310,24 @@ moduleIntegrationTestRunner({
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
expect.arrayContaining([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.created,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSets[i].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.service_zone_created,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSets[i].service_zones[0].id },
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
++i
|
||||
}
|
||||
})
|
||||
@@ -305,6 +371,27 @@ moduleIntegrationTestRunner({
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.created,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.service_zone_created,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.geo_zone_created,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].geo_zones[0].id },
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("should create a collection of fulfillment sets with new service zones and new geo zones", async function () {
|
||||
@@ -385,6 +472,32 @@ moduleIntegrationTestRunner({
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
expect.arrayContaining([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.created,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSets[i].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.service_zone_created,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSets[i].service_zones[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.geo_zone_created,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: {
|
||||
id: fulfillmentSets[i].service_zones[0].geo_zones[0].id,
|
||||
},
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
++i
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user