chore: Treat internal event differently, primarely do not display info logs for those events (#8767)
* chore: Treat internal event differently, primarely do not display info log for those events * revert doc * add few tests * only set internal option if present * revert to previous condition * start including feedback after discussion * include feedback * fix modules integration tests * fix modules integration tests * fix event bus local
This commit is contained in:
@@ -39,6 +39,49 @@ describe("LocalEventBusService", () => {
|
||||
data: { hi: "1234" },
|
||||
name: "eventName",
|
||||
})
|
||||
|
||||
expect(loggerMock.info).toHaveBeenCalledTimes(1)
|
||||
expect(loggerMock.info).toHaveBeenCalledWith(
|
||||
"Processing eventName which has undefined subscribers"
|
||||
)
|
||||
})
|
||||
|
||||
it("should emit an event but not log anything if it is internal", async () => {
|
||||
eventEmitter.emit = jest.fn((data) => data)
|
||||
|
||||
await eventBus.emit({
|
||||
name: "eventName",
|
||||
data: { hi: "1234" },
|
||||
options: {
|
||||
internal: true,
|
||||
},
|
||||
})
|
||||
|
||||
expect(eventEmitter.emit).toHaveBeenCalledTimes(1)
|
||||
expect(eventEmitter.emit).toHaveBeenCalledWith("eventName", {
|
||||
data: { hi: "1234" },
|
||||
name: "eventName",
|
||||
})
|
||||
|
||||
expect(loggerMock.info).toHaveBeenCalledTimes(0)
|
||||
|
||||
await eventBus.emit(
|
||||
{
|
||||
name: "eventName",
|
||||
data: { hi: "1234" },
|
||||
},
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
expect(eventEmitter.emit).toHaveBeenCalledTimes(2)
|
||||
expect(eventEmitter.emit).toHaveBeenCalledWith("eventName", {
|
||||
data: { hi: "1234" },
|
||||
name: "eventName",
|
||||
})
|
||||
|
||||
expect(loggerMock.info).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
|
||||
it("should emit multiple events", async () => {
|
||||
@@ -87,7 +130,7 @@ describe("LocalEventBusService", () => {
|
||||
groupEventFn = jest.spyOn(eventBus, "groupEvent" as any)
|
||||
eventEmitter.emit = jest.fn((data) => data)
|
||||
|
||||
eventBus.emit([
|
||||
await eventBus.emit([
|
||||
{
|
||||
name: "test-event",
|
||||
data: { test: "1234" },
|
||||
@@ -201,12 +244,12 @@ describe("LocalEventBusService", () => {
|
||||
expect(getMap().get("group-1")).toHaveLength(1)
|
||||
expect(getMap().get("group-2")).toHaveLength(1)
|
||||
|
||||
eventBus.clearGroupedEvents("group-1")
|
||||
await eventBus.clearGroupedEvents("group-1")
|
||||
|
||||
expect(getMap().get("group-1")).not.toBeDefined()
|
||||
expect(getMap().get("group-2")).toHaveLength(1)
|
||||
|
||||
eventBus.clearGroupedEvents("group-2")
|
||||
await eventBus.clearGroupedEvents("group-2")
|
||||
|
||||
expect(getMap().get("group-2")).not.toBeDefined()
|
||||
})
|
||||
|
||||
@@ -35,6 +35,12 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
this.groupedEventsMap_ = new Map()
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept an event name and some options
|
||||
*
|
||||
* @param eventsData
|
||||
* @param options The options can include `internal` which will prevent the event from being logged
|
||||
*/
|
||||
async emit<T = unknown>(
|
||||
eventsData: Message<T> | Message<T>[],
|
||||
options: Record<string, unknown> = {}
|
||||
@@ -48,9 +54,11 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
eventData.name
|
||||
)
|
||||
|
||||
this.logger_?.info(
|
||||
`Processing ${eventData.name} which has ${eventListenersCount} subscribers`
|
||||
)
|
||||
if (!options.internal && !eventData.options?.internal) {
|
||||
this.logger_?.info(
|
||||
`Processing ${eventData.name} which has ${eventListenersCount} subscribers`
|
||||
)
|
||||
}
|
||||
|
||||
if (eventListenersCount === 0) {
|
||||
continue
|
||||
@@ -98,7 +106,7 @@ export default class LocalEventBusService extends AbstractEventBusModuleService
|
||||
this.eventEmitter_.emit(event.name, eventBody)
|
||||
}
|
||||
|
||||
this.clearGroupedEvents(eventGroupId)
|
||||
await this.clearGroupedEvents(eventGroupId)
|
||||
}
|
||||
|
||||
async clearGroupedEvents(eventGroupId: string) {
|
||||
|
||||
@@ -307,6 +307,8 @@ describe("RedisEventBusService", () => {
|
||||
JSON.stringify(testGroup2Event2),
|
||||
])
|
||||
}
|
||||
|
||||
return
|
||||
})
|
||||
|
||||
queue = (eventBus as any).queue_
|
||||
@@ -337,7 +339,7 @@ describe("RedisEventBusService", () => {
|
||||
})
|
||||
|
||||
describe("worker_", () => {
|
||||
let result
|
||||
let result!: any
|
||||
|
||||
describe("Successfully processes the jobs", () => {
|
||||
beforeEach(async () => {
|
||||
@@ -421,12 +423,16 @@ describe("RedisEventBusService", () => {
|
||||
})
|
||||
|
||||
it("should retry processing when subcribers fail, if configured - final attempt", async () => {
|
||||
eventBus.subscribe("eventName", async () => Promise.resolve(), {
|
||||
eventBus.subscribe("eventName", async () => await Promise.resolve(), {
|
||||
subscriberId: "1",
|
||||
})
|
||||
eventBus.subscribe("eventName", async () => Promise.reject("fail1"), {
|
||||
subscriberId: "2",
|
||||
})
|
||||
eventBus.subscribe(
|
||||
"eventName",
|
||||
async () => await Promise.reject("fail1"),
|
||||
{
|
||||
subscriberId: "2",
|
||||
}
|
||||
)
|
||||
|
||||
result = await eventBus
|
||||
.worker_({
|
||||
@@ -456,12 +462,16 @@ describe("RedisEventBusService", () => {
|
||||
})
|
||||
|
||||
it("should retry processing when subcribers fail, if configured", async () => {
|
||||
eventBus.subscribe("eventName", async () => Promise.resolve(), {
|
||||
eventBus.subscribe("eventName", async () => await Promise.resolve(), {
|
||||
subscriberId: "1",
|
||||
})
|
||||
eventBus.subscribe("eventName", async () => Promise.reject("fail1"), {
|
||||
subscriberId: "2",
|
||||
})
|
||||
eventBus.subscribe(
|
||||
"eventName",
|
||||
async () => await Promise.reject("fail1"),
|
||||
{
|
||||
subscriberId: "2",
|
||||
}
|
||||
)
|
||||
|
||||
result = await eventBus
|
||||
.worker_({
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { BulkJobOptions, Queue, Worker } from "bullmq"
|
||||
import { Redis } from "ioredis"
|
||||
import { BullJob, EventBusRedisModuleOptions } from "../types"
|
||||
import { BullJob, EventBusRedisModuleOptions, Options } from "../types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
logger: Logger
|
||||
@@ -87,7 +87,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
|
||||
private buildEvents<T>(
|
||||
eventsData: Message<T>[],
|
||||
options: BulkJobOptions = {}
|
||||
options: Options = {}
|
||||
): IORedisEventType<T>[] {
|
||||
const opts = {
|
||||
// default options
|
||||
@@ -127,7 +127,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
*/
|
||||
async emit<T = unknown>(
|
||||
eventsData: Message<T> | Message<T>[],
|
||||
options: BulkJobOptions & { groupedEventsTTL?: number } = {}
|
||||
options: Options = {}
|
||||
): Promise<void> {
|
||||
let eventsDataArray = Array.isArray(eventsData) ? eventsData : [eventsData]
|
||||
|
||||
@@ -169,7 +169,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
// This will be helpful in preventing stale data from staying in redis for too long
|
||||
// in the event the module fails to cleanup events. For long running workflows, setting a much higher
|
||||
// TTL or even skipping the TTL would be required
|
||||
this.setExpire(groupId, groupedEventsTTL)
|
||||
void this.setExpire(groupId, groupedEventsTTL)
|
||||
|
||||
const eventsData = this.buildEvents(events, options)
|
||||
|
||||
@@ -229,7 +229,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
* @return resolves to the results of the subscriber calls.
|
||||
*/
|
||||
worker_ = async <T>(job: BullJob<T>): Promise<unknown> => {
|
||||
const { data, name } = job
|
||||
const { data, name, opts } = job
|
||||
const eventSubscribers = this.eventToSubscribersMap.get(name) || []
|
||||
const wildcardSubscribers = this.eventToSubscribersMap.get("*") || []
|
||||
|
||||
@@ -250,18 +250,20 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
|
||||
const isFinalAttempt = currentAttempt === configuredAttempts
|
||||
|
||||
if (isRetry) {
|
||||
if (isFinalAttempt) {
|
||||
this.logger_.info(`Final retry attempt for ${name}`)
|
||||
}
|
||||
if (!opts.internal) {
|
||||
if (isRetry) {
|
||||
if (isFinalAttempt) {
|
||||
this.logger_.info(`Final retry attempt for ${name}`)
|
||||
}
|
||||
|
||||
this.logger_.info(
|
||||
`Retrying ${name} which has ${eventSubscribers.length} subscribers (${subscribersInCurrentAttempt.length} of them failed)`
|
||||
)
|
||||
} else {
|
||||
this.logger_.info(
|
||||
`Processing ${name} which has ${eventSubscribers.length} subscribers`
|
||||
)
|
||||
this.logger_.info(
|
||||
`Retrying ${name} which has ${eventSubscribers.length} subscribers (${subscribersInCurrentAttempt.length} of them failed)`
|
||||
)
|
||||
} else {
|
||||
this.logger_.info(
|
||||
`Processing ${name} which has ${eventSubscribers.length} subscribers`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const completedSubscribersInCurrentAttempt: string[] = []
|
||||
@@ -315,7 +317,7 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
|
||||
this.logger_.warn(errorMessage)
|
||||
|
||||
return Promise.reject(Error(errorMessage))
|
||||
throw Error(errorMessage)
|
||||
}
|
||||
|
||||
if (didSubscribersFail && !isFinalAttempt) {
|
||||
@@ -325,6 +327,6 @@ export default class RedisEventBusService extends AbstractEventBusModuleService
|
||||
)
|
||||
}
|
||||
|
||||
return Promise.resolve(subscribersResult)
|
||||
return subscribersResult
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { Job, JobsOptions, QueueOptions, WorkerOptions } from "bullmq"
|
||||
import {
|
||||
BulkJobOptions,
|
||||
Job,
|
||||
JobsOptions,
|
||||
QueueOptions,
|
||||
WorkerOptions,
|
||||
} from "bullmq"
|
||||
import { RedisOptions } from "ioredis"
|
||||
|
||||
export type JobData<T> = {
|
||||
@@ -7,8 +13,14 @@ export type JobData<T> = {
|
||||
completedSubscriberIds?: string[] | undefined
|
||||
}
|
||||
|
||||
export type Options = BulkJobOptions & {
|
||||
groupedEventsTTL?: number
|
||||
internal?: boolean
|
||||
}
|
||||
|
||||
export type BullJob<T> = {
|
||||
data: JobData<T>
|
||||
opts: Job["opts"] & Options
|
||||
} & Job
|
||||
|
||||
export type EmitOptions = JobsOptions
|
||||
|
||||
+102
-58
@@ -167,14 +167,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a collection of fulfillment sets", async function () {
|
||||
@@ -211,7 +216,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSets[i].id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
++i
|
||||
@@ -245,20 +253,25 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a collection of fulfillment sets with new service zones", async function () {
|
||||
@@ -326,7 +339,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSets[i].service_zones[0].id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
++i
|
||||
@@ -373,26 +389,31 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].geo_zones[0].id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_set",
|
||||
data: { id: fulfillmentSet.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SERVICE_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "service_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: { id: fulfillmentSet.service_zones[0].geo_zones[0].id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a collection of fulfillment sets with new service zones and new geo zones", async function () {
|
||||
@@ -496,7 +517,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
id: fulfillmentSets[i].service_zones[0].geo_zones[0].id,
|
||||
},
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
++i
|
||||
@@ -633,14 +657,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment_set",
|
||||
data: { id: updatedFulfillmentSets.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_SET_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment_set",
|
||||
data: { id: updatedFulfillmentSets.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a collection of fulfillment sets", async function () {
|
||||
@@ -698,7 +727,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "fulfillment_set",
|
||||
data: { id: currentFullfillmentSet.id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -816,7 +848,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
id: createdFulfillmentSet.service_zones[0].geo_zones[0].id,
|
||||
},
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
@@ -920,7 +955,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
id: createdServiceZone.geo_zones[0].id,
|
||||
},
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1087,7 +1125,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
.id,
|
||||
},
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1230,7 +1271,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
id: createdServiceZone.geo_zones[0].id,
|
||||
},
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+107
-86
@@ -153,32 +153,37 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment",
|
||||
data: { id: fulfillment.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_address",
|
||||
data: { id: fulfillment.delivery_address.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_item",
|
||||
data: { id: fulfillment.items[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_label",
|
||||
data: { id: fulfillment.labels[0].id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment",
|
||||
data: { id: fulfillment.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_address",
|
||||
data: { id: fulfillment.delivery_address.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_item",
|
||||
data: { id: fulfillment.items[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_label",
|
||||
data: { id: fulfillment.labels[0].id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a return fulfillment", async () => {
|
||||
@@ -240,32 +245,37 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment",
|
||||
data: { id: fulfillment.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_address",
|
||||
data: { id: fulfillment.delivery_address.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_item",
|
||||
data: { id: fulfillment.items[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_label",
|
||||
data: { id: fulfillment.labels[0].id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment",
|
||||
data: { id: fulfillment.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ADDRESS_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_address",
|
||||
data: { id: fulfillment.delivery_address.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_ITEM_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_item",
|
||||
data: { id: fulfillment.items[0].id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_label",
|
||||
data: { id: fulfillment.labels[0].id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -374,32 +384,37 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment",
|
||||
data: { id: updatedFulfillment.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_DELETED,
|
||||
action: "deleted",
|
||||
object: "fulfillment_label",
|
||||
data: { id: label3.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment_label",
|
||||
data: { id: label2.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_label",
|
||||
data: { id: label4.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment",
|
||||
data: { id: updatedFulfillment.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_DELETED,
|
||||
action: "deleted",
|
||||
object: "fulfillment_label",
|
||||
data: { id: label3.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment_label",
|
||||
data: { id: label2.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_LABEL_CREATED,
|
||||
action: "created",
|
||||
object: "fulfillment_label",
|
||||
data: { id: label4.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -450,14 +465,20 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
expect(idempotentResult.canceled_at).toEqual(result.canceled_at)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenNthCalledWith(1, [
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment",
|
||||
data: { id: fulfillment.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.FULFILLMENT_UPDATED,
|
||||
action: "updated",
|
||||
object: "fulfillment",
|
||||
data: { id: fulfillment.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to cancel a fulfillment that is already shipped", async () => {
|
||||
|
||||
+34
-18
@@ -107,14 +107,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: { id: geoZone.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: { id: geoZone.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a collection of geo zones", async function () {
|
||||
@@ -165,7 +170,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "geo_zone",
|
||||
data: { id: geoZones[i].id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
++i
|
||||
@@ -265,14 +273,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_UPDATED,
|
||||
action: "updated",
|
||||
object: "geo_zone",
|
||||
data: { id: updatedGeoZone.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_UPDATED,
|
||||
action: "updated",
|
||||
object: "geo_zone",
|
||||
data: { id: updatedGeoZone.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a collection of geo zones", async function () {
|
||||
@@ -337,7 +350,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "geo_zone",
|
||||
data: { id: expectedGeoZone.id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
+31
-26
@@ -366,32 +366,37 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)!
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(4)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_DELETED,
|
||||
action: "deleted",
|
||||
object: "geo_zone",
|
||||
data: { id: ukGeoZone.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SERVICE_ZONE_UPDATED,
|
||||
action: "updated",
|
||||
object: "service_zone",
|
||||
data: { id: updatedServiceZone.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: { id: chGeoZone.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_UPDATED,
|
||||
action: "updated",
|
||||
object: "geo_zone",
|
||||
data: { id: usGeoZone.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_DELETED,
|
||||
action: "deleted",
|
||||
object: "geo_zone",
|
||||
data: { id: ukGeoZone.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SERVICE_ZONE_UPDATED,
|
||||
action: "updated",
|
||||
object: "service_zone",
|
||||
data: { id: updatedServiceZone.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_CREATED,
|
||||
action: "created",
|
||||
object: "geo_zone",
|
||||
data: { id: chGeoZone.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.GEO_ZONE_UPDATED,
|
||||
action: "updated",
|
||||
object: "geo_zone",
|
||||
data: { id: usGeoZone.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail on duplicated service zone name", async function () {
|
||||
|
||||
+59
-38
@@ -517,26 +517,31 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(3)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option",
|
||||
data: { id: createdShippingOption.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_TYPE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option_type",
|
||||
data: { id: createdShippingOption.type.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option_rule",
|
||||
data: { id: createdShippingOption.rules[0].id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option",
|
||||
data: { id: createdShippingOption.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_TYPE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option_type",
|
||||
data: { id: createdShippingOption.type.id },
|
||||
}),
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option_rule",
|
||||
data: { id: createdShippingOption.rules[0].id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create multiple new shipping options", async function () {
|
||||
@@ -624,7 +629,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "shipping_option_rule",
|
||||
data: { id: createdShippingOptions[i].rules[0].id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
++i
|
||||
@@ -819,7 +827,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "shipping_option_rule",
|
||||
data: { id: updatedShippingOption.rules[0].id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1247,14 +1258,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option_rule",
|
||||
data: { id: rule.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_option_rule",
|
||||
data: { id: rule.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
const rules = await service.listShippingOptionRules()
|
||||
expect(rules).toHaveLength(2)
|
||||
@@ -1324,14 +1340,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
})
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_UPDATED,
|
||||
action: "updated",
|
||||
object: "shipping_option_rule",
|
||||
data: { id: updatedRule.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_OPTION_RULE_UPDATED,
|
||||
action: "updated",
|
||||
object: "shipping_option_rule",
|
||||
data: { id: updatedRule.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to update a non-existent shipping option rule", async () => {
|
||||
|
||||
+17
-9
@@ -45,14 +45,19 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_PROFILE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_profile",
|
||||
data: { id: createdShippingProfile.id },
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
buildExpectedEventMessageShape({
|
||||
eventName: FulfillmentEvents.SHIPPING_PROFILE_CREATED,
|
||||
action: "created",
|
||||
object: "shipping_profile",
|
||||
data: { id: createdShippingProfile.id },
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should create multiple new shipping profiles", async function () {
|
||||
@@ -90,7 +95,10 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
object: "shipping_profile",
|
||||
data: { id: createdShippingProfiles[i].id },
|
||||
}),
|
||||
])
|
||||
]),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
++i
|
||||
|
||||
@@ -14,18 +14,18 @@ import {
|
||||
UpdateServiceZoneDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
EmitEvents,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
arrayDifference,
|
||||
deepEqualObj,
|
||||
EmitEvents,
|
||||
getSetDifference,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isDefined,
|
||||
isPresent,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
|
||||
@@ -12,19 +12,19 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import { IInventoryService } from "@medusajs/types/dist/inventory"
|
||||
import {
|
||||
arrayDifference,
|
||||
BigNumber,
|
||||
CommonEvents,
|
||||
EmitEvents,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
InventoryEvents,
|
||||
isDefined,
|
||||
isString,
|
||||
MathBN,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
MedusaService,
|
||||
arrayDifference,
|
||||
isDefined,
|
||||
isString,
|
||||
partitionArray,
|
||||
} from "@medusajs/utils"
|
||||
import { InventoryItem, InventoryLevel, ReservationItem } from "@models"
|
||||
|
||||
+14
-9
@@ -1,10 +1,10 @@
|
||||
import { INotificationModuleService } from "@medusajs/types"
|
||||
import {
|
||||
CommonEvents,
|
||||
composeMessage,
|
||||
Module,
|
||||
Modules,
|
||||
NotificationEvents,
|
||||
composeMessage,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
MockEventBusService,
|
||||
@@ -94,14 +94,19 @@ moduleIntegrationTestRunner({
|
||||
const result = await service.createNotifications(notification)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
composeMessage(NotificationEvents.NOTIFICATION_CREATED, {
|
||||
data: { id: result.id },
|
||||
object: "notification",
|
||||
source: Modules.NOTIFICATION,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(NotificationEvents.NOTIFICATION_CREATED, {
|
||||
data: { id: result.id },
|
||||
object: "notification",
|
||||
source: Modules.NOTIFICATION,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("ensures the same notification is not sent twice", async () => {
|
||||
|
||||
+43
-28
@@ -1,10 +1,10 @@
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import {
|
||||
CommonEvents,
|
||||
composeMessage,
|
||||
Modules,
|
||||
ProductEvents,
|
||||
ProductStatus,
|
||||
composeMessage,
|
||||
} from "@medusajs/utils"
|
||||
import { Product, ProductCategory } from "@models"
|
||||
import {
|
||||
@@ -410,14 +410,19 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
})
|
||||
|
||||
expect(eventBusSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_CATEGORY_CREATED, {
|
||||
data: { id: category.id },
|
||||
object: "product_category",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_CATEGORY_CREATED, {
|
||||
data: { id: category.id },
|
||||
object: "product_category",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should append rank from an existing category depending on parent", async () => {
|
||||
@@ -505,14 +510,19 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
})
|
||||
|
||||
expect(eventBusSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_CATEGORY_UPDATED, {
|
||||
data: { id: productCategoryZero.id },
|
||||
object: "product_category",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_CATEGORY_UPDATED, {
|
||||
data: { id: productCategoryZero.id },
|
||||
object: "product_category",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should update the name of the category successfully", async () => {
|
||||
@@ -678,17 +688,22 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
await service.deleteProductCategories([productCategoryOne.id])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect.objectContaining({
|
||||
data: { id: productCategoryOne.id },
|
||||
name: "product-category.deleted",
|
||||
metadata: {
|
||||
action: "",
|
||||
object: "",
|
||||
source: "",
|
||||
},
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
expect.objectContaining({
|
||||
data: { id: productCategoryOne.id },
|
||||
name: "product-category.deleted",
|
||||
metadata: {
|
||||
action: "",
|
||||
object: "",
|
||||
source: "",
|
||||
},
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when an id does not exist", async () => {
|
||||
|
||||
+35
-20
@@ -278,17 +278,22 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
await service.deleteProductCollections([collectionId])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
{
|
||||
name: "product-collection.deleted",
|
||||
data: { id: collectionId },
|
||||
metadata: {
|
||||
action: "",
|
||||
object: "",
|
||||
source: "",
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
{
|
||||
name: "product-collection.deleted",
|
||||
data: { id: collectionId },
|
||||
metadata: {
|
||||
action: "",
|
||||
object: "",
|
||||
source: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
])
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -306,12 +311,17 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
{
|
||||
data: { id: collectionId },
|
||||
name: "product-collection.updated",
|
||||
},
|
||||
],
|
||||
{
|
||||
data: { id: collectionId },
|
||||
name: "product-collection.updated",
|
||||
},
|
||||
])
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should update the value of the collection successfully", async () => {
|
||||
@@ -502,12 +512,17 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
{
|
||||
data: { id: collections[0].id },
|
||||
name: "product-collection.created",
|
||||
},
|
||||
],
|
||||
{
|
||||
data: { id: collections[0].id },
|
||||
name: "product-collection.created",
|
||||
},
|
||||
])
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+45
-30
@@ -278,14 +278,19 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
expect(productTag.value).toEqual("UK")
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_UPDATED, {
|
||||
data: { id: productTag.id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_UPDATED, {
|
||||
data: { id: productTag.id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error when an id does not exist", async () => {
|
||||
@@ -320,14 +325,19 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
expect(productTag[0]?.value).toEqual("UK")
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_CREATED, {
|
||||
data: { id: productTag[0].id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_CREATED, {
|
||||
data: { id: productTag[0].id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -374,20 +384,25 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
const updatedTag = productTags.find((t) => t.value === "updated")!
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(2)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_CREATED, {
|
||||
data: { id: newTag.id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_UPDATED, {
|
||||
data: { id: updatedTag.id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_CREATED, {
|
||||
data: { id: newTag.id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
composeMessage(ProductEvents.PRODUCT_TAG_UPDATED, {
|
||||
data: { id: updatedTag.id },
|
||||
object: "product_tag",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
+39
-24
@@ -212,14 +212,19 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
expect(productVariant.title).toEqual("new test")
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_VARIANT_UPDATED, {
|
||||
data: { id: variantOne.id },
|
||||
object: "product_variant",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_VARIANT_UPDATED, {
|
||||
data: { id: variantOne.id },
|
||||
object: "product_variant",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should upsert the options of a variant successfully", async () => {
|
||||
@@ -245,14 +250,19 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_VARIANT_UPDATED, {
|
||||
data: { id: variantOne.id },
|
||||
object: "product_variant",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_VARIANT_UPDATED, {
|
||||
data: { id: variantOne.id },
|
||||
object: "product_variant",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should do a partial update on the options of a variant successfully", async () => {
|
||||
@@ -319,14 +329,19 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
)
|
||||
|
||||
expect(eventBusEmitSpy.mock.calls[0][0]).toHaveLength(1)
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith([
|
||||
composeMessage(ProductEvents.PRODUCT_VARIANT_CREATED, {
|
||||
data: { id: variant.id },
|
||||
object: "product_variant",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusEmitSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
composeMessage(ProductEvents.PRODUCT_VARIANT_CREATED, {
|
||||
data: { id: variant.id },
|
||||
object: "product_variant",
|
||||
source: Modules.PRODUCT,
|
||||
action: CommonEvents.CREATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should correctly associate variants with own product options", async () => {
|
||||
|
||||
+30
-15
@@ -374,12 +374,17 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
await service.upsertProducts([updateData])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
{
|
||||
name: "product.updated",
|
||||
data: { id: productOne.id },
|
||||
},
|
||||
],
|
||||
{
|
||||
name: "product.updated",
|
||||
data: { id: productOne.id },
|
||||
},
|
||||
])
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it("should add relationships to a product", async () => {
|
||||
@@ -724,12 +729,17 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
|
||||
const products = await service.createProducts([data])
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
{
|
||||
name: "product.created",
|
||||
data: { id: products[0].id },
|
||||
},
|
||||
],
|
||||
{
|
||||
name: "product.created",
|
||||
data: { id: products[0].id },
|
||||
},
|
||||
])
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -814,12 +824,17 @@ moduleIntegrationTestRunner<IProductModuleService>({
|
||||
|
||||
await service.softDeleteProducts([products[0].id])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
{
|
||||
name: "product.created",
|
||||
data: { id: products[0].id },
|
||||
},
|
||||
],
|
||||
{
|
||||
name: "product.created",
|
||||
data: { id: products[0].id },
|
||||
},
|
||||
])
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ import {
|
||||
ProductTypes,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
Image as ProductImage,
|
||||
Product,
|
||||
ProductCategory,
|
||||
ProductCollection,
|
||||
Image as ProductImage,
|
||||
ProductOption,
|
||||
ProductOptionValue,
|
||||
ProductTag,
|
||||
@@ -875,7 +875,10 @@ export default class ProductModuleService
|
||||
collections.map(({ id }) => ({
|
||||
name: ProductCollectionEvents.COLLECTION_CREATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
return Array.isArray(data) ? createdCollections : createdCollections[0]
|
||||
@@ -948,7 +951,10 @@ export default class ProductModuleService
|
||||
created.map(({ id }) => ({
|
||||
name: ProductCollectionEvents.COLLECTION_CREATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -957,7 +963,10 @@ export default class ProductModuleService
|
||||
updated.map(({ id }) => ({
|
||||
name: ProductCollectionEvents.COLLECTION_UPDATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1018,7 +1027,10 @@ export default class ProductModuleService
|
||||
updatedCollections.map(({ id }) => ({
|
||||
name: ProductCollectionEvents.COLLECTION_UPDATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
return isString(idOrSelector) ? updatedCollections[0] : updatedCollections
|
||||
@@ -1281,7 +1293,10 @@ export default class ProductModuleService
|
||||
createdProducts.map(({ id }) => ({
|
||||
name: ProductEvents.PRODUCT_CREATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
return Array.isArray(data) ? createdProducts : createdProducts[0]
|
||||
@@ -1329,7 +1344,10 @@ export default class ProductModuleService
|
||||
created.map(({ id }) => ({
|
||||
name: ProductEvents.PRODUCT_CREATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1338,7 +1356,10 @@ export default class ProductModuleService
|
||||
updated.map(({ id }) => ({
|
||||
name: ProductEvents.PRODUCT_UPDATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1392,7 +1413,10 @@ export default class ProductModuleService
|
||||
updatedProducts.map(({ id }) => ({
|
||||
name: ProductEvents.PRODUCT_UPDATED,
|
||||
data: { id },
|
||||
}))
|
||||
})),
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
|
||||
return isString(idOrSelector) ? updatedProducts[0] : updatedProducts
|
||||
|
||||
@@ -172,12 +172,17 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_UPDATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -189,12 +194,17 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
await service.refreshInviteTokens(["1"])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(2)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
describe("createInvitie", () => {
|
||||
@@ -218,24 +228,29 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
await service.createInvites(defaultInviteData)
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.INVITE_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.INVITE_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.INVITE_TOKEN_GENERATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -217,12 +217,17 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
])
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.USER_UPDATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.USER_UPDATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -247,16 +252,21 @@ moduleIntegrationTestRunner<IUserModuleService>({
|
||||
await service.createUsers(defaultUserData)
|
||||
|
||||
expect(eventBusSpy).toHaveBeenCalledTimes(1)
|
||||
expect(eventBusSpy).toHaveBeenCalledWith([
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.USER_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.USER_CREATED,
|
||||
}),
|
||||
])
|
||||
expect(eventBusSpy).toHaveBeenCalledWith(
|
||||
[
|
||||
expect.objectContaining({
|
||||
data: { id: "1" },
|
||||
name: UserEvents.USER_CREATED,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
data: { id: "2" },
|
||||
name: UserEvents.USER_CREATED,
|
||||
}),
|
||||
],
|
||||
{
|
||||
internal: true,
|
||||
}
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user