chore: Rename all event keys to uppercase (#7787)

* chore: Rename all event keys to uppercase

* fix: Remove main entity from event builder
This commit is contained in:
Stevche Radevski authored and GitHub committed 2024-06-21 10:41:35 +02:00
1 parent 937a632eb6
commit ee35379e21
22 files changed
+160 -181

No files matched your search

@@ -92,7 +92,7 @@ export const completeCartWorkflow = createWorkflow(
}, },
]) ])
emitEventStep({ eventName: OrderEvents.placed, data: { id: order.id } }) emitEventStep({ eventName: OrderEvents.PLACED, data: { id: order.id } })
return order return order
} }
+26 -46
View File
@@ -2,56 +2,43 @@ import { camelToSnakeCase, kebabCase, lowerCaseFirst } from "../common"
import { CommonEvents } from "./common-events" import { CommonEvents } from "./common-events"
import { KebabCase, SnakeCase } from "@medusajs/types" import { KebabCase, SnakeCase } from "@medusajs/types"
type ReturnType<TNames extends string[]> = TNames extends [ type ReturnType<TNames extends string[]> = {
infer TFirstName, [K in TNames[number] as `${Uppercase<
...infer TRest SnakeCase<K & string>
] >}_CREATED`]: `${KebabCase<K & string>}.created`
? {
[K in Lowercase<CommonEvents>]: `${KebabCase<TFirstName & string>}.${K}`
} & { } & {
[K in TRest[number] as `${SnakeCase<K & string>}_created`]: `${KebabCase< [K in TNames[number] as `${Uppercase<
K & string SnakeCase<K & string>
>}.created` >}_UPDATED`]: `${KebabCase<K & string>}.updated`
} & { } & {
[K in TRest[number] as `${SnakeCase<K & string>}_updated`]: `${KebabCase< [K in TNames[number] as `${Uppercase<
K & string SnakeCase<K & string>
>}.updated` >}_DELETED`]: `${KebabCase<K & string>}.deleted`
} & { } & {
[K in TRest[number] as `${SnakeCase<K & string>}_deleted`]: `${KebabCase< [K in TNames[number] as `${Uppercase<
K & string SnakeCase<K & string>
>}.deleted` >}_RESTORED`]: `${KebabCase<K & string>}.restored`
} & { } & {
[K in TRest[number] as `${SnakeCase<K & string>}_restored`]: `${KebabCase< [K in TNames[number] as `${Uppercase<
K & string SnakeCase<K & string>
>}.restored` >}_ATTACHED`]: `${KebabCase<K & string>}.attached`
} & { } & {
[K in TRest[number] as `${SnakeCase<K & string>}_attached`]: `${KebabCase< [K in TNames[number] as `${Uppercase<
K & string SnakeCase<K & string>
>}.attached` >}_DETACHED`]: `${KebabCase<K & string>}.detached`
} & {
[K in TRest[number] as `${SnakeCase<K & string>}_detached`]: `${KebabCase<
K & string
>}.detached`
} }
: {}
/** /**
* From the given strings it will produce the event names accordingly. * From the given strings it will produce the event names accordingly.
* the result will look like: * the result will look like:
* input: 'serviceZone' * input: 'serviceZone'
* output: { * output: {
* created: 'fulfillment-set.created', * SERVICE_ZONE_CREATED: 'service-zone.created',
* updated: 'fulfillment-set.updated', * SERVICE_ZONE_UPDATED: 'service-zone.updated',
* deleted: 'fulfillment-set.deleted', * SERVICE_ZONE_DELETED: 'service-zone.deleted',
* restored: 'fulfillment-set.restored', * SERVICE_ZONE_RESTORED: 'service-zone.restored',
* attached: 'fulfillment-set.attached', * SERVICE_ZONE_ATTACHED: 'service-zone.attached',
* detached: 'fulfillment-set.detached', * SERVICE_ZONE_DETACHED: 'service-zone.detached',
* service_zone_created: 'service-zone.created',
* service_zone_updated: 'service-zone.updated',
* service_zone_deleted: 'service-zone.deleted',
* service_zone_restored: 'service-zone.restored',
* service_zone_attached: 'service-zone.attached',
* service_zone_detached: 'service-zone.detached',
* ... * ...
* } * }
* *
@@ -65,16 +52,9 @@ export function buildEventNamesFromEntityName<TNames extends string[]>(
for (let i = 0; i < names.length; i++) { for (let i = 0; i < names.length; i++) {
const name = names[i] const name = names[i]
const snakedCaseName = lowerCaseFirst(camelToSnakeCase(name)) const snakedCaseName = camelToSnakeCase(name).toUpperCase()
const kebabCaseName = lowerCaseFirst(kebabCase(name)) const kebabCaseName = lowerCaseFirst(kebabCase(name))
if (i === 0) {
for (const event of Object.values(CommonEvents) as string[]) {
events[event] = `${prefix ? prefix + "." : ""}${kebabCaseName}.${event}`
}
continue
}
for (const event of Object.values(CommonEvents) as string[]) { for (const event of Object.values(CommonEvents) as string[]) {
events[`${snakedCaseName}_${event}`] = `${ events[`${snakedCaseName}_${event}`] = `${
prefix ? prefix + "." : "" prefix ? prefix + "." : ""
@@ -16,20 +16,17 @@ import { Context, EventBusTypes } from "@medusajs/types"
* sharedContext, * sharedContext,
* }) * })
* *
* @param isMainEntity
* @param action * @param action
* @param object * @param object
* @param eventsEnum * @param eventsEnum
* @param service * @param service
*/ */
export function eventBuilderFactory({ export function eventBuilderFactory({
isMainEntity,
action, action,
object, object,
eventsEnum, eventsEnum,
source, source,
}: { }: {
isMainEntity?: boolean
action: string action: string
object: string object: string
eventsEnum: Record<string, string> eventsEnum: Record<string, string>
@@ -55,9 +52,7 @@ export function eventBuilderFactory({
action, action,
context: sharedContext, context: sharedContext,
data: { id: dataItem.id }, data: { id: dataItem.id },
eventName: isMainEntity eventName: eventsEnum[`${object}_${action}`],
? eventsEnum[action]
: eventsEnum[`${object}_${action}`],
object, object,
}) })
}) })
+3 -3
View File
@@ -1,5 +1,5 @@
export const OrderEvents = { export const OrderEvents = {
placed: "order.placed", PLACED: "order.placed",
canceled: "order.canceled", CANCELED: "order.canceled",
completed: "order.completed", COMPLETED: "order.completed",
} }
+1 -1
View File
@@ -5,5 +5,5 @@ const eventBaseNames: ["user", "invite"] = ["user", "invite"]
export const UserEvents = { export const UserEvents = {
...buildEventNamesFromEntityName(eventBaseNames, Modules.USER), ...buildEventNamesFromEntityName(eventBaseNames, Modules.USER),
invite_token_generated: `${Modules.USER}.user.invite.token_generated`, INVITE_TOKEN_GENERATED: `${Modules.USER}.user.invite.token_generated`,
} }
@@ -167,7 +167,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.created, eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
action: "created", action: "created",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: fulfillmentSet.id }, data: { id: fulfillmentSet.id },
@@ -204,7 +204,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.created, eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
action: "created", action: "created",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: fulfillmentSets[i].id }, data: { id: fulfillmentSets[i].id },
@@ -245,13 +245,13 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.created, eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
action: "created", action: "created",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: fulfillmentSet.id }, data: { id: fulfillmentSet.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: fulfillmentSet.service_zones[0].id }, data: { id: fulfillmentSet.service_zones[0].id },
@@ -313,13 +313,13 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.created, eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
action: "created", action: "created",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: fulfillmentSets[i].id }, data: { id: fulfillmentSets[i].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: fulfillmentSets[i].service_zones[0].id }, data: { id: fulfillmentSets[i].service_zones[0].id },
@@ -373,19 +373,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.created, eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
action: "created", action: "created",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: fulfillmentSet.id }, data: { id: fulfillmentSet.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: fulfillmentSet.service_zones[0].id }, data: { id: fulfillmentSet.service_zones[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { id: fulfillmentSet.service_zones[0].geo_zones[0].id }, data: { id: fulfillmentSet.service_zones[0].geo_zones[0].id },
@@ -475,19 +475,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.created, eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
action: "created", action: "created",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: fulfillmentSets[i].id }, data: { id: fulfillmentSets[i].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: fulfillmentSets[i].service_zones[0].id }, data: { id: fulfillmentSets[i].service_zones[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { data: {
@@ -633,7 +633,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.updated, eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
action: "updated", action: "updated",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: updatedFulfillmentSets.id }, data: { id: updatedFulfillmentSets.id },
@@ -691,7 +691,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenLastCalledWith( expect(eventBusEmitSpy).toHaveBeenLastCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.updated, eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
action: "updated", action: "updated",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: currentFullfillmentSet.id }, data: { id: currentFullfillmentSet.id },
@@ -781,19 +781,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenLastCalledWith( expect(eventBusEmitSpy).toHaveBeenLastCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.updated, eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
action: "updated", action: "updated",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: updatedFulfillmentSet.id }, data: { id: updatedFulfillmentSet.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: updatedFulfillmentSet.service_zones[0].id }, data: { id: updatedFulfillmentSet.service_zones[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { data: {
@@ -801,13 +801,13 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
}, },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_deleted, eventName: FulfillmentEvents.SERVICE_ZONE_DELETED,
action: "deleted", action: "deleted",
object: "service_zone", object: "service_zone",
data: { id: createdFulfillmentSet.service_zones[0].id }, data: { id: createdFulfillmentSet.service_zones[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_deleted, eventName: FulfillmentEvents.GEO_ZONE_DELETED,
action: "deleted", action: "deleted",
object: "geo_zone", object: "geo_zone",
data: { data: {
@@ -899,19 +899,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenLastCalledWith( expect(eventBusEmitSpy).toHaveBeenLastCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.updated, eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
action: "updated", action: "updated",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: updatedFulfillmentSet.id }, data: { id: updatedFulfillmentSet.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: createdServiceZone.id }, data: { id: createdServiceZone.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { data: {
@@ -1050,19 +1050,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenLastCalledWith( expect(eventBusEmitSpy).toHaveBeenLastCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.updated, eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
action: "updated", action: "updated",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: expectedFulfillmentSet.id }, data: { id: expectedFulfillmentSet.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: expectedFulfillmentSet.service_zones[0].id }, data: { id: expectedFulfillmentSet.service_zones[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { data: {
@@ -1071,13 +1071,13 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
}, },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_deleted, eventName: FulfillmentEvents.SERVICE_ZONE_DELETED,
action: "deleted", action: "deleted",
object: "service_zone", object: "service_zone",
data: { id: originalFulfillmentSet.service_zones[0].id }, data: { id: originalFulfillmentSet.service_zones[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_deleted, eventName: FulfillmentEvents.GEO_ZONE_DELETED,
action: "deleted", action: "deleted",
object: "geo_zone", object: "geo_zone",
data: { data: {
@@ -1209,19 +1209,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenLastCalledWith( expect(eventBusEmitSpy).toHaveBeenLastCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.updated, eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
action: "updated", action: "updated",
object: "fulfillment_set", object: "fulfillment_set",
data: { id: expectedFulfillmentSet.id }, data: { id: expectedFulfillmentSet.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_created, eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
action: "created", action: "created",
object: "service_zone", object: "service_zone",
data: { id: createdServiceZone.id }, data: { id: createdServiceZone.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { data: {
@@ -159,25 +159,25 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_created, eventName: FulfillmentEvents.FULFILLMENT_CREATED,
action: "created", action: "created",
object: "fulfillment", object: "fulfillment",
data: { id: fulfillment.id }, data: { id: fulfillment.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_address_created, eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED,
action: "created", action: "created",
object: "fulfillment_address", object: "fulfillment_address",
data: { id: fulfillment.delivery_address.id }, data: { id: fulfillment.delivery_address.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_item_created, eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED,
action: "created", action: "created",
object: "fulfillment_item", object: "fulfillment_item",
data: { id: fulfillment.items[0].id }, data: { id: fulfillment.items[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_label_created, eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
action: "created", action: "created",
object: "fulfillment_label", object: "fulfillment_label",
data: { id: fulfillment.labels[0].id }, data: { id: fulfillment.labels[0].id },
@@ -246,25 +246,25 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_created, eventName: FulfillmentEvents.FULFILLMENT_CREATED,
action: "created", action: "created",
object: "fulfillment", object: "fulfillment",
data: { id: fulfillment.id }, data: { id: fulfillment.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_address_created, eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED,
action: "created", action: "created",
object: "fulfillment_address", object: "fulfillment_address",
data: { id: fulfillment.delivery_address.id }, data: { id: fulfillment.delivery_address.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_item_created, eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED,
action: "created", action: "created",
object: "fulfillment_item", object: "fulfillment_item",
data: { id: fulfillment.items[0].id }, data: { id: fulfillment.items[0].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_label_created, eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
action: "created", action: "created",
object: "fulfillment_label", object: "fulfillment_label",
data: { id: fulfillment.labels[0].id }, data: { id: fulfillment.labels[0].id },
@@ -380,25 +380,25 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_updated, eventName: FulfillmentEvents.FULFILLMENT_UPDATED,
action: "updated", action: "updated",
object: "fulfillment", object: "fulfillment",
data: { id: updatedFulfillment.id }, data: { id: updatedFulfillment.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_label_deleted, eventName: FulfillmentEvents.FULFILLMENT_LABEL_DELETED,
action: "deleted", action: "deleted",
object: "fulfillment_label", object: "fulfillment_label",
data: { id: label3.id }, data: { id: label3.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_label_updated, eventName: FulfillmentEvents.FULFILLMENT_LABEL_UPDATED,
action: "updated", action: "updated",
object: "fulfillment_label", object: "fulfillment_label",
data: { id: label2.id }, data: { id: label2.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_label_created, eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
action: "created", action: "created",
object: "fulfillment_label", object: "fulfillment_label",
data: { id: label4.id }, data: { id: label4.id },
@@ -456,7 +456,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenNthCalledWith(1, [ expect(eventBusEmitSpy).toHaveBeenNthCalledWith(1, [
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.fulfillment_updated, eventName: FulfillmentEvents.FULFILLMENT_UPDATED,
action: "updated", action: "updated",
object: "fulfillment", object: "fulfillment",
data: { id: fulfillment.id }, data: { id: fulfillment.id },
@@ -109,7 +109,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { id: geoZone.id }, data: { id: geoZone.id },
@@ -160,7 +160,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { id: geoZones[i].id }, data: { id: geoZones[i].id },
@@ -267,7 +267,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_updated, eventName: FulfillmentEvents.GEO_ZONE_UPDATED,
action: "updated", action: "updated",
object: "geo_zone", object: "geo_zone",
data: { id: updatedGeoZone.id }, data: { id: updatedGeoZone.id },
@@ -332,7 +332,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_updated, eventName: FulfillmentEvents.GEO_ZONE_UPDATED,
action: "updated", action: "updated",
object: "geo_zone", object: "geo_zone",
data: { id: expectedGeoZone.id }, data: { id: expectedGeoZone.id },
@@ -368,25 +368,25 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_deleted, eventName: FulfillmentEvents.GEO_ZONE_DELETED,
action: "deleted", action: "deleted",
object: "geo_zone", object: "geo_zone",
data: { id: ukGeoZone.id }, data: { id: ukGeoZone.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.service_zone_updated, eventName: FulfillmentEvents.SERVICE_ZONE_UPDATED,
action: "updated", action: "updated",
object: "service_zone", object: "service_zone",
data: { id: updatedServiceZone.id }, data: { id: updatedServiceZone.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_created, eventName: FulfillmentEvents.GEO_ZONE_CREATED,
action: "created", action: "created",
object: "geo_zone", object: "geo_zone",
data: { id: chGeoZone.id }, data: { id: chGeoZone.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.geo_zone_updated, eventName: FulfillmentEvents.GEO_ZONE_UPDATED,
action: "updated", action: "updated",
object: "geo_zone", object: "geo_zone",
data: { id: usGeoZone.id }, data: { id: usGeoZone.id },
@@ -483,19 +483,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(3) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(3)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_created, eventName: FulfillmentEvents.SHIPPING_OPTION_CREATED,
action: "created", action: "created",
object: "shipping_option", object: "shipping_option",
data: { id: createdShippingOption.id }, data: { id: createdShippingOption.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_type_created, eventName: FulfillmentEvents.SHIPPING_OPTION_TYPE_CREATED,
action: "created", action: "created",
object: "shipping_option_type", object: "shipping_option_type",
data: { id: createdShippingOption.type.id }, data: { id: createdShippingOption.type.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_rule_created, eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
action: "created", action: "created",
object: "shipping_option_rule", object: "shipping_option_rule",
data: { id: createdShippingOption.rules[0].id }, data: { id: createdShippingOption.rules[0].id },
@@ -571,19 +571,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_created, eventName: FulfillmentEvents.SHIPPING_OPTION_CREATED,
action: "created", action: "created",
object: "shipping_option", object: "shipping_option",
data: { id: createdShippingOptions[i].id }, data: { id: createdShippingOptions[i].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_type_created, eventName: FulfillmentEvents.SHIPPING_OPTION_TYPE_CREATED,
action: "created", action: "created",
object: "shipping_option_type", object: "shipping_option_type",
data: { id: createdShippingOptions[i].type.id }, data: { id: createdShippingOptions[i].type.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_rule_created, eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
action: "created", action: "created",
object: "shipping_option_rule", object: "shipping_option_rule",
data: { id: createdShippingOptions[i].rules[0].id }, data: { id: createdShippingOptions[i].rules[0].id },
@@ -754,31 +754,31 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_updated, eventName: FulfillmentEvents.SHIPPING_OPTION_UPDATED,
action: "updated", action: "updated",
object: "shipping_option", object: "shipping_option",
data: { id: updatedShippingOption.id }, data: { id: updatedShippingOption.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_type_deleted, eventName: FulfillmentEvents.SHIPPING_OPTION_TYPE_DELETED,
action: "deleted", action: "deleted",
object: "shipping_option_type", object: "shipping_option_type",
data: { id: shippingOption.type.id }, data: { id: shippingOption.type.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_type_created, eventName: FulfillmentEvents.SHIPPING_OPTION_TYPE_CREATED,
action: "created", action: "created",
object: "shipping_option_type", object: "shipping_option_type",
data: { id: updatedShippingOption.type.id }, data: { id: updatedShippingOption.type.id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_rule_created, eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
action: "created", action: "created",
object: "shipping_option_rule", object: "shipping_option_rule",
data: { id: updatedShippingOption.rules[1].id }, data: { id: updatedShippingOption.rules[1].id },
}), }),
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_rule_updated, eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_UPDATED,
action: "updated", action: "updated",
object: "shipping_option_rule", object: "shipping_option_rule",
data: { id: updatedShippingOption.rules[0].id }, data: { id: updatedShippingOption.rules[0].id },
@@ -1213,7 +1213,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_rule_created, eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
action: "created", action: "created",
object: "shipping_option_rule", object: "shipping_option_rule",
data: { id: rule.id }, data: { id: rule.id },
@@ -1290,7 +1290,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_option_rule_updated, eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_UPDATED,
action: "updated", action: "updated",
object: "shipping_option_rule", object: "shipping_option_rule",
data: { id: updatedRule.id }, data: { id: updatedRule.id },
@@ -47,7 +47,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_profile_created, eventName: FulfillmentEvents.SHIPPING_PROFILE_CREATED,
action: "created", action: "created",
object: "shipping_profile", object: "shipping_profile",
data: { id: createdShippingProfile.id }, data: { id: createdShippingProfile.id },
@@ -85,7 +85,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
expect(eventBusEmitSpy).toHaveBeenCalledWith( expect(eventBusEmitSpy).toHaveBeenCalledWith(
expect.arrayContaining([ expect.arrayContaining([
buildExpectedEventMessageShape({ buildExpectedEventMessageShape({
eventName: FulfillmentEvents.shipping_profile_created, eventName: FulfillmentEvents.SHIPPING_PROFILE_CREATED,
action: "created", action: "created",
object: "shipping_profile", object: "shipping_profile",
data: { id: createdShippingProfiles[i].id }, data: { id: createdShippingProfiles[i].id },
@@ -116,21 +116,18 @@ export const eventBuilders = {
source: Modules.FULFILLMENT, source: Modules.FULFILLMENT,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "fulfillment_set", object: "fulfillment_set",
isMainEntity: true,
eventsEnum: FulfillmentEvents, eventsEnum: FulfillmentEvents,
}), }),
updatedFulfillmentSet: eventBuilderFactory({ updatedFulfillmentSet: eventBuilderFactory({
source: Modules.FULFILLMENT, source: Modules.FULFILLMENT,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "fulfillment_set", object: "fulfillment_set",
isMainEntity: true,
eventsEnum: FulfillmentEvents, eventsEnum: FulfillmentEvents,
}), }),
deletedFulfillmentSet: eventBuilderFactory({ deletedFulfillmentSet: eventBuilderFactory({
source: Modules.FULFILLMENT, source: Modules.FULFILLMENT,
action: CommonEvents.DELETED, action: CommonEvents.DELETED,
object: "fulfillment_set", object: "fulfillment_set",
isMainEntity: true,
eventsEnum: FulfillmentEvents, eventsEnum: FulfillmentEvents,
}), }),
createdServiceZone: eventBuilderFactory({ createdServiceZone: eventBuilderFactory({
@@ -237,7 +237,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
created.map((reservationItem) => ({ created.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_created, eventName: InventoryEvents.RESERVATION_ITEM_CREATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "reservation-item", object: "reservation-item",
@@ -331,7 +331,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
result.map((inventoryItem) => ({ result.map((inventoryItem) => ({
eventName: InventoryEvents.created, eventName: InventoryEvents.INVENTORY_ITEM_CREATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "inventory-item", object: "inventory-item",
@@ -385,7 +385,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
created.map((inventoryLevel) => ({ created.map((inventoryLevel) => ({
eventName: InventoryEvents.inventory_level_created, eventName: InventoryEvents.INVENTORY_LEVEL_CREATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "inventory-level", object: "inventory-level",
@@ -439,7 +439,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
result.map((inventoryItem) => ({ result.map((inventoryItem) => ({
eventName: InventoryEvents.updated, eventName: InventoryEvents.INVENTORY_ITEM_UPDATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "inventory-item", object: "inventory-item",
@@ -480,7 +480,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
result[0].map((inventoryLevel) => ({ result[0].map((inventoryLevel) => ({
eventName: InventoryEvents.inventory_level_deleted, eventName: InventoryEvents.INVENTORY_LEVEL_DELETED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.DELETED, action: CommonEvents.DELETED,
object: "inventory-level", object: "inventory-level",
@@ -511,7 +511,7 @@ export default class InventoryModuleService
) )
context.messageAggregator?.saveRawMessageData({ context.messageAggregator?.saveRawMessageData({
eventName: InventoryEvents.inventory_level_deleted, eventName: InventoryEvents.INVENTORY_LEVEL_DELETED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.DELETED, action: CommonEvents.DELETED,
object: "inventory-level", object: "inventory-level",
@@ -554,7 +554,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
levels.map((inventoryLevel) => ({ levels.map((inventoryLevel) => ({
eventName: InventoryEvents.inventory_level_updated, eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "inventory-level", object: "inventory-level",
@@ -637,7 +637,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
result.map((reservationItem) => ({ result.map((reservationItem) => ({
eventName: InventoryEvents.inventory_level_updated, eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "reservation-item", object: "reservation-item",
@@ -790,7 +790,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
reservations.map((reservationItem) => ({ reservations.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_deleted, eventName: InventoryEvents.RESERVATION_ITEM_DELETED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.DELETED, action: CommonEvents.DELETED,
object: "reservation-item", object: "reservation-item",
@@ -832,7 +832,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
reservations.map((reservationItem) => ({ reservations.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_deleted, eventName: InventoryEvents.RESERVATION_ITEM_DELETED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.DELETED, action: CommonEvents.DELETED,
object: "reservation-item", object: "reservation-item",
@@ -869,7 +869,7 @@ export default class InventoryModuleService
context.messageAggregator?.saveRawMessageData( context.messageAggregator?.saveRawMessageData(
reservations.map((reservationItem) => ({ reservations.map((reservationItem) => ({
eventName: InventoryEvents.reservation_item_created, eventName: InventoryEvents.RESERVATION_ITEM_CREATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "reservation-item", object: "reservation-item",
@@ -938,7 +938,7 @@ export default class InventoryModuleService
results.push(result) results.push(result)
context.messageAggregator?.saveRawMessageData({ context.messageAggregator?.saveRawMessageData({
eventName: InventoryEvents.inventory_level_updated, eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "inventory-level", object: "inventory-level",
@@ -507,7 +507,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
const events = eventBusEmitSpy.mock.calls[0][0] const events = eventBusEmitSpy.mock.calls[0][0]
expect(events).toHaveLength(4) expect(events).toHaveLength(4)
expect(events[0]).toEqual( expect(events[0]).toEqual(
composeMessage(PricingEvents.price_list_created, { composeMessage(PricingEvents.PRICE_LIST_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price_list", object: "price_list",
@@ -515,7 +515,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
}) })
) )
expect(events[1]).toEqual( expect(events[1]).toEqual(
composeMessage(PricingEvents.price_list_rule_created, { composeMessage(PricingEvents.PRICE_LIST_RULE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price_list_rule", object: "price_list_rule",
@@ -523,7 +523,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
}) })
) )
expect(events[2]).toEqual( expect(events[2]).toEqual(
composeMessage(PricingEvents.price_list_rule_created, { composeMessage(PricingEvents.PRICE_LIST_RULE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price_list_rule", object: "price_list_rule",
@@ -531,7 +531,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
}) })
) )
expect(events[3]).toEqual( expect(events[3]).toEqual(
composeMessage(PricingEvents.price_created, { composeMessage(PricingEvents.PRICE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price", object: "price",
@@ -866,7 +866,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
expect(events).toHaveLength(2) expect(events).toHaveLength(2)
expect(events[0]).toEqual( expect(events[0]).toEqual(
composeMessage(PricingEvents.price_created, { composeMessage(PricingEvents.PRICE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price", object: "price",
@@ -874,7 +874,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
}) })
) )
expect(events[1]).toEqual( expect(events[1]).toEqual(
composeMessage(PricingEvents.price_rule_created, { composeMessage(PricingEvents.PRICE_RULE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price_rule", object: "price_rule",
@@ -448,7 +448,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
const events = eventBusEmitSpy.mock.calls[0][0] const events = eventBusEmitSpy.mock.calls[0][0]
expect(events).toHaveLength(3) expect(events).toHaveLength(3)
expect(events[0]).toEqual( expect(events[0]).toEqual(
composeMessage(PricingEvents.price_set_created, { composeMessage(PricingEvents.PRICE_SET_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price_set", object: "price_set",
@@ -457,7 +457,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
) )
expect(events[1]).toEqual( expect(events[1]).toEqual(
composeMessage(PricingEvents.price_created, { composeMessage(PricingEvents.PRICE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price", object: "price",
@@ -466,7 +466,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
) )
expect(events[2]).toEqual( expect(events[2]).toEqual(
composeMessage(PricingEvents.price_rule_created, { composeMessage(PricingEvents.PRICE_RULE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price_rule", object: "price_rule",
@@ -696,7 +696,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
const events = eventBusEmitSpy.mock.calls[0][0] const events = eventBusEmitSpy.mock.calls[0][0]
expect(events).toHaveLength(2) expect(events).toHaveLength(2)
expect(events[0]).toEqual( expect(events[0]).toEqual(
composeMessage(PricingEvents.price_created, { composeMessage(PricingEvents.PRICE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price", object: "price",
@@ -704,7 +704,7 @@ moduleIntegrationTestRunner<IPricingModuleService>({
}) })
) )
expect(events[1]).toEqual( expect(events[1]).toEqual(
composeMessage(PricingEvents.price_rule_created, { composeMessage(PricingEvents.PRICE_RULE_CREATED, {
source: Modules.PRICING, source: Modules.PRICING,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "price_rule", object: "price_rule",
@@ -1,5 +1,11 @@
import { IProductModuleService } from "@medusajs/types" import { IProductModuleService } from "@medusajs/types"
import { Modules, ProductStatus } from "@medusajs/utils" import {
Modules,
CommonEvents,
ProductEvents,
ProductStatus,
composeMessage,
} from "@medusajs/utils"
import { Product, ProductCategory } from "@models" import { Product, ProductCategory } from "@models"
import { import {
MockEventBusService, MockEventBusService,
@@ -291,11 +297,13 @@ moduleIntegrationTestRunner<IProductModuleService>({
parent_category_id: productCategoryOne.id, parent_category_id: productCategoryOne.id,
}) })
expect(eventBusSpy).toHaveBeenCalledTimes(1) expect(eventBusSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusSpy).toHaveBeenCalledWith([ expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({ composeMessage(ProductEvents.PRODUCT_CATEGORY_CREATED, {
data: { id: category.id }, data: { id: category.id },
eventName: "productService.product-category.created", object: "product_category",
source: Modules.PRODUCT,
action: CommonEvents.CREATED,
}), }),
]) ])
}) })
@@ -384,11 +392,13 @@ moduleIntegrationTestRunner<IProductModuleService>({
name: "New Category", name: "New Category",
}) })
expect(eventBusSpy).toHaveBeenCalledTimes(1) expect(eventBusSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusSpy).toHaveBeenCalledWith([ expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({ composeMessage(ProductEvents.PRODUCT_CATEGORY_UPDATED, {
data: { id: productCategoryZero.id }, data: { id: productCategoryZero.id },
eventName: "productService.product-category.updated", object: "product_category",
source: Modules.PRODUCT,
action: CommonEvents.UPDATED,
}), }),
]) ])
}) })
@@ -279,7 +279,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
composeMessage(ProductEvents.product_tag_updated, { composeMessage(ProductEvents.PRODUCT_TAG_UPDATED, {
data: { id: productTag.id }, data: { id: productTag.id },
object: "product_tag", object: "product_tag",
source: Modules.PRODUCT, source: Modules.PRODUCT,
@@ -321,7 +321,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
composeMessage(ProductEvents.product_tag_created, { composeMessage(ProductEvents.PRODUCT_TAG_CREATED, {
data: { id: productTag[0].id }, data: { id: productTag[0].id },
object: "product_tag", object: "product_tag",
source: Modules.PRODUCT, source: Modules.PRODUCT,
@@ -375,13 +375,13 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(2) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(2)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
composeMessage(ProductEvents.product_tag_created, { composeMessage(ProductEvents.PRODUCT_TAG_CREATED, {
data: { id: newTag.id }, data: { id: newTag.id },
object: "product_tag", object: "product_tag",
source: Modules.PRODUCT, source: Modules.PRODUCT,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
}), }),
composeMessage(ProductEvents.product_tag_updated, { composeMessage(ProductEvents.PRODUCT_TAG_UPDATED, {
data: { id: updatedTag.id }, data: { id: updatedTag.id },
object: "product_tag", object: "product_tag",
source: Modules.PRODUCT, source: Modules.PRODUCT,
@@ -213,7 +213,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
composeMessage(ProductEvents.product_variant_updated, { composeMessage(ProductEvents.PRODUCT_VARIANT_UPDATED, {
data: { id: variantOne.id }, data: { id: variantOne.id },
object: "product_variant", object: "product_variant",
source: Modules.PRODUCT, source: Modules.PRODUCT,
@@ -246,7 +246,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
composeMessage(ProductEvents.product_variant_updated, { composeMessage(ProductEvents.PRODUCT_VARIANT_UPDATED, {
data: { id: variantOne.id }, data: { id: variantOne.id },
object: "product_variant", object: "product_variant",
source: Modules.PRODUCT, source: Modules.PRODUCT,
@@ -320,7 +320,7 @@ moduleIntegrationTestRunner<IProductModuleService>({
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1) expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
expect(eventBusEmitSpy).toHaveBeenCalledWith([ expect(eventBusEmitSpy).toHaveBeenCalledWith([
composeMessage(ProductEvents.product_variant_created, { composeMessage(ProductEvents.PRODUCT_VARIANT_CREATED, {
data: { id: variant.id }, data: { id: variant.id },
object: "product_variant", object: "product_variant",
source: Modules.PRODUCT, source: Modules.PRODUCT,
@@ -11,21 +11,18 @@ export const eventBuilders = {
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "product", object: "product",
eventsEnum: ProductEvents, eventsEnum: ProductEvents,
isMainEntity: true,
}), }),
updatedProduct: eventBuilderFactory({ updatedProduct: eventBuilderFactory({
source: Modules.PRODUCT, source: Modules.PRODUCT,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "product", object: "product",
eventsEnum: ProductEvents, eventsEnum: ProductEvents,
isMainEntity: true,
}), }),
deletedProduct: eventBuilderFactory({ deletedProduct: eventBuilderFactory({
source: Modules.PRODUCT, source: Modules.PRODUCT,
action: CommonEvents.DELETED, action: CommonEvents.DELETED,
object: "product", object: "product",
eventsEnum: ProductEvents, eventsEnum: ProductEvents,
isMainEntity: true,
}), }),
createdProductVariant: eventBuilderFactory({ createdProductVariant: eventBuilderFactory({
source: Modules.PRODUCT, source: Modules.PRODUCT,
@@ -175,7 +175,7 @@ moduleIntegrationTestRunner<IUserModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([ expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({ expect.objectContaining({
data: { id: "1" }, data: { id: "1" },
eventName: UserEvents.invite_updated, eventName: UserEvents.INVITE_UPDATED,
}), }),
]) ])
}) })
@@ -192,7 +192,7 @@ moduleIntegrationTestRunner<IUserModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([ expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({ expect.objectContaining({
data: { id: "1" }, data: { id: "1" },
eventName: UserEvents.invite_token_generated, eventName: UserEvents.INVITE_TOKEN_GENERATED,
}), }),
]) ])
}) })
@@ -221,19 +221,19 @@ moduleIntegrationTestRunner<IUserModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([ expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({ expect.objectContaining({
data: { id: "1" }, data: { id: "1" },
eventName: UserEvents.invite_created, eventName: UserEvents.INVITE_CREATED,
}), }),
expect.objectContaining({ expect.objectContaining({
data: { id: "2" }, data: { id: "2" },
eventName: UserEvents.invite_created, eventName: UserEvents.INVITE_CREATED,
}), }),
expect.objectContaining({ expect.objectContaining({
data: { id: "1" }, data: { id: "1" },
eventName: UserEvents.invite_token_generated, eventName: UserEvents.INVITE_TOKEN_GENERATED,
}), }),
expect.objectContaining({ expect.objectContaining({
data: { id: "2" }, data: { id: "2" },
eventName: UserEvents.invite_token_generated, eventName: UserEvents.INVITE_TOKEN_GENERATED,
}), }),
]) ])
}) })
@@ -188,7 +188,7 @@ moduleIntegrationTestRunner<IUserModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([ expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({ expect.objectContaining({
data: { id: "1" }, data: { id: "1" },
eventName: UserEvents.updated, eventName: UserEvents.USER_UPDATED,
}), }),
]) ])
}) })
@@ -218,11 +218,11 @@ moduleIntegrationTestRunner<IUserModuleService>({
expect(eventBusSpy).toHaveBeenCalledWith([ expect(eventBusSpy).toHaveBeenCalledWith([
expect.objectContaining({ expect.objectContaining({
data: { id: "1" }, data: { id: "1" },
eventName: UserEvents.created, eventName: UserEvents.USER_CREATED,
}), }),
expect.objectContaining({ expect.objectContaining({
data: { id: "2" }, data: { id: "2" },
eventName: UserEvents.created, eventName: UserEvents.USER_CREATED,
}), }),
]) ])
}) })
@@ -115,7 +115,7 @@ export default class UserModuleService
sharedContext.messageAggregator?.saveRawMessageData( sharedContext.messageAggregator?.saveRawMessageData(
invites.map((invite) => ({ invites.map((invite) => ({
eventName: UserEvents.invite_token_generated, eventName: UserEvents.INVITE_TOKEN_GENERATED,
source: this.constructor.name, source: this.constructor.name,
action: "token_generated", action: "token_generated",
object: "invite", object: "invite",
@@ -198,7 +198,7 @@ export default class UserModuleService
sharedContext.messageAggregator?.saveRawMessageData( sharedContext.messageAggregator?.saveRawMessageData(
users.map((user) => ({ users.map((user) => ({
eventName: UserEvents.created, eventName: UserEvents.USER_CREATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "user", object: "user",
@@ -238,7 +238,7 @@ export default class UserModuleService
sharedContext.messageAggregator?.saveRawMessageData( sharedContext.messageAggregator?.saveRawMessageData(
updatedUsers.map((user) => ({ updatedUsers.map((user) => ({
eventName: UserEvents.updated, eventName: UserEvents.USER_UPDATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "user", object: "user",
@@ -278,7 +278,7 @@ export default class UserModuleService
sharedContext.messageAggregator?.saveRawMessageData( sharedContext.messageAggregator?.saveRawMessageData(
invites.map((invite) => ({ invites.map((invite) => ({
eventName: UserEvents.invite_created, eventName: UserEvents.INVITE_CREATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.CREATED, action: CommonEvents.CREATED,
object: "invite", object: "invite",
@@ -289,7 +289,7 @@ export default class UserModuleService
sharedContext.messageAggregator?.saveRawMessageData( sharedContext.messageAggregator?.saveRawMessageData(
invites.map((invite) => ({ invites.map((invite) => ({
eventName: UserEvents.invite_token_generated, eventName: UserEvents.INVITE_TOKEN_GENERATED,
source: this.constructor.name, source: this.constructor.name,
action: "token_generated", action: "token_generated",
object: "invite", object: "invite",
@@ -360,7 +360,7 @@ export default class UserModuleService
sharedContext.messageAggregator?.saveRawMessageData( sharedContext.messageAggregator?.saveRawMessageData(
serializedInvites.map((invite) => ({ serializedInvites.map((invite) => ({
eventName: UserEvents.invite_updated, eventName: UserEvents.INVITE_UPDATED,
source: this.constructor.name, source: this.constructor.name,
action: CommonEvents.UPDATED, action: CommonEvents.UPDATED,
object: "invite", object: "invite",