feat(medusa): Middleware to add default SC on query if no SC already exist on it (#3694)
This commit is contained in:
@@ -682,7 +682,7 @@ describe("Publishable API keys", () => {
|
||||
)
|
||||
})
|
||||
|
||||
it("returns all products if PK is not passed", async () => {
|
||||
it("returns default product from default sales channel if PK is not passed", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await api.post(
|
||||
@@ -703,15 +703,9 @@ describe("Publishable API keys", () => {
|
||||
},
|
||||
})
|
||||
|
||||
expect(response.data.products.length).toBe(3)
|
||||
expect(response.data.products.length).toBe(1)
|
||||
expect(response.data.products).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: product1.id,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: product2.id,
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: product3.id,
|
||||
}),
|
||||
|
||||
@@ -5,7 +5,7 @@ const { initDb, useDb } = require("../../../helpers/use-db")
|
||||
|
||||
const {
|
||||
simpleProductFactory,
|
||||
simpleProductCategoryFactory,
|
||||
simpleSalesChannelFactory,
|
||||
} = require("../../factories")
|
||||
|
||||
const productSeeder = require("../../helpers/store-product-seeder")
|
||||
@@ -37,7 +37,14 @@ describe("/store/products", () => {
|
||||
|
||||
describe("GET /store/products", () => {
|
||||
beforeEach(async () => {
|
||||
await productSeeder(dbConnection)
|
||||
const defaultSalesChannel = await simpleSalesChannelFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: "sales-channel",
|
||||
is_default: true,
|
||||
}
|
||||
)
|
||||
await productSeeder(dbConnection, defaultSalesChannel)
|
||||
await adminSeeder(dbConnection)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { simpleSalesChannelFactory } from "../../../factories"
|
||||
|
||||
const path = require("path")
|
||||
const setupServer = require("../../../../helpers/setup-server")
|
||||
const { useApi } = require("../../../../helpers/use-api")
|
||||
const { initDb, useDb } = require("../../../../helpers/use-db")
|
||||
|
||||
const {
|
||||
simpleProductCategoryFactory,
|
||||
} = require("../../../factories")
|
||||
const { simpleProductCategoryFactory } = require("../../../factories")
|
||||
|
||||
const productSeeder = require("../../../helpers/store-product-seeder")
|
||||
const adminSeeder = require("../../../helpers/admin-seeder")
|
||||
@@ -26,7 +26,7 @@ describe("/store/products", () => {
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({
|
||||
cwd,
|
||||
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true }
|
||||
env: { MEDUSA_FF_PRODUCT_CATEGORIES: true },
|
||||
})
|
||||
})
|
||||
|
||||
@@ -51,9 +51,15 @@ describe("/store/products", () => {
|
||||
const internalCategoryWithProductId = "inactive-category-with-product-id"
|
||||
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager
|
||||
const defaultSalesChannel = await simpleSalesChannelFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: "sales-channel",
|
||||
is_default: true,
|
||||
}
|
||||
)
|
||||
|
||||
await productSeeder(dbConnection)
|
||||
await productSeeder(dbConnection, defaultSalesChannel)
|
||||
await adminSeeder(dbConnection)
|
||||
|
||||
categoryWithProduct = await simpleProductCategoryFactory(dbConnection, {
|
||||
@@ -76,25 +82,31 @@ describe("/store/products", () => {
|
||||
}
|
||||
)
|
||||
|
||||
inactiveCategoryWithProduct = await simpleProductCategoryFactory(dbConnection, {
|
||||
id: inactiveCategoryWithProductId,
|
||||
name: "inactive category with Product",
|
||||
products: [{ id: testProductFilteringId2 }],
|
||||
parent_category: nestedCategoryWithProduct,
|
||||
is_active: false,
|
||||
is_internal: false,
|
||||
rank: 0,
|
||||
})
|
||||
inactiveCategoryWithProduct = await simpleProductCategoryFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: inactiveCategoryWithProductId,
|
||||
name: "inactive category with Product",
|
||||
products: [{ id: testProductFilteringId2 }],
|
||||
parent_category: nestedCategoryWithProduct,
|
||||
is_active: false,
|
||||
is_internal: false,
|
||||
rank: 0,
|
||||
}
|
||||
)
|
||||
|
||||
internalCategoryWithProduct = await simpleProductCategoryFactory(dbConnection, {
|
||||
id: inactiveCategoryWithProductId,
|
||||
name: "inactive category with Product",
|
||||
products: [{ id: testProductFilteringId2 }],
|
||||
parent_category: nestedCategoryWithProduct,
|
||||
is_active: true,
|
||||
is_internal: true,
|
||||
rank: 1,
|
||||
})
|
||||
internalCategoryWithProduct = await simpleProductCategoryFactory(
|
||||
dbConnection,
|
||||
{
|
||||
id: inactiveCategoryWithProductId,
|
||||
name: "inactive category with Product",
|
||||
products: [{ id: testProductFilteringId2 }],
|
||||
parent_category: nestedCategoryWithProduct,
|
||||
is_active: true,
|
||||
is_internal: true,
|
||||
rank: 1,
|
||||
}
|
||||
)
|
||||
|
||||
nested2CategoryWithProduct = await simpleProductCategoryFactory(
|
||||
dbConnection,
|
||||
|
||||
Reference in New Issue
Block a user