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>
This commit is contained in:
Harminder VirkandAdrien de Peretti authored and GitHub committed 2024-07-16 17:09:16 +01:00
1 parent 5813216c88
commit f579f0b3be
26 files changed
+194 -111

No files matched your search

@@ -681,7 +681,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({
data: { id: productCategoryOne.id },
eventName: "product-category.deleted",
name: "product-category.deleted",
metadata: {
action: "",
object: "",
@@ -280,7 +280,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
{
eventName: "product-collection.deleted",
name: "product-collection.deleted",
data: { id: collectionId },
metadata: {
action: "",
@@ -309,7 +309,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([
{
data: { id: collectionId },
eventName: "product-collection.updated",
name: "product-collection.updated",
},
])
})
@@ -505,7 +505,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([
{
data: { id: collections[0].id },
eventName: "product-collection.created",
name: "product-collection.created",
},
])
})
@@ -283,7 +283,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
{
eventName: "product.updated",
name: "product.updated",
data: { id: productOne.id },
},
])
@@ -631,7 +631,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledTimes(1)
expect(eventBusSpy).toHaveBeenCalledWith([
{
eventName: "product.created",
name: "product.created",
data: { id: products[0].id },
},
])
@@ -721,7 +721,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([
{
eventName: "product.created",
name: "product.created",
data: { id: products[0].id },
},
])
@@ -873,7 +873,7 @@ export default class ProductModuleService
await this.eventBusModuleService_?.emit<ProductCollectionEventData>(
collections.map(({ id }) => ({
eventName: ProductCollectionEvents.COLLECTION_CREATED,
name: ProductCollectionEvents.COLLECTION_CREATED,
data: { id },
}))
)
@@ -946,7 +946,7 @@ export default class ProductModuleService
if (created.length) {
await this.eventBusModuleService_?.emit<ProductCollectionEventData>(
created.map(({ id }) => ({
eventName: ProductCollectionEvents.COLLECTION_CREATED,
name: ProductCollectionEvents.COLLECTION_CREATED,
data: { id },
}))
)
@@ -955,7 +955,7 @@ export default class ProductModuleService
if (updated.length) {
await this.eventBusModuleService_?.emit<ProductCollectionEventData>(
updated.map(({ id }) => ({
eventName: ProductCollectionEvents.COLLECTION_UPDATED,
name: ProductCollectionEvents.COLLECTION_UPDATED,
data: { id },
}))
)
@@ -1016,7 +1016,7 @@ export default class ProductModuleService
await this.eventBusModuleService_?.emit<ProductCollectionEventData>(
updatedCollections.map(({ id }) => ({
eventName: ProductCollectionEvents.COLLECTION_UPDATED,
name: ProductCollectionEvents.COLLECTION_UPDATED,
data: { id },
}))
)
@@ -1279,7 +1279,7 @@ export default class ProductModuleService
await this.eventBusModuleService_?.emit<ProductEventData>(
createdProducts.map(({ id }) => ({
eventName: ProductEvents.PRODUCT_CREATED,
name: ProductEvents.PRODUCT_CREATED,
data: { id },
}))
)
@@ -1327,7 +1327,7 @@ export default class ProductModuleService
if (created.length) {
await this.eventBusModuleService_?.emit<ProductEventData>(
created.map(({ id }) => ({
eventName: ProductEvents.PRODUCT_CREATED,
name: ProductEvents.PRODUCT_CREATED,
data: { id },
}))
)
@@ -1336,7 +1336,7 @@ export default class ProductModuleService
if (updated.length) {
await this.eventBusModuleService_?.emit<ProductEventData>(
updated.map(({ id }) => ({
eventName: ProductEvents.PRODUCT_UPDATED,
name: ProductEvents.PRODUCT_UPDATED,
data: { id },
}))
)
@@ -1390,7 +1390,7 @@ export default class ProductModuleService
await this.eventBusModuleService_?.emit<ProductEventData>(
updatedProducts.map(({ id }) => ({
eventName: ProductEvents.PRODUCT_UPDATED,
name: ProductEvents.PRODUCT_UPDATED,
data: { id },
}))
)