fix(inventory): Wrong event emitted on reservation update (#11714)
* fix(inventory): Wrong event emitted on reservation update * fix(inventory): Wrong event emitted on reservation update * Create tall-mice-smile.md
This commit is contained in:
1 parent
d172ad8ebc
commit
cad8b40c13
3 files changed
+64
-15
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/inventory": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(inventory): Wrong event emitted on reservation update
|
||||||
+45
-2
@@ -1,12 +1,25 @@
|
|||||||
import { IInventoryService, InventoryItemDTO } from "@medusajs/framework/types"
|
import { IInventoryService, InventoryItemDTO } from "@medusajs/framework/types"
|
||||||
import { BigNumber, Module, Modules } from "@medusajs/framework/utils"
|
import {
|
||||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
BigNumber,
|
||||||
|
CommonEvents,
|
||||||
|
composeMessage,
|
||||||
|
InventoryEvents,
|
||||||
|
Module,
|
||||||
|
Modules,
|
||||||
|
} from "@medusajs/framework/utils"
|
||||||
|
import {
|
||||||
|
MockEventBusService,
|
||||||
|
moduleIntegrationTestRunner,
|
||||||
|
} from "@medusajs/test-utils"
|
||||||
import { InventoryModuleService } from "../../src/services"
|
import { InventoryModuleService } from "../../src/services"
|
||||||
|
|
||||||
jest.setTimeout(100000)
|
jest.setTimeout(100000)
|
||||||
|
|
||||||
moduleIntegrationTestRunner<IInventoryService>({
|
moduleIntegrationTestRunner<IInventoryService>({
|
||||||
moduleName: Modules.INVENTORY,
|
moduleName: Modules.INVENTORY,
|
||||||
|
injectedDependencies: {
|
||||||
|
[Modules.EVENT_BUS]: new MockEventBusService(),
|
||||||
|
},
|
||||||
testSuite: ({ service }) => {
|
testSuite: ({ service }) => {
|
||||||
describe("Inventory Module Service", () => {
|
describe("Inventory Module Service", () => {
|
||||||
it(`should export the appropriate linkable configuration`, () => {
|
it(`should export the appropriate linkable configuration`, () => {
|
||||||
@@ -414,6 +427,8 @@ moduleIntegrationTestRunner<IInventoryService>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should update a reservationItem", async () => {
|
it("should update a reservationItem", async () => {
|
||||||
|
const eventBusSpy = jest.spyOn(MockEventBusService.prototype, "emit")
|
||||||
|
|
||||||
const update = {
|
const update = {
|
||||||
id: reservationItem.id,
|
id: reservationItem.id,
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
@@ -422,6 +437,20 @@ moduleIntegrationTestRunner<IInventoryService>({
|
|||||||
const updated = await service.updateReservationItems(update)
|
const updated = await service.updateReservationItems(update)
|
||||||
|
|
||||||
expect(updated).toEqual(expect.objectContaining(update))
|
expect(updated).toEqual(expect.objectContaining(update))
|
||||||
|
expect(eventBusSpy).toHaveBeenNthCalledWith(
|
||||||
|
1,
|
||||||
|
[
|
||||||
|
composeMessage(InventoryEvents.RESERVATION_ITEM_UPDATED, {
|
||||||
|
data: { id: reservationItem.id },
|
||||||
|
object: "reservation-item",
|
||||||
|
source: Modules.INVENTORY,
|
||||||
|
action: CommonEvents.UPDATED,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
{
|
||||||
|
internal: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const update2 = {
|
const update2 = {
|
||||||
id: reservationItem.id,
|
id: reservationItem.id,
|
||||||
@@ -431,6 +460,20 @@ moduleIntegrationTestRunner<IInventoryService>({
|
|||||||
const updated2 = await service.updateReservationItems(update2)
|
const updated2 = await service.updateReservationItems(update2)
|
||||||
|
|
||||||
expect(updated2).toEqual(expect.objectContaining(update2))
|
expect(updated2).toEqual(expect.objectContaining(update2))
|
||||||
|
expect(eventBusSpy).toHaveBeenNthCalledWith(
|
||||||
|
2,
|
||||||
|
[
|
||||||
|
composeMessage(InventoryEvents.RESERVATION_ITEM_UPDATED, {
|
||||||
|
data: { id: reservationItem.id },
|
||||||
|
object: "reservation-item",
|
||||||
|
source: Modules.INVENTORY,
|
||||||
|
action: CommonEvents.UPDATED,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
{
|
||||||
|
internal: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should adjust reserved_quantity of inventory level after updates increasing reserved quantity", async () => {
|
it("should adjust reserved_quantity of inventory level after updates increasing reserved quantity", async () => {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
MedusaContext,
|
MedusaContext,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
MedusaService,
|
MedusaService,
|
||||||
|
Modules,
|
||||||
partitionArray,
|
partitionArray,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { InventoryItem, InventoryLevel, ReservationItem } from "@models"
|
import { InventoryItem, InventoryLevel, ReservationItem } from "@models"
|
||||||
@@ -250,7 +251,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
created.map((reservationItem) => ({
|
created.map((reservationItem) => ({
|
||||||
eventName: InventoryEvents.RESERVATION_ITEM_CREATED,
|
eventName: InventoryEvents.RESERVATION_ITEM_CREATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.CREATED,
|
action: CommonEvents.CREATED,
|
||||||
object: "reservation-item",
|
object: "reservation-item",
|
||||||
context,
|
context,
|
||||||
@@ -352,7 +353,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
result.map((inventoryItem) => ({
|
result.map((inventoryItem) => ({
|
||||||
eventName: InventoryEvents.INVENTORY_ITEM_CREATED,
|
eventName: InventoryEvents.INVENTORY_ITEM_CREATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.CREATED,
|
action: CommonEvents.CREATED,
|
||||||
object: "inventory-item",
|
object: "inventory-item",
|
||||||
context,
|
context,
|
||||||
@@ -408,7 +409,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
created.map((inventoryLevel) => ({
|
created.map((inventoryLevel) => ({
|
||||||
eventName: InventoryEvents.INVENTORY_LEVEL_CREATED,
|
eventName: InventoryEvents.INVENTORY_LEVEL_CREATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.CREATED,
|
action: CommonEvents.CREATED,
|
||||||
object: "inventory-level",
|
object: "inventory-level",
|
||||||
context,
|
context,
|
||||||
@@ -464,7 +465,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
result.map((inventoryItem) => ({
|
result.map((inventoryItem) => ({
|
||||||
eventName: InventoryEvents.INVENTORY_ITEM_UPDATED,
|
eventName: InventoryEvents.INVENTORY_ITEM_UPDATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.UPDATED,
|
action: CommonEvents.UPDATED,
|
||||||
object: "inventory-item",
|
object: "inventory-item",
|
||||||
context,
|
context,
|
||||||
@@ -505,7 +506,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
result[0].map((inventoryLevel) => ({
|
result[0].map((inventoryLevel) => ({
|
||||||
eventName: InventoryEvents.INVENTORY_LEVEL_DELETED,
|
eventName: InventoryEvents.INVENTORY_LEVEL_DELETED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.DELETED,
|
action: CommonEvents.DELETED,
|
||||||
object: "inventory-level",
|
object: "inventory-level",
|
||||||
context,
|
context,
|
||||||
@@ -536,7 +537,7 @@ export default class InventoryModuleService
|
|||||||
|
|
||||||
context.messageAggregator?.saveRawMessageData({
|
context.messageAggregator?.saveRawMessageData({
|
||||||
eventName: InventoryEvents.INVENTORY_LEVEL_DELETED,
|
eventName: InventoryEvents.INVENTORY_LEVEL_DELETED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.DELETED,
|
action: CommonEvents.DELETED,
|
||||||
object: "inventory-level",
|
object: "inventory-level",
|
||||||
context,
|
context,
|
||||||
@@ -581,7 +582,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
levels.map((inventoryLevel) => ({
|
levels.map((inventoryLevel) => ({
|
||||||
eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
|
eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.UPDATED,
|
action: CommonEvents.UPDATED,
|
||||||
object: "inventory-level",
|
object: "inventory-level",
|
||||||
context,
|
context,
|
||||||
@@ -663,8 +664,8 @@ export default class InventoryModuleService
|
|||||||
|
|
||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
result.map((reservationItem) => ({
|
result.map((reservationItem) => ({
|
||||||
eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
|
eventName: InventoryEvents.RESERVATION_ITEM_UPDATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.UPDATED,
|
action: CommonEvents.UPDATED,
|
||||||
object: "reservation-item",
|
object: "reservation-item",
|
||||||
context,
|
context,
|
||||||
@@ -869,7 +870,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
reservations.map((reservationItem) => ({
|
reservations.map((reservationItem) => ({
|
||||||
eventName: InventoryEvents.RESERVATION_ITEM_DELETED,
|
eventName: InventoryEvents.RESERVATION_ITEM_DELETED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.DELETED,
|
action: CommonEvents.DELETED,
|
||||||
object: "reservation-item",
|
object: "reservation-item",
|
||||||
context,
|
context,
|
||||||
@@ -911,7 +912,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
reservations.map((reservationItem) => ({
|
reservations.map((reservationItem) => ({
|
||||||
eventName: InventoryEvents.RESERVATION_ITEM_DELETED,
|
eventName: InventoryEvents.RESERVATION_ITEM_DELETED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.DELETED,
|
action: CommonEvents.DELETED,
|
||||||
object: "reservation-item",
|
object: "reservation-item",
|
||||||
context,
|
context,
|
||||||
@@ -948,7 +949,7 @@ export default class InventoryModuleService
|
|||||||
context.messageAggregator?.saveRawMessageData(
|
context.messageAggregator?.saveRawMessageData(
|
||||||
reservations.map((reservationItem) => ({
|
reservations.map((reservationItem) => ({
|
||||||
eventName: InventoryEvents.RESERVATION_ITEM_CREATED,
|
eventName: InventoryEvents.RESERVATION_ITEM_CREATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.CREATED,
|
action: CommonEvents.CREATED,
|
||||||
object: "reservation-item",
|
object: "reservation-item",
|
||||||
context,
|
context,
|
||||||
@@ -1017,7 +1018,7 @@ export default class InventoryModuleService
|
|||||||
|
|
||||||
context.messageAggregator?.saveRawMessageData({
|
context.messageAggregator?.saveRawMessageData({
|
||||||
eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
|
eventName: InventoryEvents.INVENTORY_LEVEL_UPDATED,
|
||||||
source: this.constructor.name,
|
source: Modules.INVENTORY,
|
||||||
action: CommonEvents.UPDATED,
|
action: CommonEvents.UPDATED,
|
||||||
object: "inventory-level",
|
object: "inventory-level",
|
||||||
context,
|
context,
|
||||||
|
|||||||
Reference in new issue
Block a user