fix(medusa): Product repo typeorm issues (#4084)
* fix(medusa): Product repo typeorm issues * chore: fixed category scopes * WIP fix categories * fix product repo to attach categories * fix uni tests * Create eighty-icons-exercise.md * revert package.json * fix change set * last fixes * cleanup iteration * fix repository deep relations joining aliasing * improve response time * improve category test case * fix free texts search * fix repo * centralise repository manipulation into utils and use the utils in the product repo * fix product repo * fix customer group * update changeset * fix customer group * include feedback * fix repo * remove query strategy --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
committed by
GitHub
parent
26963acc0a
commit
9518efccae
@@ -1,27 +1,14 @@
|
||||
const path = require("path")
|
||||
const { ProductCategory } = require("@medusajs/medusa")
|
||||
const { DiscountRuleType, AllocationType } = require("@medusajs/medusa/dist")
|
||||
const { IdMap } = require("medusa-test-utils")
|
||||
const {
|
||||
ProductVariant,
|
||||
ProductOptionValue,
|
||||
MoneyAmount,
|
||||
DiscountConditionType,
|
||||
DiscountConditionOperator,
|
||||
} = require("@medusajs/medusa")
|
||||
|
||||
const setupServer = require("../../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../../helpers/use-db")
|
||||
const adminSeeder = require("../../../helpers/admin-seeder")
|
||||
const productSeeder = require("../../../helpers/product-seeder")
|
||||
const priceListSeeder = require("../../../helpers/price-list-seeder")
|
||||
const {
|
||||
simpleProductFactory,
|
||||
simpleDiscountFactory,
|
||||
simpleProductCategoryFactory,
|
||||
simpleSalesChannelFactory,
|
||||
simpleRegionFactory,
|
||||
} = require("../../../factories")
|
||||
|
||||
const testProductId = "test-product"
|
||||
@@ -124,10 +111,7 @@ describe("/admin/products [MEDUSA_FF_PRODUCT_CATEGORIES=true]", () => {
|
||||
it("returns a list of products in product category without category children", async () => {
|
||||
const api = useApi()
|
||||
const params = `category_id[]=${categoryWithProductId}`
|
||||
const response = await api.get(
|
||||
`/admin/products?${params}`,
|
||||
adminHeaders
|
||||
)
|
||||
const response = await api.get(`/admin/products?${params}`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
@@ -141,10 +125,7 @@ describe("/admin/products [MEDUSA_FF_PRODUCT_CATEGORIES=true]", () => {
|
||||
it("returns a list of products in product category without category children explicitly set to false", async () => {
|
||||
const api = useApi()
|
||||
const params = `category_id[]=${categoryWithProductId}&include_category_children=false`
|
||||
const response = await api.get(
|
||||
`/admin/products?${params}`,
|
||||
adminHeaders
|
||||
)
|
||||
const response = await api.get(`/admin/products?${params}`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
@@ -159,10 +140,7 @@ describe("/admin/products [MEDUSA_FF_PRODUCT_CATEGORIES=true]", () => {
|
||||
const api = useApi()
|
||||
|
||||
const params = `category_id[]=${categoryWithProductId}&include_category_children=true`
|
||||
const response = await api.get(
|
||||
`/admin/products?${params}`,
|
||||
adminHeaders
|
||||
)
|
||||
const response = await api.get(`/admin/products?${params}`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(3)
|
||||
@@ -185,10 +163,7 @@ describe("/admin/products [MEDUSA_FF_PRODUCT_CATEGORIES=true]", () => {
|
||||
const api = useApi()
|
||||
|
||||
const params = `category_id[]=${categoryWithoutProductId}&include_category_children=true`
|
||||
const response = await api.get(
|
||||
`/admin/products?${params}`,
|
||||
adminHeaders
|
||||
)
|
||||
const response = await api.get(`/admin/products?${params}`, adminHeaders)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(0)
|
||||
|
||||
@@ -98,7 +98,7 @@ describe("/store/products", () => {
|
||||
internalCategoryWithProduct = await simpleProductCategoryFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: inactiveCategoryWithProductId,
|
||||
id: internalCategoryWithProductId,
|
||||
name: "inactive category with Product",
|
||||
products: [{ id: testProductFilteringId2 }],
|
||||
parent_category: nestedCategoryWithProduct,
|
||||
@@ -219,6 +219,51 @@ describe("/store/products", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("returns only active and public products with include_category_children when categories are expanded", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const params = `id[]=${testProductFilteringId2}&expand=categories`
|
||||
let response = await api.get(`/store/products?${params}`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: testProductFilteringId2,
|
||||
categories: [],
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
const category = await simpleProductCategoryFactory(dbConnection, {
|
||||
id: categoryWithProductId,
|
||||
name: "category with Product 2",
|
||||
products: [{ id: response.data.products[0].id }],
|
||||
is_active: true,
|
||||
is_internal: false,
|
||||
})
|
||||
|
||||
response = await api.get(`/store/products?${params}`)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.products).toHaveLength(1)
|
||||
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: testProductFilteringId2,
|
||||
categories: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: category.id,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
|
||||
it("does not query products with category that are inactive", async () => {
|
||||
const api = useApi()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user