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:
1 parent
6cfe9bd874
commit
5bec38538a
27 files changed
+915
-465
No files matched your search
+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
|
||||
|
||||
Reference in new issue
Block a user