Files
medusa-store/integration-tests/modules/__tests__/event-bus/index.spec.ts
Harminder Virk f579f0b3be feat: restructure events payload (#8143)
* refactor: restructure events payload

Breaking change: This PR changes the event payload accepted by the event
listeners

* refactor: fix failing tests and implement feedback

* add integration tests

* fix timeout

---------

Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
2024-07-16 17:09:16 +01:00

51 lines
1.4 KiB
TypeScript

import { medusaIntegrationTestRunner } from "medusa-test-utils"
import { MedusaContainer } from "@medusajs/types"
import { composeMessage, ModuleRegistrationName } from "@medusajs/utils"
import testEventPayloadHandlerMock from "../../dist/subscribers/test-event-payload"
jest.setTimeout(30000)
medusaIntegrationTestRunner({
testSuite: ({ getContainer }) => {
let container!: MedusaContainer
describe("EventBusModule", () => {
beforeAll(() => {
container = getContainer()
})
it(`should emit event with the expected shape to be received by the subscribers`, async () => {
const eventBus = container.resolve(ModuleRegistrationName.EVENT_BUS)
const eventName = "test-event-payload"
await eventBus.emit(
composeMessage(eventName, {
data: {
test: "foo",
},
object: "object",
source: "source",
action: "action",
})
)
expect(testEventPayloadHandlerMock).toHaveBeenCalled()
expect(
testEventPayloadHandlerMock.mock.calls[0][0].pluginOptions
).toEqual({})
expect(testEventPayloadHandlerMock.mock.calls[0][0].event).toEqual({
name: eventName,
data: {
test: "foo",
},
metadata: {
object: "object",
source: "source",
action: "action",
},
})
})
})
},
})