fix(index): merge filterable fields schema (#12888)
This commit is contained in:
1 parent
46bf7ae7ae
commit
fa76f85bba
4 files changed
+66
-3
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/test-utils": patch
|
||||||
|
"@medusajs/index": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(index): merge filterable fields with default fields
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
|
import CustomerModule from "@medusajs/customer"
|
||||||
|
import ProductModule from "@medusajs/product"
|
||||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||||
import { RemoteQueryFunction } from "@medusajs/types"
|
import { RemoteQueryFunction } from "@medusajs/types"
|
||||||
import { ContainerRegistrationKeys, defaultCurrencies } from "@medusajs/utils"
|
import {
|
||||||
|
ContainerRegistrationKeys,
|
||||||
|
defaultCurrencies,
|
||||||
|
defineLink,
|
||||||
|
} from "@medusajs/utils"
|
||||||
import { setTimeout } from "timers/promises"
|
import { setTimeout } from "timers/promises"
|
||||||
import {
|
import {
|
||||||
adminHeaders,
|
adminHeaders,
|
||||||
@@ -26,6 +32,7 @@ async function populateData(api: any) {
|
|||||||
title: "Test Product",
|
title: "Test Product",
|
||||||
status: "published",
|
status: "published",
|
||||||
description: "test-product-description",
|
description: "test-product-description",
|
||||||
|
origin_country: "USA",
|
||||||
shipping_profile_id: shippingProfile.id,
|
shipping_profile_id: shippingProfile.id,
|
||||||
options: [{ title: "Denominations", values: ["100"] }],
|
options: [{ title: "Denominations", values: ["100"] }],
|
||||||
variants: [
|
variants: [
|
||||||
@@ -82,6 +89,17 @@ async function populateData(api: any) {
|
|||||||
process.env.ENABLE_INDEX_MODULE = "true"
|
process.env.ENABLE_INDEX_MODULE = "true"
|
||||||
|
|
||||||
medusaIntegrationTestRunner({
|
medusaIntegrationTestRunner({
|
||||||
|
hooks: {
|
||||||
|
beforeServerStart: async () => {
|
||||||
|
const customer = CustomerModule.linkable.customer
|
||||||
|
const product = ProductModule.linkable.product
|
||||||
|
|
||||||
|
defineLink(customer, {
|
||||||
|
linkable: product,
|
||||||
|
filterable: ["origin_country"],
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
testSuite: ({ getContainer, dbConnection, api, dbConfig }) => {
|
testSuite: ({ getContainer, dbConnection, api, dbConfig }) => {
|
||||||
let appContainer
|
let appContainer
|
||||||
|
|
||||||
@@ -417,6 +435,33 @@ medusaIntegrationTestRunner({
|
|||||||
|
|
||||||
expect(resultset.data.length).toEqual(2)
|
expect(resultset.data.length).toEqual(2)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should query by custom linkable field and default field using query.index", async () => {
|
||||||
|
await populateData(api)
|
||||||
|
|
||||||
|
const query = appContainer.resolve(
|
||||||
|
ContainerRegistrationKeys.QUERY
|
||||||
|
) as RemoteQueryFunction
|
||||||
|
|
||||||
|
const resultset = await fetchAndRetry(
|
||||||
|
async () =>
|
||||||
|
await query.index({
|
||||||
|
entity: "product",
|
||||||
|
fields: ["id", "origin_country"],
|
||||||
|
filters: {
|
||||||
|
origin_country: ["USA"],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
({ data }) => data.length > 0,
|
||||||
|
{
|
||||||
|
retries: 3,
|
||||||
|
waitSeconds: 3,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(resultset.data.length).toEqual(1)
|
||||||
|
expect(resultset.data[0].origin_country).toEqual("USA")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { logger } from "@medusajs/framework/logger"
|
||||||
import { MedusaAppOutput } from "@medusajs/framework/modules-sdk"
|
import { MedusaAppOutput } from "@medusajs/framework/modules-sdk"
|
||||||
import { MedusaContainer } from "@medusajs/framework/types"
|
import { MedusaContainer } from "@medusajs/framework/types"
|
||||||
import {
|
import {
|
||||||
@@ -7,7 +8,6 @@ import {
|
|||||||
mergePluginModules,
|
mergePluginModules,
|
||||||
} from "@medusajs/framework/utils"
|
} from "@medusajs/framework/utils"
|
||||||
import { asValue } from "awilix"
|
import { asValue } from "awilix"
|
||||||
import { logger } from "@medusajs/framework/logger"
|
|
||||||
import { dbTestUtilFactory, getDatabaseURL } from "./database"
|
import { dbTestUtilFactory, getDatabaseURL } from "./database"
|
||||||
import {
|
import {
|
||||||
applyEnvVarsToProcess,
|
applyEnvVarsToProcess,
|
||||||
@@ -48,6 +48,9 @@ interface TestRunnerConfig {
|
|||||||
schema?: string
|
schema?: string
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
inApp?: boolean
|
inApp?: boolean
|
||||||
|
hooks?: {
|
||||||
|
beforeServerStart?: (container: MedusaContainer) => Promise<void>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MedusaTestRunner {
|
class MedusaTestRunner {
|
||||||
@@ -72,6 +75,7 @@ class MedusaTestRunner {
|
|||||||
private loadedApplication: any = null
|
private loadedApplication: any = null
|
||||||
private shutdown: () => Promise<void> = async () => void 0
|
private shutdown: () => Promise<void> = async () => void 0
|
||||||
private isFirstTime = true
|
private isFirstTime = true
|
||||||
|
private hooks: TestRunnerConfig["hooks"] = {}
|
||||||
|
|
||||||
constructor(config: TestRunnerConfig) {
|
constructor(config: TestRunnerConfig) {
|
||||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||||
@@ -93,6 +97,7 @@ class MedusaTestRunner {
|
|||||||
schema: this.schema,
|
schema: this.schema,
|
||||||
debug: this.debug,
|
debug: this.debug,
|
||||||
}
|
}
|
||||||
|
this.hooks = config.hooks ?? {}
|
||||||
|
|
||||||
this.setupProcessHandlers()
|
this.setupProcessHandlers()
|
||||||
}
|
}
|
||||||
@@ -158,6 +163,10 @@ class MedusaTestRunner {
|
|||||||
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
|
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (this.hooks?.beforeServerStart) {
|
||||||
|
await this.hooks.beforeServerStart(container)
|
||||||
|
}
|
||||||
|
|
||||||
await this.initializeDatabase()
|
await this.initializeDatabase()
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
@@ -309,6 +318,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
debug = false,
|
debug = false,
|
||||||
inApp = false,
|
inApp = false,
|
||||||
testSuite,
|
testSuite,
|
||||||
|
hooks,
|
||||||
}: {
|
}: {
|
||||||
moduleName?: string
|
moduleName?: string
|
||||||
env?: Record<string, any>
|
env?: Record<string, any>
|
||||||
@@ -318,6 +328,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
debug?: boolean
|
debug?: boolean
|
||||||
inApp?: boolean
|
inApp?: boolean
|
||||||
testSuite: (options: MedusaSuiteOptions) => void
|
testSuite: (options: MedusaSuiteOptions) => void
|
||||||
|
hooks?: TestRunnerConfig["hooks"]
|
||||||
}) {
|
}) {
|
||||||
const runner = new MedusaTestRunner({
|
const runner = new MedusaTestRunner({
|
||||||
moduleName,
|
moduleName,
|
||||||
@@ -327,6 +338,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
env,
|
env,
|
||||||
debug,
|
debug,
|
||||||
inApp,
|
inApp,
|
||||||
|
hooks,
|
||||||
})
|
})
|
||||||
|
|
||||||
return describe("", () => {
|
return describe("", () => {
|
||||||
|
|||||||
@@ -1206,7 +1206,7 @@ function buildSchemaFromFilterableLinks(
|
|||||||
})
|
})
|
||||||
.join("\n")
|
.join("\n")
|
||||||
|
|
||||||
return `type ${entity} ${events} {
|
return `extend type ${entity} ${events} {
|
||||||
${fieldDefinitions}
|
${fieldDefinitions}
|
||||||
}`
|
}`
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in new issue
Block a user