fix: package.json run test integration in packages (#7249)
This commit is contained in:
committed by
GitHub
parent
e7a3528367
commit
a736e728b8
@@ -132,7 +132,6 @@ moduleIntegrationTestRunner({
|
||||
handle: "category-0",
|
||||
mpath: "category-0.",
|
||||
parent_category_id: null,
|
||||
parent_category: null,
|
||||
category_children: [
|
||||
expect.objectContaining({
|
||||
id: "category-1",
|
||||
@@ -551,7 +550,6 @@ moduleIntegrationTestRunner({
|
||||
handle: "category-0",
|
||||
mpath: "category-0.",
|
||||
parent_category_id: null,
|
||||
parent_category: null,
|
||||
category_children: [
|
||||
expect.objectContaining({
|
||||
id: "category-1",
|
||||
@@ -803,7 +801,6 @@ moduleIntegrationTestRunner({
|
||||
handle: "category-0",
|
||||
mpath: "category-0.",
|
||||
parent_category_id: null,
|
||||
parent_category: null,
|
||||
category_children: [
|
||||
expect.objectContaining({
|
||||
id: "category-1",
|
||||
@@ -865,7 +862,6 @@ moduleIntegrationTestRunner({
|
||||
handle: "category-0",
|
||||
mpath: "category-0.",
|
||||
parent_category_id: null,
|
||||
parent_category: null,
|
||||
category_children: [
|
||||
expect.objectContaining({
|
||||
id: "category-1",
|
||||
|
||||
@@ -4,11 +4,11 @@ import {
|
||||
ProductCategoryTransformOptions,
|
||||
ProductTypes,
|
||||
} from "@medusajs/types"
|
||||
import { DALUtils, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { DALUtils, isDefined, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
LoadStrategy,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { ProductCategory } from "@models"
|
||||
@@ -51,7 +51,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
}
|
||||
|
||||
const shouldExpandParent =
|
||||
familyOptions.includeAncestorsTree || populate.includes("parent_category") || fields.some(field => field.startsWith('parent_category'))
|
||||
familyOptions.includeAncestorsTree ||
|
||||
populate.includes("parent_category") ||
|
||||
fields.some((field) => field.startsWith("parent_category."))
|
||||
|
||||
if (shouldExpandParent) {
|
||||
populate.indexOf("parent_category") === -1 &&
|
||||
@@ -59,7 +61,9 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
}
|
||||
|
||||
const shouldExpandChildren =
|
||||
familyOptions.includeDescendantsTree || populate.includes("category_children") || fields.some(field => field.startsWith('category_children'))
|
||||
familyOptions.includeDescendantsTree ||
|
||||
populate.includes("category_children") ||
|
||||
fields.some((field) => field.startsWith("category_children."))
|
||||
|
||||
if (shouldExpandChildren) {
|
||||
populate.indexOf("category_children") === -1 &&
|
||||
@@ -85,7 +89,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
const productCategories = await manager.find(
|
||||
ProductCategory,
|
||||
findOptions_.where as MikroFilterQuery<ProductCategory>,
|
||||
findOptions_.options as MikroOptions<ProductCategory>
|
||||
{ ...findOptions_.options } as MikroOptions<ProductCategory>
|
||||
)
|
||||
|
||||
if (
|
||||
@@ -116,6 +120,20 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
): Promise<ProductCategory[]> {
|
||||
const manager = super.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
// We dont want to get the relations as we will fetch all the categories and build the tree manually
|
||||
let relationIndex =
|
||||
findOptions.options?.populate?.indexOf("parent_category")
|
||||
const shouldPopulateParent = relationIndex !== -1
|
||||
if (shouldPopulateParent && include.ancestors) {
|
||||
findOptions.options!.populate!.splice(relationIndex as number, 1)
|
||||
}
|
||||
|
||||
relationIndex = findOptions.options?.populate?.indexOf("category_children")
|
||||
const shouldPopulateChildren = relationIndex !== -1
|
||||
if (shouldPopulateChildren && include.descendants) {
|
||||
findOptions.options!.populate!.splice(relationIndex as number, 1)
|
||||
}
|
||||
|
||||
const mpaths: any[] = []
|
||||
const parentMpaths = new Set()
|
||||
for (const cat of productCategories) {
|
||||
@@ -161,7 +179,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
const categoriesById = new Map(allCategories.map((cat) => [cat.id, cat]))
|
||||
|
||||
allCategories.forEach((cat: any) => {
|
||||
if (cat.parent_category_id) {
|
||||
if (cat.parent_category_id && include.ancestors) {
|
||||
cat.parent_category = categoriesById.get(cat.parent_category_id)
|
||||
}
|
||||
})
|
||||
@@ -178,12 +196,17 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
}
|
||||
|
||||
if (level === 0) {
|
||||
if (!include.ancestors && !shouldPopulateParent) {
|
||||
delete category.parent_category
|
||||
}
|
||||
|
||||
return category
|
||||
}
|
||||
|
||||
if (include.ancestors) {
|
||||
delete category.category_children
|
||||
}
|
||||
|
||||
if (include.descendants) {
|
||||
delete category.parent_category
|
||||
}
|
||||
@@ -205,7 +228,7 @@ export class ProductCategoryRepository extends DALUtils.MikroOrmBaseTreeReposito
|
||||
context: Context = {}
|
||||
): Promise<[ProductCategory[], number]> {
|
||||
const manager = super.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
|
||||
const findOptions_ = this.buildFindOptions(findOptions, transformOptions)
|
||||
|
||||
const [productCategories, count] = await manager.findAndCount(
|
||||
|
||||
Reference in New Issue
Block a user