fix(index): merge filterable fields schema (#12888)
This commit is contained in:
committed by
GitHub
parent
46bf7ae7ae
commit
fa76f85bba
6
.changeset/tough-horses-return.md
Normal file
6
.changeset/tough-horses-return.md
Normal file
@@ -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 { RemoteQueryFunction } from "@medusajs/types"
|
||||
import { ContainerRegistrationKeys, defaultCurrencies } from "@medusajs/utils"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
defaultCurrencies,
|
||||
defineLink,
|
||||
} from "@medusajs/utils"
|
||||
import { setTimeout } from "timers/promises"
|
||||
import {
|
||||
adminHeaders,
|
||||
@@ -26,6 +32,7 @@ async function populateData(api: any) {
|
||||
title: "Test Product",
|
||||
status: "published",
|
||||
description: "test-product-description",
|
||||
origin_country: "USA",
|
||||
shipping_profile_id: shippingProfile.id,
|
||||
options: [{ title: "Denominations", values: ["100"] }],
|
||||
variants: [
|
||||
@@ -82,6 +89,17 @@ async function populateData(api: any) {
|
||||
process.env.ENABLE_INDEX_MODULE = "true"
|
||||
|
||||
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 }) => {
|
||||
let appContainer
|
||||
|
||||
@@ -417,6 +435,33 @@ medusaIntegrationTestRunner({
|
||||
|
||||
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 { MedusaContainer } from "@medusajs/framework/types"
|
||||
import {
|
||||
@@ -7,7 +8,6 @@ import {
|
||||
mergePluginModules,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { asValue } from "awilix"
|
||||
import { logger } from "@medusajs/framework/logger"
|
||||
import { dbTestUtilFactory, getDatabaseURL } from "./database"
|
||||
import {
|
||||
applyEnvVarsToProcess,
|
||||
@@ -48,6 +48,9 @@ interface TestRunnerConfig {
|
||||
schema?: string
|
||||
debug?: boolean
|
||||
inApp?: boolean
|
||||
hooks?: {
|
||||
beforeServerStart?: (container: MedusaContainer) => Promise<void>
|
||||
}
|
||||
}
|
||||
|
||||
class MedusaTestRunner {
|
||||
@@ -72,6 +75,7 @@ class MedusaTestRunner {
|
||||
private loadedApplication: any = null
|
||||
private shutdown: () => Promise<void> = async () => void 0
|
||||
private isFirstTime = true
|
||||
private hooks: TestRunnerConfig["hooks"] = {}
|
||||
|
||||
constructor(config: TestRunnerConfig) {
|
||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||
@@ -93,6 +97,7 @@ class MedusaTestRunner {
|
||||
schema: this.schema,
|
||||
debug: this.debug,
|
||||
}
|
||||
this.hooks = config.hooks ?? {}
|
||||
|
||||
this.setupProcessHandlers()
|
||||
}
|
||||
@@ -158,6 +163,10 @@ class MedusaTestRunner {
|
||||
[ContainerRegistrationKeys.LOGGER]: asValue(logger),
|
||||
})
|
||||
|
||||
if (this.hooks?.beforeServerStart) {
|
||||
await this.hooks.beforeServerStart(container)
|
||||
}
|
||||
|
||||
await this.initializeDatabase()
|
||||
|
||||
logger.info(
|
||||
@@ -309,6 +318,7 @@ export function medusaIntegrationTestRunner({
|
||||
debug = false,
|
||||
inApp = false,
|
||||
testSuite,
|
||||
hooks,
|
||||
}: {
|
||||
moduleName?: string
|
||||
env?: Record<string, any>
|
||||
@@ -318,6 +328,7 @@ export function medusaIntegrationTestRunner({
|
||||
debug?: boolean
|
||||
inApp?: boolean
|
||||
testSuite: (options: MedusaSuiteOptions) => void
|
||||
hooks?: TestRunnerConfig["hooks"]
|
||||
}) {
|
||||
const runner = new MedusaTestRunner({
|
||||
moduleName,
|
||||
@@ -327,6 +338,7 @@ export function medusaIntegrationTestRunner({
|
||||
env,
|
||||
debug,
|
||||
inApp,
|
||||
hooks,
|
||||
})
|
||||
|
||||
return describe("", () => {
|
||||
|
||||
@@ -1206,7 +1206,7 @@ function buildSchemaFromFilterableLinks(
|
||||
})
|
||||
.join("\n")
|
||||
|
||||
return `type ${entity} ${events} {
|
||||
return `extend type ${entity} ${events} {
|
||||
${fieldDefinitions}
|
||||
}`
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user