Add inventory options to restock notification (#364)
* add options inventory required precedence on condition check * merge develop * checkout medusa packages * remove medusa-interfaces from dependencies * run yarn after removing dependencies
This commit is contained in:
committed by
GitHub
parent
cdf9c972c9
commit
639e8cff14
@@ -16,6 +16,12 @@ describe("RestockNotificationService", () => {
|
||||
emails: ["test@tesmail.com"],
|
||||
})
|
||||
}
|
||||
if (q.where.variant_id === "variant_low_inventory") {
|
||||
return Promise.resolve({
|
||||
variant_id: "variant_low_inventory",
|
||||
email: ["test@tesmail.com"],
|
||||
})
|
||||
}
|
||||
return Promise.resolve()
|
||||
},
|
||||
})
|
||||
@@ -34,6 +40,12 @@ describe("RestockNotificationService", () => {
|
||||
inventory_quantity: 10,
|
||||
}
|
||||
}
|
||||
if (id === "variant_low_inventory") {
|
||||
return {
|
||||
id,
|
||||
inventory_quantity: 2,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
@@ -162,5 +174,50 @@ describe("RestockNotificationService", () => {
|
||||
"variant_1234"
|
||||
)
|
||||
})
|
||||
|
||||
it("options inventory_required takes precedence if given", async () => {
|
||||
jest.clearAllMocks()
|
||||
const service = new RestockNotificationService(
|
||||
{
|
||||
manager: MockManager,
|
||||
productVariantService: ProductVariantService,
|
||||
restockNotificationModel: RestockNotificationModel,
|
||||
eventBusService: EventBusService,
|
||||
},
|
||||
{ inventory_required: 5 }
|
||||
)
|
||||
|
||||
await service.triggerRestock("variant_1234")
|
||||
|
||||
expect(EventBusService.emit).toHaveBeenCalledTimes(1)
|
||||
expect(EventBusService.emit).toHaveBeenCalledWith(
|
||||
"restock-notification.restocked",
|
||||
{
|
||||
variant_id: "variant_1234",
|
||||
emails: ["test@tesmail.com"],
|
||||
}
|
||||
)
|
||||
expect(RestockNotificationModel.delete).toHaveBeenCalledTimes(1)
|
||||
expect(RestockNotificationModel.delete).toHaveBeenCalledWith(
|
||||
"variant_1234"
|
||||
)
|
||||
})
|
||||
it("Inventory requires 5, wont emit when called with variant inventory 2", async () => {
|
||||
jest.clearAllMocks()
|
||||
const service = new RestockNotificationService(
|
||||
{
|
||||
manager: MockManager,
|
||||
productVariantService: ProductVariantService,
|
||||
restockNotificationModel: RestockNotificationModel,
|
||||
eventBusService: EventBusService,
|
||||
},
|
||||
{ inventory_required: 5 }
|
||||
)
|
||||
|
||||
await service.triggerRestock("variant_low_inventory")
|
||||
|
||||
expect(EventBusService.emit).toHaveBeenCalledTimes(0)
|
||||
expect(RestockNotificationModel.delete).toHaveBeenCalledTimes(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -117,7 +117,10 @@ class RestockNotificationService extends BaseService {
|
||||
}
|
||||
|
||||
const variant = await this.productVariantService_.retrieve(variantId)
|
||||
if (variant.inventory_quantity > 0) {
|
||||
|
||||
if (
|
||||
variant.inventory_quantity > (this.options_?.inventory_required ?? 0)
|
||||
) {
|
||||
await this.eventBus_
|
||||
.withTransaction(manager)
|
||||
.emit("restock-notification.restocked", {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user