Merge branch 'develop' of https://github.com/medusajs/medusa into develop
This commit is contained in:
@@ -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
@@ -32,7 +32,7 @@ const convertToKebabCase = (string) => {
|
||||
const replaceUrl = (item) => {
|
||||
let { url, hierarchy } = item
|
||||
if (url.includes("api/store") || url.includes("/api/admin")) {
|
||||
url = url.replace("#", "/")
|
||||
url = url.replace("#", "")
|
||||
if (hierarchy.lvl2) {
|
||||
const index = url.lastIndexOf("/")
|
||||
url =
|
||||
|
||||
@@ -19,7 +19,7 @@ const Search = () => {
|
||||
const replaceUrl = item => {
|
||||
let { url, hierarchy } = item
|
||||
if (url.includes("api/store") || url.includes("/api/admin")) {
|
||||
url = url.replace("#", "/")
|
||||
url = url.replace("#", "")
|
||||
if (hierarchy.lvl2) {
|
||||
const index = url.lastIndexOf("/")
|
||||
url =
|
||||
|
||||
Reference in New Issue
Block a user