add: medusa-plugin-meilisearch + add deleted event in productService + tweak emitted event data in productVariantService

This commit is contained in:
zakariaelas committed 2021-09-09 17:56:10 +01:00
1 parent 4602cfc083
commit c56f37415d
24 files changed
+14041 -3

No files matched your search

@@ -801,6 +801,7 @@ describe("ProductVariantService", () => {
}
return Promise.resolve({
id: IdMap.getId("ironman"),
product_id: IdMap.getId("product-test"),
})
},
})
@@ -819,9 +820,20 @@ describe("ProductVariantService", () => {
await productVariantService.delete(IdMap.getId("ironman"))
expect(productVariantRepository.softRemove).toBeCalledTimes(1)
expect(productVariantRepository.softRemove).toBeCalledWith({
id: IdMap.getId("ironman"),
})
expect(productVariantRepository.softRemove).toBeCalledWith(
expect.objectContaining({
id: IdMap.getId("ironman"),
})
)
expect(eventBusService.emit).toHaveBeenCalledTimes(1)
expect(eventBusService.emit).toHaveBeenCalledWith(
"product-variant.deleted",
{
id: IdMap.getId("ironman"),
product_id: IdMap.getId("product-test"),
}
)
})
it("successfully resolves if variant does not exist", async () => {
@@ -306,6 +306,7 @@ describe("ProductService", () => {
const productService = new ProductService({
manager: MockManager,
productRepository,
eventBusService,
})
beforeEach(() => {
@@ -318,6 +319,11 @@ describe("ProductService", () => {
expect(productRepository.softRemove).toBeCalledWith({
id: IdMap.getId("ironman"),
})
expect(eventBusService.emit).toBeCalledTimes(1)
expect(eventBusService.emit).toBeCalledWith("product.deleted", {
id: IdMap.getId("ironman"),
})
})
})
@@ -11,6 +11,7 @@ class ProductVariantService extends BaseService {
static Events = {
UPDATED: "product-variant.updated",
CREATED: "product-variant.created",
DELETED: "product-variant.deleted",
}
/** @param { productVariantModel: (ProductVariantModel) } */
@@ -229,6 +230,7 @@ class ProductVariantService extends BaseService {
.withTransaction(manager)
.emit(ProductVariantService.Events.UPDATED, {
id: result.id,
product_id: result.product_id,
})
return result
@@ -305,6 +307,7 @@ class ProductVariantService extends BaseService {
.withTransaction(manager)
.emit(ProductVariantService.Events.UPDATED, {
id: result.id,
product_id: result.product_id,
fields: Object.keys(update),
})
return result
@@ -587,6 +590,11 @@ class ProductVariantService extends BaseService {
await variantRepo.softRemove(variant)
await this.eventBus_.emit(ProductVariantService.Events.DELETED, {
id: variant.id,
product_id: variant.product_id,
})
return Promise.resolve()
})
}
+7
View File
@@ -11,6 +11,7 @@ class ProductService extends BaseService {
static Events = {
UPDATED: "product.updated",
CREATED: "product.created",
DELETED: "product.deleted",
}
constructor({
@@ -473,6 +474,12 @@ class ProductService extends BaseService {
await productRepo.softRemove(product)
await this.eventBus_
.withTransaction(manager)
.emit(ProductService.Events.DELETED, {
id: productId,
})
return Promise.resolve()
})
}