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
co-authored by Adrien de Peretti
parent 3b8160b564
commit 39ddba2491
24 changed files with 924 additions and 732 deletions
@@ -291,8 +291,9 @@ moduleIntegrationTestRunner<IProductModuleService>({
})
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith("product-category.created", {
id: category.id,
expect(eventBusSpy).toHaveBeenCalledWith({
data: { id: category.id },
eventName: "product-category.created",
})
})
@@ -380,8 +381,9 @@ moduleIntegrationTestRunner<IProductModuleService>({
})
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith("product-category.updated", {
id: productCategoryZero.id,
expect(eventBusSpy).toHaveBeenCalledWith({
data: { id: productCategoryZero.id },
eventName: "product-category.updated",
})
})
@@ -547,8 +549,9 @@ moduleIntegrationTestRunner<IProductModuleService>({
await service.deleteCategory(productCategoryOne.id)
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith("product-category.deleted", {
id: productCategoryOne.id,
expect(eventBusSpy).toHaveBeenCalledWith({
data: { id: productCategoryOne.id },
eventName: "product-category.deleted",
})
})
@@ -298,8 +298,8 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
{
eventName: "product-collection.updated",
data: { id: collectionId },
eventName: "product-collection.updated",
},
])
})
@@ -488,16 +488,14 @@ moduleIntegrationTestRunner<IProductModuleService>({
const eventBusSpy = jest.spyOn(MockEventBusService.prototype, "emit")
const collections = await service.createCollections([
{
title: "New Collection",
},
{ title: "New Collection" },
])
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
{
eventName: "product-collection.created",
data: { id: collections[0].id },
eventName: "product-collection.created",
},
])
})
@@ -51,8 +51,8 @@ import {
UpdateTagInput,
UpdateTypeInput,
} from "../types"
import { entityNameToLinkableKeysMap, joinerConfig } from "./../joiner-config"
import { eventBuilders } from "../utils"
import { entityNameToLinkableKeysMap, joinerConfig } from "./../joiner-config"
type InjectedDependencies = {
baseRepository: DAL.RepositoryService
@@ -1134,10 +1134,10 @@ export default class ProductModuleService<
sharedContext
)
await this.eventBusModuleService_?.emit<ProductCategoryEventData>(
ProductCategoryEvents.CATEGORY_CREATED,
{ id: productCategory.id }
)
await this.eventBusModuleService_?.emit<ProductCategoryEventData>({
eventName: ProductCategoryEvents.CATEGORY_CREATED,
data: { id: productCategory.id },
})
return productCategory
}
@@ -1154,10 +1154,10 @@ export default class ProductModuleService<
sharedContext
)
await this.eventBusModuleService_?.emit<ProductCategoryEventData>(
ProductCategoryEvents.CATEGORY_UPDATED,
{ id: productCategory.id }
)
await this.eventBusModuleService_?.emit<ProductCategoryEventData>({
eventName: ProductCategoryEvents.CATEGORY_UPDATED,
data: { id: productCategory.id },
})
return await this.baseRepository_.serialize(productCategory, {
populate: true,
@@ -1171,10 +1171,10 @@ export default class ProductModuleService<
): Promise<void> {
await this.productCategoryService_.delete(categoryId, sharedContext)
await this.eventBusModuleService_?.emit<ProductCategoryEventData>(
ProductCategoryEvents.CATEGORY_DELETED,
{ id: categoryId }
)
await this.eventBusModuleService_?.emit<ProductCategoryEventData>({
eventName: ProductCategoryEvents.CATEGORY_DELETED,
data: { id: categoryId },
})
}
create(