chore: ability to group events on redis event bus (#7655)

* chore: ability to group events on redis event bus

* chore: fix tests

* Update packages/modules/event-bus-redis/src/services/event-bus-redis.ts

Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>

* chore: change shape of input and body data

* chore: fix builds

* chore: address comments

* chore: fix unit test

---------

Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
This commit is contained in:
Riqwan Thamir
2024-06-10 22:15:43 +02:00
committed by GitHub
parent 3b8160b564
commit 39ddba2491
24 changed files with 924 additions and 732 deletions

View File

@@ -1,9 +1,12 @@
import { IUserModuleService } from "@medusajs/types/dist/user"
import { MockEventBusService } from "medusa-test-utils"
import { Modules } from "@medusajs/modules-sdk"
import { IUserModuleService } from "@medusajs/types/dist/user"
import { UserEvents } from "@medusajs/utils"
import {
MockEventBusService,
moduleIntegrationTestRunner,
SuiteOptions,
} from "medusa-test-utils"
import { createInvites } from "../../../__fixtures__/invite"
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
jest.setTimeout(30000)
@@ -178,9 +181,7 @@ moduleIntegrationTestRunner({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({
body: expect.objectContaining({
data: { id: "1" },
}),
data: { id: "1" },
eventName: UserEvents.invite_updated,
}),
])
@@ -197,9 +198,7 @@ moduleIntegrationTestRunner({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({
body: expect.objectContaining({
data: { id: "1" },
}),
data: { id: "1" },
eventName: UserEvents.invite_token_generated,
}),
])
@@ -228,27 +227,19 @@ moduleIntegrationTestRunner({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({
body: expect.objectContaining({
data: { id: "1" },
}),
data: { id: "1" },
eventName: UserEvents.invite_created,
}),
expect.objectContaining({
body: expect.objectContaining({
data: { id: "2" },
}),
data: { id: "2" },
eventName: UserEvents.invite_created,
}),
expect.objectContaining({
body: expect.objectContaining({
data: { id: "1" },
}),
data: { id: "1" },
eventName: UserEvents.invite_token_generated,
}),
expect.objectContaining({
body: expect.objectContaining({
data: { id: "2" },
}),
data: { id: "2" },
eventName: UserEvents.invite_token_generated,
}),
])

View File

@@ -1,9 +1,12 @@
import { IUserModuleService } from "@medusajs/types/dist/user"
import { MockEventBusService } from "medusa-test-utils"
import { Modules } from "@medusajs/modules-sdk"
import { IUserModuleService } from "@medusajs/types/dist/user"
import { UserEvents } from "@medusajs/utils"
import {
MockEventBusService,
moduleIntegrationTestRunner,
SuiteOptions,
} from "medusa-test-utils"
import { createUsers } from "../../../__fixtures__/user"
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
jest.setTimeout(30000)
@@ -190,9 +193,7 @@ moduleIntegrationTestRunner({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({
body: expect.objectContaining({
data: { id: "1" },
}),
data: { id: "1" },
eventName: UserEvents.updated,
}),
])
@@ -222,15 +223,11 @@ moduleIntegrationTestRunner({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({
body: expect.objectContaining({
data: { id: "1" },
}),
data: { id: "1" },
eventName: UserEvents.created,
}),
expect.objectContaining({
body: expect.objectContaining({
data: { id: "2" },
}),
data: { id: "2" },
eventName: UserEvents.created,
}),
])