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