1 import { MedusaContainer } from "@medusajs/types"
2 import { Modules, composeMessage } from "@medusajs/utils"
3 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
4 import testEventPayloadHandlerMock from "../../src/subscribers/test-event-payload"
5
6 jest.setTimeout(30000)
7
8 medusaIntegrationTestRunner({
9 testSuite: ({ getContainer }) => {
10 let container!: MedusaContainer
11
12 describe("EventBusModule", () => {
13 beforeAll(() => {
14 container = getContainer()
15 })
16
17 it(`should emit event with the expected shape to be received by the subscribers`, async () => {
18 const eventBus = container.resolve(Modules.EVENT_BUS)
19 const eventName = "test-event-payload"
20
21 await eventBus.emit(
22 composeMessage(eventName, {
23 data: {
24 test: "foo",
25 },
26 object: "object",
27 source: "source",
28 action: "action",
29 })
30 )
31
32 expect(testEventPayloadHandlerMock).toHaveBeenCalled()
33 expect(
34 testEventPayloadHandlerMock.mock.calls[0][0].pluginOptions
35 ).toEqual(expect.any(Object))
36 expect(testEventPayloadHandlerMock.mock.calls[0][0].event).toEqual({
37 name: eventName,
38 data: {
39 test: "foo",
40 },
41 metadata: {
42 object: "object",
43 source: "source",
44 action: "action",
45 created_at: expect.any(Date),
46 published_at: expect.any(Date),
47 },
48 })
49 })
50 })
51 },
52 })