From 90d530565ba3019bf0eb754fc77660b101475019 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Tue, 24 Sep 2024 16:06:45 +0200 Subject: [PATCH] chore(): Remove default limit from the build query (#9257) * chore(): Remove default limit from the build query * rm take: null * fix tests * fix tests * fix db usage * fix typo * rm unsused template arg * fixes * fixes * fixes * fixes * fixes * fixes * fixes --- .../steps/get-promotion-codes-to-apply.ts | 2 +- .../steps/set-shipping-options-price-sets.ts | 1 - .../steps/set-shipping-options-prices.ts | 1 - .../steps/validate-fulfillment-providers.ts | 3 +- .../get-existing-price-lists-price-ids.ts | 2 +- .../steps/validate-variant-price-links.ts | 2 +- .../update-price-preferences-as-array.ts | 21 +- .../steps/batch-link-products-collection.ts | 3 +- .../steps/batch-link-products-in-category.ts | 4 +- .../src/product/steps/generate-product-csv.ts | 2 +- .../src/product/steps/get-products.ts | 2 +- .../product/steps/group-products-for-batch.ts | 2 +- .../src/product/steps/parse-product-csv.ts | 13 +- .../steps/set-regions-payment-providers.ts | 1 - .../core/medusa-test-utils/src/database.ts | 54 +++ packages/core/medusa-test-utils/src/index.ts | 1 + .../src/medusa-test-runner-utils/index.ts | 5 + .../src/medusa-test-runner.ts | 60 +-- .../src/dal/mikro-orm/__fixtures__/utils.ts | 28 +- .../__fixtures__/database.ts | 15 + .../integration-tests/__fixtures__/utils.ts | 352 ++++++++++++++++++ .../__tests__/mikro-orm-repository.spec.ts | 22 +- .../__tests__/utils.spec.ts | 34 +- .../core/utils/src/dal/mikro-orm/utils.ts | 21 +- .../core/utils/src/modules-sdk/build-query.ts | 26 +- .../modules-sdk/medusa-internal-service.ts | 6 +- .../src/services/api-key-module-service.ts | 6 +- .../__tests__/currency-module-service.spec.ts | 13 +- .../fulfillment-module-service/index.spec.ts | 7 +- .../__tests__/index-engine-module.spec.ts | 5 +- .../__tests__/query-builder.spec.ts | 5 +- .../src/services/inventory-module.ts | 2 +- .../services/notification-module-service.ts | 2 +- .../__tests__/create-order.ts | 4 - .../src/services/order-module-service.ts | 6 +- .../modules/payment/src/loaders/providers.ts | 2 +- .../pricing/src/services/pricing-module.ts | 8 +- .../src/services/product-module-service.ts | 11 +- .../src/services/promotion-module.ts | 15 +- .../__tests__/region-module.spec.ts | 2 +- .../region/src/services/region-module.ts | 2 +- 41 files changed, 549 insertions(+), 224 deletions(-) create mode 100644 packages/core/medusa-test-utils/src/medusa-test-runner-utils/index.ts create mode 100644 packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts create mode 100644 packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/utils.ts rename packages/core/utils/src/dal/mikro-orm/{ => integration-tests}/__tests__/utils.spec.ts (82%) diff --git a/packages/core/core-flows/src/cart/steps/get-promotion-codes-to-apply.ts b/packages/core/core-flows/src/cart/steps/get-promotion-codes-to-apply.ts index 615c300c83..c9c02e82c5 100644 --- a/packages/core/core-flows/src/cart/steps/get-promotion-codes-to-apply.ts +++ b/packages/core/core-flows/src/cart/steps/get-promotion-codes-to-apply.ts @@ -42,7 +42,7 @@ export const getPromotionCodesToApply = createStep( ( await promotionService.listPromotions( { code: adjustmentCodes }, - { select: ["code"], take: null } + { select: ["code"] } ) ).map((p) => p.code!) ) diff --git a/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-price-sets.ts b/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-price-sets.ts index 25febc6a87..410ae2792c 100644 --- a/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-price-sets.ts +++ b/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-price-sets.ts @@ -31,7 +31,6 @@ async function getCurrentShippingOptionPriceSetsLinks( service: LINKS.ShippingOptionPriceSet, variables: { filters: { shipping_option_id: shippingOptionIds }, - take: null, }, fields: ["shipping_option_id", "price_set_id"], } as any)) as { diff --git a/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts b/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts index aedf72d39d..6d875d1c30 100644 --- a/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts +++ b/packages/core/core-flows/src/fulfillment/steps/set-shipping-options-prices.ts @@ -36,7 +36,6 @@ async function getCurrentShippingOptionPrices( service: LINKS.ShippingOptionPriceSet, variables: { filters: { shipping_option_id: shippingOptionIds }, - take: null, }, fields: ["shipping_option_id", "price_set_id", "price_set.prices.*"], } as any)) as { diff --git a/packages/core/core-flows/src/fulfillment/steps/validate-fulfillment-providers.ts b/packages/core/core-flows/src/fulfillment/steps/validate-fulfillment-providers.ts index 097b497928..ccc715b120 100644 --- a/packages/core/core-flows/src/fulfillment/steps/validate-fulfillment-providers.ts +++ b/packages/core/core-flows/src/fulfillment/steps/validate-fulfillment-providers.ts @@ -4,7 +4,7 @@ import { MedusaError, Modules, } from "@medusajs/utils" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" export type FulfillmentProviderValidationWorkflowInput = { id?: string @@ -36,7 +36,6 @@ export const validateFulfillmentProvidersStep = createStep( }, { select: ["id", "service_zone_id", "provider_id"], - take: null, } ) diff --git a/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts b/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts index ae632ba956..9e8bb984c0 100644 --- a/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts +++ b/packages/core/core-flows/src/price-list/steps/get-existing-price-lists-price-ids.ts @@ -19,7 +19,7 @@ export const getExistingPriceListsPriceIdsStep = createStep( const existingPrices = priceListIds.length ? await pricingModule.listPrices( { price_list_id: priceListIds }, - { relations: ["price_list"], take: null } + { relations: ["price_list"] } ) : [] diff --git a/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts b/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts index 006514e004..0d638f265f 100644 --- a/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts +++ b/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts @@ -27,7 +27,7 @@ export const validateVariantPriceLinksStep = createStep( const links = await remoteQuery({ entryPoint: "product_variant_price_set", fields: ["variant_id", "price_set_id"], - variables: { variant_id: variantIds, take: null }, + variables: { variant_id: variantIds }, }) const variantPriceSetMap: Record = {} diff --git a/packages/core/core-flows/src/pricing/steps/update-price-preferences-as-array.ts b/packages/core/core-flows/src/pricing/steps/update-price-preferences-as-array.ts index 929f2682a9..f8cb368834 100644 --- a/packages/core/core-flows/src/pricing/steps/update-price-preferences-as-array.ts +++ b/packages/core/core-flows/src/pricing/steps/update-price-preferences-as-array.ts @@ -16,19 +16,16 @@ export const updatePricePreferencesAsArrayStep = createStep( const service = container.resolve(Modules.PRICING) const prevData = await service.listPricePreferences({ - $or: input.map( - (entry) => { - if (!entry.attribute || !entry.value) { - throw new MedusaError( - MedusaError.Types.INVALID_DATA, - "Attribute and value must be provided when updating price preferences" - ) - } + $or: input.map((entry) => { + if (!entry.attribute || !entry.value) { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + "Attribute and value must be provided when updating price preferences" + ) + } - return { attribute: entry.attribute, value: entry.value } - }, - { take: null } - ), + return { attribute: entry.attribute, value: entry.value } + }, {}), }) const toUpsert = input.map((entry) => { diff --git a/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts b/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts index c5ad777a94..fc0921ee4e 100644 --- a/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts +++ b/packages/core/core-flows/src/product/steps/batch-link-products-collection.ts @@ -1,6 +1,6 @@ import { IProductModuleService, LinkWorkflowInput } from "@medusajs/types" import { Modules } from "@medusajs/utils" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" export const batchLinkProductsToCollectionStepId = "batch-link-products-to-collection" @@ -17,7 +17,6 @@ export const batchLinkProductsToCollectionStep = createStep( } const dbCollection = await service.retrieveProductCollection(data.id, { - take: null, select: ["id", "products.id"], relations: ["products"], }) diff --git a/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts b/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts index dc9797d290..6863607545 100644 --- a/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts +++ b/packages/core/core-flows/src/product/steps/batch-link-products-in-category.ts @@ -1,6 +1,6 @@ import { IProductModuleService, ProductCategoryWorkflow } from "@medusajs/types" import { Modules } from "@medusajs/utils" -import { StepResponse, createStep } from "@medusajs/workflows-sdk" +import { createStep, StepResponse } from "@medusajs/workflows-sdk" export const batchLinkProductsToCategoryStepId = "batch-link-products-to-category" @@ -23,7 +23,6 @@ export const batchLinkProductsToCategoryStep = createStep( const dbProducts = await service.listProducts( { id: [...(data.add ?? []), ...(data.remove ?? [])] }, { - take: null, select: ["id", "categories"], } ) @@ -63,7 +62,6 @@ export const batchLinkProductsToCategoryStep = createStep( const dbProducts = await service.listProducts( { id: prevData.productIds }, { - take: null, select: ["id", "categories"], } ) diff --git a/packages/core/core-flows/src/product/steps/generate-product-csv.ts b/packages/core/core-flows/src/product/steps/generate-product-csv.ts index 3c8ba095e8..664bdbe890 100644 --- a/packages/core/core-flows/src/product/steps/generate-product-csv.ts +++ b/packages/core/core-flows/src/product/steps/generate-product-csv.ts @@ -71,7 +71,7 @@ export const generateProductCsvStep = createStep( const regions = await regionService.listRegions( {}, - { select: ["id", "name", "currency_code"], take: null } + { select: ["id", "name", "currency_code"] } ) const normalizedData = normalizeForExport(products, { regions }) diff --git a/packages/core/core-flows/src/product/steps/get-products.ts b/packages/core/core-flows/src/product/steps/get-products.ts index 4d10d5deae..35fa69bcf6 100644 --- a/packages/core/core-flows/src/product/steps/get-products.ts +++ b/packages/core/core-flows/src/product/steps/get-products.ts @@ -21,7 +21,7 @@ export const getProductsStep = createStep( const products = await service.listProducts( { id: data.ids }, - { relations: ["variants"], take: null } + { relations: ["variants"] } ) return new StepResponse(products, products) } diff --git a/packages/core/core-flows/src/product/steps/group-products-for-batch.ts b/packages/core/core-flows/src/product/steps/group-products-for-batch.ts index c3af51b379..5bd83d850e 100644 --- a/packages/core/core-flows/src/product/steps/group-products-for-batch.ts +++ b/packages/core/core-flows/src/product/steps/group-products-for-batch.ts @@ -19,7 +19,7 @@ export const groupProductsForBatchStep = createStep( // We use the ID to do product updates id: data.map((product) => product.id).filter(Boolean) as string[], }, - { take: null, select: ["handle"] } + { select: ["handle"] } ) const existingProductsSet = new Set(existingProducts.map((p) => p.id)) diff --git a/packages/core/core-flows/src/product/steps/parse-product-csv.ts b/packages/core/core-flows/src/product/steps/parse-product-csv.ts index 45631bf1de..ac616b7e78 100644 --- a/packages/core/core-flows/src/product/steps/parse-product-csv.ts +++ b/packages/core/core-flows/src/product/steps/parse-product-csv.ts @@ -30,9 +30,9 @@ export const parseProductCsvStep = createStep( const [productTypes, productCollections, salesChannels] = await Promise.all( [ - productService.listProductTypes({}, { take: null }), - productService.listProductCollections({}, { take: null }), - salesChannelService.listSalesChannels({}, { take: null }), + productService.listProductTypes({}, {}), + productService.listProductCollections({}, {}), + salesChannelService.listSalesChannels({}, {}), ] ) @@ -55,12 +55,9 @@ export const parseProductCsvStep = createStep( const [allRegions, allTags] = await Promise.all([ regionService.listRegions( {}, - { select: ["id", "name", "currency_code"], take: null } - ), - productService.listProductTags( - {}, - { select: ["id", "value"], take: null } + { select: ["id", "name", "currency_code"] } ), + productService.listProductTags({}, { select: ["id", "value"] }), ]) const normalizedData = normalizeForImport(v1Normalized, { diff --git a/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts b/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts index f077591b05..af788bf3fb 100644 --- a/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts +++ b/packages/core/core-flows/src/region/steps/set-regions-payment-providers.ts @@ -66,7 +66,6 @@ async function getCurrentRegionPaymentProvidersLinks( service: LINKS.RegionPaymentProvider, variables: { filters: { region_id: regionIds }, - take: null, }, fields: ["region_id", "payment_provider_id"], } as any)) as { diff --git a/packages/core/medusa-test-utils/src/database.ts b/packages/core/medusa-test-utils/src/database.ts index 9e74cc5e0f..df093c6008 100644 --- a/packages/core/medusa-test-utils/src/database.ts +++ b/packages/core/medusa-test-utils/src/database.ts @@ -1,4 +1,15 @@ import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql" +import { createDatabase, dropDatabase } from "pg-god" + +const DB_HOST = process.env.DB_HOST ?? "localhost" +const DB_USERNAME = process.env.DB_USERNAME ?? "" +const DB_PASSWORD = process.env.DB_PASSWORD ?? "" + +const pgGodCredentials = { + user: DB_USERNAME, + password: DB_PASSWORD, + host: DB_HOST, +} export function getDatabaseURL(dbName?: string): string { const DB_HOST = process.env.DB_HOST ?? "localhost" @@ -158,3 +169,46 @@ export function getMikroOrmWrapper({ }, } } + +export const dbTestUtilFactory = (): any => ({ + pgConnection_: null, + + create: async function (dbName: string) { + await createDatabase( + { databaseName: dbName, errorIfExist: false }, + pgGodCredentials + ) + }, + + teardown: async function ({ schema }: { schema?: string } = {}) { + if (!this.pgConnection_) { + return + } + + const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_) + + schema ??= "public" + + await runRawQuery(`SET session_replication_role = 'replica';`) + const { rows: tableNames } = await runRawQuery(`SELECT table_name + FROM information_schema.tables + WHERE table_schema = '${schema}';`) + + for (const { table_name } of tableNames) { + await runRawQuery(`DELETE + FROM ${schema}."${table_name}";`) + } + + await runRawQuery(`SET session_replication_role = 'origin';`) + }, + + shutdown: async function (dbName: string) { + await this.pgConnection_?.context?.destroy() + await this.pgConnection_?.destroy() + + return await dropDatabase( + { databaseName: dbName, errorIfNonExist: false }, + pgGodCredentials + ) + }, +}) diff --git a/packages/core/medusa-test-utils/src/index.ts b/packages/core/medusa-test-utils/src/index.ts index 8cc6c7f72b..ee45c10016 100644 --- a/packages/core/medusa-test-utils/src/index.ts +++ b/packages/core/medusa-test-utils/src/index.ts @@ -4,5 +4,6 @@ export { default as IdMap } from "./id-map" export * from "./init-modules" export * as JestUtils from "./jest" export * from "./medusa-test-runner" +export * from "./medusa-test-runner-utils/" export { default as MockEventBusService } from "./mock-event-bus-service" export * from "./module-test-runner" diff --git a/packages/core/medusa-test-utils/src/medusa-test-runner-utils/index.ts b/packages/core/medusa-test-utils/src/medusa-test-runner-utils/index.ts new file mode 100644 index 0000000000..96bf3498ad --- /dev/null +++ b/packages/core/medusa-test-utils/src/medusa-test-runner-utils/index.ts @@ -0,0 +1,5 @@ +export * from "./bootstrap-app" +export * from "./clear-instances" +export * from "./config" +export * from "./use-db" +export * from "./utils" \ No newline at end of file diff --git a/packages/core/medusa-test-utils/src/medusa-test-runner.ts b/packages/core/medusa-test-utils/src/medusa-test-runner.ts index c4ffb61ce2..f09039c8db 100644 --- a/packages/core/medusa-test-utils/src/medusa-test-runner.ts +++ b/packages/core/medusa-test-utils/src/medusa-test-runner.ts @@ -5,8 +5,7 @@ import { createMedusaContainer, } from "@medusajs/utils" import { asValue } from "awilix" -import { createDatabase, dropDatabase } from "pg-god" -import { getDatabaseURL } from "./database" +import { dbTestUtilFactory, getDatabaseURL } from "./database" import { startApp } from "./medusa-test-runner-utils/bootstrap-app" import { clearInstances } from "./medusa-test-runner-utils/clear-instances" import { configLoaderOverride } from "./medusa-test-runner-utils/config" @@ -17,60 +16,7 @@ import { } from "./medusa-test-runner-utils/use-db" import { applyEnvVarsToProcess } from "./medusa-test-runner-utils/utils" -const DB_HOST = process.env.DB_HOST -const DB_USERNAME = process.env.DB_USERNAME ?? "" -const DB_PASSWORD = process.env.DB_PASSWORD ?? "" - -const pgGodCredentials = { - user: DB_USERNAME, - password: DB_PASSWORD, - host: DB_HOST, -} - -export const dbTestUtilFactory = (): any => ({ - pgConnection_: null, - - create: async function (dbName: string) { - await createDatabase( - { databaseName: dbName, errorIfExist: false }, - pgGodCredentials - ) - }, - - teardown: async function ({ schema }: { schema?: string } = {}) { - if (!this.pgConnection_) { - return - } - - const runRawQuery = this.pgConnection_.raw.bind(this.pgConnection_) - - schema ??= "public" - - await runRawQuery(`SET session_replication_role = 'replica';`) - const { rows: tableNames } = await runRawQuery(`SELECT table_name - FROM information_schema.tables - WHERE table_schema = '${schema}';`) - - for (const { table_name } of tableNames) { - await runRawQuery(`DELETE - FROM ${schema}."${table_name}";`) - } - - await runRawQuery(`SET session_replication_role = 'origin';`) - }, - - shutdown: async function (dbName: string) { - await this.pgConnection_?.context?.destroy() - await this.pgConnection_?.destroy() - - return await dropDatabase( - { databaseName: dbName, errorIfNonExist: false }, - pgGodCredentials - ) - }, -}) - -export interface MedusaSuiteOptions { +export interface MedusaSuiteOptions { dbConnection: any // knex instance getContainer: () => MedusaContainer api: any @@ -106,7 +52,7 @@ export function medusaIntegrationTestRunner({ schema?: string debug?: boolean inApp?: boolean - testSuite: (options: MedusaSuiteOptions) => void + testSuite: (options: MedusaSuiteOptions) => void }) { const tempName = parseInt(process.env.JEST_WORKER_ID || "1") moduleName = moduleName ?? Math.random().toString(36).substring(7) diff --git a/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts b/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts index c8e9918044..97021f172d 100644 --- a/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts +++ b/packages/core/utils/src/dal/mikro-orm/__fixtures__/utils.ts @@ -20,7 +20,7 @@ class RecursiveEntity1 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @OneToMany(() => RecursiveEntity2, (entity2) => entity2.entity1, { @@ -44,7 +44,7 @@ class RecursiveEntity2 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @ManyToOne(() => RecursiveEntity1, { @@ -64,7 +64,7 @@ class Entity1 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @OneToMany(() => Entity2, (entity2) => entity2.entity1, { @@ -89,7 +89,7 @@ class Entity2 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @ManyToOne(() => Entity1, { mapToPk: true }) @@ -111,7 +111,7 @@ class DeepRecursiveEntity1 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @OneToMany(() => DeepRecursiveEntity2, (entity2) => entity2.entity1, { @@ -136,7 +136,7 @@ class DeepRecursiveEntity2 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @ManyToOne(() => DeepRecursiveEntity1) @@ -163,7 +163,7 @@ class DeepRecursiveEntity3 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @ManyToOne(() => DeepRecursiveEntity1, { @@ -187,7 +187,7 @@ class DeepRecursiveEntity4 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @ManyToOne(() => DeepRecursiveEntity1) @@ -214,7 +214,7 @@ class InternalCircularDependencyEntity1 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @OneToMany( @@ -226,7 +226,7 @@ class InternalCircularDependencyEntity1 { ) children = new Collection(this) - @ManyToOne(() => InternalCircularDependencyEntity1) + @ManyToOne(() => InternalCircularDependencyEntity1, { nullable: true }) parent: Rel } @@ -244,7 +244,7 @@ class Entity1WithUnDecoratedProp { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @OneToMany(() => Entity2WithUnDecoratedProp, (entity2) => entity2.entity1, { @@ -271,7 +271,7 @@ class Entity2WithUnDecoratedProp { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @ManyToOne(() => Entity1WithUnDecoratedProp, { mapToPk: true }) @@ -293,7 +293,7 @@ class SearchableEntity1 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @Searchable() @@ -321,7 +321,7 @@ class SearchableEntity2 { @PrimaryKey() id: string - @Property() + @Property({ nullable: true }) deleted_at: Date | null @Searchable() diff --git a/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts new file mode 100644 index 0000000000..34b07c08bc --- /dev/null +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/database.ts @@ -0,0 +1,15 @@ +const DB_HOST = process.env.DB_HOST ?? "localhost" +const DB_USERNAME = process.env.DB_USERNAME ?? "" +const DB_PASSWORD = process.env.DB_PASSWORD + +export const pgGodCredentials = { + user: DB_USERNAME, + password: DB_PASSWORD, + host: DB_HOST, +} + +export function getDatabaseURL(dbName): string { + return `postgres://${DB_USERNAME}${ + DB_PASSWORD ? `:${DB_PASSWORD}` : "" + }@${DB_HOST}/${dbName}` +} diff --git a/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/utils.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/utils.ts new file mode 100644 index 0000000000..dbf28eb70e --- /dev/null +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__fixtures__/utils.ts @@ -0,0 +1,352 @@ +import { + Collection, + Entity, + ManyToOne, + OneToMany, + PrimaryKey, + Property, + Rel, +} from "@mikro-orm/core" +import { Searchable } from "../../decorators/searchable" + +// Circular dependency one level +@Entity() +class RecursiveEntity1 { + constructor(props: { id: string; deleted_at: Date | null }) { + this.id = props.id + this.deleted_at = props.deleted_at + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @OneToMany(() => RecursiveEntity2, (entity2) => entity2.entity1, { + cascade: ["soft-remove"] as any, + }) + entity2 = new Collection(this) +} + +@Entity() +class RecursiveEntity2 { + constructor(props: { + id: string + deleted_at: Date | null + entity1: RecursiveEntity1 + }) { + this.id = props.id + this.deleted_at = props.deleted_at + this.entity1 = props.entity1 + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @ManyToOne(() => RecursiveEntity1, { + cascade: ["soft-remove"] as any, + }) + entity1: Rel +} + +// No circular dependency +@Entity() +class Entity1 { + constructor(props: { id: string; deleted_at: Date | null }) { + this.id = props.id + this.deleted_at = props.deleted_at + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @OneToMany(() => Entity2, (entity2) => entity2.entity1, { + cascade: ["soft-remove"] as any, + }) + entity2 = new Collection(this) +} + +@Entity() +class Entity2 { + constructor(props: { + id: string + deleted_at: Date | null + entity1: Rel + }) { + this.id = props.id + this.deleted_at = props.deleted_at + this.entity1 = props.entity1 + this.entity1_id = props.entity1.id + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @ManyToOne(() => Entity1, { mapToPk: true }) + entity1_id: string + + @ManyToOne(() => Entity1, { persist: false }) + entity1: Entity1 +} + +// Circular dependency deep level + +@Entity() +class DeepRecursiveEntity1 { + constructor(props: { id: string; deleted_at: Date | null }) { + this.id = props.id + this.deleted_at = props.deleted_at + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @OneToMany(() => DeepRecursiveEntity2, (entity2) => entity2.entity1, { + cascade: ["soft-remove"] as any, + }) + entity2 = new Collection(this) +} + +@Entity() +class DeepRecursiveEntity2 { + constructor(props: { + id: string + deleted_at: Date | null + entity1: Rel + entity3: Rel + }) { + this.id = props.id + this.deleted_at = props.deleted_at + this.entity3 = props.entity3 + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @ManyToOne(() => DeepRecursiveEntity1) + entity1: DeepRecursiveEntity1 + + @ManyToOne(() => DeepRecursiveEntity3, { + cascade: ["soft-remove"] as any, + }) + entity3: Rel +} + +@Entity() +class DeepRecursiveEntity3 { + constructor(props: { + id: string + deleted_at: Date | null + entity1: Rel + }) { + this.id = props.id + this.deleted_at = props.deleted_at + this.entity1 = props.entity1 + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @ManyToOne(() => DeepRecursiveEntity1, { + cascade: ["soft-remove"] as any, + }) + entity1: Rel +} + +@Entity() +class DeepRecursiveEntity4 { + constructor(props: { + id: string + deleted_at: Date | null + entity1: Rel + }) { + this.id = props.id + this.deleted_at = props.deleted_at + this.entity1 = props.entity1 + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @ManyToOne(() => DeepRecursiveEntity1) + entity1: Rel +} + +// Internal circular dependency + +@Entity() +class InternalCircularDependencyEntity1 { + constructor(props: { + id: string + deleted_at: Date | null + parent?: InternalCircularDependencyEntity1 + }) { + this.id = props.id + this.deleted_at = props.deleted_at + + if (props.parent) { + this.parent = props.parent + } + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @OneToMany( + () => InternalCircularDependencyEntity1, + (entity) => entity.parent, + { + cascade: ["soft-remove"] as any, + } + ) + children = new Collection(this) + + @ManyToOne(() => InternalCircularDependencyEntity1, { nullable: true }) + parent: Rel +} + +// With un decorated prop + +@Entity() +class Entity1WithUnDecoratedProp { + constructor(props: { id: string; deleted_at: Date | null }) { + this.id = props.id + this.deleted_at = props.deleted_at + } + + unknownProp: string + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @OneToMany(() => Entity2WithUnDecoratedProp, (entity2) => entity2.entity1, { + cascade: ["soft-remove"] as any, + }) + entity2 = new Collection(this) +} + +@Entity() +class Entity2WithUnDecoratedProp { + constructor(props: { + id: string + deleted_at: Date | null + entity1: Rel + }) { + this.id = props.id + this.deleted_at = props.deleted_at + this.entity1 = props.entity1 + this.entity1_id = props.entity1.id + } + + unknownProp: string + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @ManyToOne(() => Entity1WithUnDecoratedProp, { mapToPk: true }) + entity1_id: string + + @ManyToOne(() => Entity1WithUnDecoratedProp, { persist: false }) + entity1: Rel +} + +// Searchable fields + +@Entity() +class SearchableEntity1 { + constructor(props: { id: string; deleted_at: Date | null }) { + this.id = props.id + this.deleted_at = props.deleted_at + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @Searchable() + @Property() + searchableField: string + + @Searchable() + @OneToMany(() => SearchableEntity2, (entity2) => entity2.entity1) + entity2 = new Collection(this) +} + +@Entity() +class SearchableEntity2 { + constructor(props: { + id: string + deleted_at: Date | null + entity1: SearchableEntity1 + }) { + this.id = props.id + this.deleted_at = props.deleted_at + this.entity1 = props.entity1 + this.entity1_id = props.entity1.id + } + + @PrimaryKey() + id: string + + @Property({ nullable: true }) + deleted_at: Date | null + + @Searchable() + @Property() + searchableField: string + + @ManyToOne(() => SearchableEntity1, { mapToPk: true }) + entity1_id: string + + @ManyToOne(() => SearchableEntity1, { persist: false }) + entity1: Rel +} + +export { + DeepRecursiveEntity1, + DeepRecursiveEntity2, + DeepRecursiveEntity3, + DeepRecursiveEntity4, + Entity1, + Entity1WithUnDecoratedProp, + Entity2, + Entity2WithUnDecoratedProp, + InternalCircularDependencyEntity1, + RecursiveEntity1, + RecursiveEntity2, + SearchableEntity1, + SearchableEntity2, +} diff --git a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts index 2540f84fb4..060de818df 100644 --- a/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/mikro-orm-repository.spec.ts @@ -18,23 +18,9 @@ import { dropDatabase } from "pg-god" import { MikroOrmBigNumberProperty } from "../../big-number-field" import BigNumber from "bignumber.js" import { BigNumberRawValue } from "@medusajs/types" +import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database" -const DB_HOST = process.env.DB_HOST ?? "localhost" -const DB_USERNAME = process.env.DB_USERNAME ?? "" -const DB_PASSWORD = process.env.DB_PASSWORD -const DB_NAME = "mikroorm-integration-1" - -const pgGodCredentials = { - user: DB_USERNAME, - password: DB_PASSWORD, - host: DB_HOST, -} - -export function getDatabaseURL(): string { - return `postgres://${DB_USERNAME}${ - DB_PASSWORD ? `:${DB_PASSWORD}` : "" - }@${DB_HOST}/${DB_NAME}` -} +const dbName = "mikroorm-integration-1" jest.setTimeout(300000) @Entity() @@ -153,13 +139,13 @@ describe("mikroOrmRepository", () => { beforeEach(async () => { await dropDatabase( - { databaseName: DB_NAME, errorIfNonExist: false }, + { databaseName: dbName, errorIfNonExist: false }, pgGodCredentials ) orm = await MikroORM.init({ entities: [Entity1, Entity2], - clientUrl: getDatabaseURL(), + clientUrl: getDatabaseURL(dbName), type: "postgresql", }) diff --git a/packages/core/utils/src/dal/mikro-orm/__tests__/utils.spec.ts b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/utils.spec.ts similarity index 82% rename from packages/core/utils/src/dal/mikro-orm/__tests__/utils.spec.ts rename to packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/utils.spec.ts index 5b8995771c..cbef2979e8 100644 --- a/packages/core/utils/src/dal/mikro-orm/__tests__/utils.spec.ts +++ b/packages/core/utils/src/dal/mikro-orm/integration-tests/__tests__/utils.spec.ts @@ -1,4 +1,4 @@ -import { mikroOrmUpdateDeletedAtRecursively } from "../utils" +import { mikroOrmUpdateDeletedAtRecursively } from "../../utils" import { MikroORM } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" import { @@ -12,6 +12,10 @@ import { RecursiveEntity1, RecursiveEntity2, } from "../__fixtures__/utils" +import { dropDatabase } from "pg-god" +import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database" + +const dbName = "mikroorm-utils-integration-1" jest.mock("@mikro-orm/core", () => ({ ...jest.requireActual("@mikro-orm/core"), @@ -29,6 +33,11 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => { let orm!: MikroORM beforeEach(async () => { + await dropDatabase( + { databaseName: dbName, errorIfNonExist: false }, + pgGodCredentials + ) + orm = await MikroORM.init({ entities: [ Entity1, @@ -41,13 +50,19 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => { DeepRecursiveEntity4, InternalCircularDependencyEntity1, ], - dbName: "test", + clientUrl: getDatabaseURL(dbName), type: "postgresql", }) + + const generator = orm.getSchemaGenerator() + await generator.ensureDatabase() + await generator.createSchema() }) afterEach(async () => { - await orm.close() + const generator = orm.getSchemaGenerator() + await generator.dropSchema() + await orm.close(true) }) it("should successfully mark the entities deleted_at recursively", async () => { @@ -59,12 +74,14 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => { entity1: entity1, }) entity1.entity2.add(entity2) + manager.persist(entity1) + manager.persist(entity2) const deletedAt = new Date() await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt) - expect(entity1.deleted_at).toEqual(deletedAt) - expect(entity2.deleted_at).toEqual(deletedAt) + expect(!!entity1.deleted_at).toEqual(true) + expect(!!entity2.deleted_at).toEqual(true) }) it("should successfully mark the entities deleted_at recursively with internal parent/child relation", async () => { @@ -80,11 +97,14 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => { parent: entity1, }) + manager.persist(entity1) + manager.persist(childEntity1) + const deletedAt = new Date() await mikroOrmUpdateDeletedAtRecursively(manager, [entity1], deletedAt) - expect(entity1.deleted_at).toEqual(deletedAt) - expect(childEntity1.deleted_at).toEqual(deletedAt) + expect(!!entity1.deleted_at).toEqual(true) + expect(!!childEntity1.deleted_at).toEqual(true) }) it("should throw an error when a circular dependency is detected", async () => { diff --git a/packages/core/utils/src/dal/mikro-orm/utils.ts b/packages/core/utils/src/dal/mikro-orm/utils.ts index ec3f8f9a6d..64123bbdc3 100644 --- a/packages/core/utils/src/dal/mikro-orm/utils.ts +++ b/packages/core/utils/src/dal/mikro-orm/utils.ts @@ -1,4 +1,4 @@ -import { EntityMetadata, FindOptions, wrap } from "@mikro-orm/core" +import { Collection, EntityMetadata, FindOptions, wrap } from "@mikro-orm/core" import { SqlEntityManager } from "@mikro-orm/postgresql" import { buildQuery } from "../../modules-sdk/build-query" @@ -92,28 +92,29 @@ async function performCascadingSoftDeletion( ) } + entityRelation = await retrieveEntity() + entityRelation = entityRelation[relation.name] if (!entityRelation) { - // Fixes the case of many to many through pivot table - entityRelation = await retrieveEntity() - if (!entityRelation) { - continue - } + continue } const isCollection = "toArray" in entityRelation let relationEntities: any[] = [] if (isCollection) { - if (!entityRelation.isInitialized()) { + if (!(entityRelation as Collection).isInitialized()) { entityRelation = await retrieveEntity() entityRelation = entityRelation[relation.name] } relationEntities = entityRelation.getItems() } else { const wrappedEntity = wrap(entityRelation) - const initializedEntityRelation = wrappedEntity.isInitialized() - ? entityRelation - : await wrap(entityRelation).init() + + let initializedEntityRelation = entityRelation + if (!wrappedEntity.isInitialized()) { + initializedEntityRelation = await wrap(entityRelation).init() + } + relationEntities = [initializedEntityRelation] } diff --git a/packages/core/utils/src/modules-sdk/build-query.ts b/packages/core/utils/src/modules-sdk/build-query.ts index 04974bc8bf..b6dd21afa9 100644 --- a/packages/core/utils/src/modules-sdk/build-query.ts +++ b/packages/core/utils/src/modules-sdk/build-query.ts @@ -1,5 +1,5 @@ import { DAL, FindConfig } from "@medusajs/types" -import { deduplicate, isDefined, isObject } from "../common" +import { deduplicate, isObject } from "../common" import { SoftDeletableFilterKey } from "../dal/mikro-orm/mikro-orm-soft-deletable-filter" @@ -18,33 +18,13 @@ export function buildQuery( const filterFlags: FilterFlags = {} buildWhere(filters, where, filterFlags) - const primaryKeyFieldArray = isDefined(config.primaryKeyFields) - ? !Array.isArray(config.primaryKeyFields) - ? [config.primaryKeyFields] - : config.primaryKeyFields - : ["id"] - - const whereHasPrimaryKeyFields = primaryKeyFieldArray.some( - (pkField) => !!where[pkField] - ) - - const defaultLimit = whereHasPrimaryKeyFields ? undefined : 15 - delete config.primaryKeyFields const findOptions: DAL.OptionsQuery = { populate: deduplicate(config.relations ?? []), fields: config.select as string[], - limit: - (Number.isSafeInteger(config.take) && config.take! >= 0) || - null === config.take - ? config.take ?? undefined - : defaultLimit, - offset: - (Number.isSafeInteger(config.skip) && config.skip! >= 0) || - null === config.skip - ? config.skip ?? undefined - : 0, + limit: (Number.isSafeInteger(config.take) && config.take) || undefined, + offset: (Number.isSafeInteger(config.skip) && config.skip) || undefined, } if (config.order) { diff --git a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts index cc5db00de3..506ab979de 100644 --- a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts +++ b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts @@ -272,9 +272,7 @@ export function MedusaInternalService< if (input_.selector) { const entitiesToUpdate = await this.list( input_.selector, - { - take: null, - }, + {}, sharedContext ) // Create a pair of entity and data to update @@ -303,7 +301,7 @@ export function MedusaInternalService< if (keySelectorForDataOnly.$or.length) { const entitiesToUpdate = await this.list( keySelectorForDataOnly, - { take: null }, + {}, sharedContext ) diff --git a/packages/modules/api-key/src/services/api-key-module-service.ts b/packages/modules/api-key/src/services/api-key-module-service.ts index 9b5e58a94a..5d4748f999 100644 --- a/packages/modules/api-key/src/services/api-key-module-service.ts +++ b/packages/modules/api-key/src/services/api-key-module-service.ts @@ -79,7 +79,7 @@ export class ApiKeyModuleService { revoked_at: { $gt: new Date() } }, ], }, - { take: null, select: ["id"] }, + { select: ["id"] }, sharedContext ) ).map((apiKey) => apiKey.id) @@ -445,7 +445,7 @@ export class ApiKeyModuleService { revoked_at: { $gt: new Date() } }, ], }, - { take: null }, + {}, sharedContext ) @@ -500,7 +500,7 @@ export class ApiKeyModuleService { revoked_at: { $gt: new Date() } }, ], }, - { take: null }, + {}, sharedContext ) diff --git a/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts b/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts index 0520a02ab5..65ea7eb01b 100644 --- a/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts +++ b/packages/modules/currency/integration-tests/__tests__/currency-module-service.spec.ts @@ -35,10 +35,7 @@ moduleIntegrationTestRunner({ describe("list", () => { it("list currencies", async () => { - const currenciesResult = await service.listCurrencies( - {}, - { take: null } - ) + const currenciesResult = await service.listCurrencies({}, {}) expect(currenciesResult).toEqual( expect.arrayContaining([ expect.objectContaining({ @@ -58,7 +55,7 @@ moduleIntegrationTestRunner({ it("list currencies by code", async () => { const currenciesResult = await service.listCurrencies( { code: ["usd"] }, - { take: null } + {} ) expect(currenciesResult).toEqual([ @@ -72,7 +69,7 @@ moduleIntegrationTestRunner({ it("list currencies by code regardless of case-sensitivity", async () => { const currenciesResult = await service.listCurrencies( { code: ["Usd"] }, - { take: null } + {} ) expect(currenciesResult).toEqual([ @@ -87,7 +84,7 @@ moduleIntegrationTestRunner({ describe("listAndCountCurrenciesCurrencies", () => { it("should return currencies and count", async () => { const [currenciesResult, count] = - await service.listAndCountCurrencies({}, { take: null }) + await service.listAndCountCurrencies({}, {}) expect(count).toEqual(120) expect(currenciesResult).toEqual( @@ -110,7 +107,7 @@ moduleIntegrationTestRunner({ { code: ["usd"], }, - { take: null } + {} ) expect(count).toEqual(1) diff --git a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts index 531e3041b7..866d4f18f3 100644 --- a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts +++ b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts @@ -3,14 +3,16 @@ import { FulfillmentSetDTO, IFulfillmentModuleService } from "@medusajs/types" import { Module, Modules } from "@medusajs/utils" import { FulfillmentModuleService, FulfillmentProviderService } from "@services" import { - SuiteOptions, initModules, moduleIntegrationTestRunner, + SuiteOptions, } from "medusa-test-utils" import { resolve } from "path" import { createFullDataStructure } from "../../__fixtures__" import { FulfillmentProviderServiceFixtures } from "../../__fixtures__/providers" +jest.setTimeout(60000) + let moduleOptions = { providers: [ { @@ -34,7 +36,6 @@ async function list( const finalConfig = { relations: [ "service_zones.geo_zones", - "service_zones.shipping_options.shipping_profile", "service_zones.shipping_options.provider", "service_zones.shipping_options.type", "service_zones.shipping_options.rules", @@ -382,7 +383,7 @@ moduleIntegrationTestRunner({ */ await service.restoreFulfillmentSets([fulfillmentSets[0].id]) - const restoredFulfillmentSets = await list(service) + const restoredFulfillmentSets = await list(service, {}) expectSoftDeleted(restoredFulfillmentSets) }) }), diff --git a/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts b/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts index 1365303501..b90ecc255b 100644 --- a/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts +++ b/packages/modules/index/integration-tests/__tests__/index-engine-module.spec.ts @@ -14,8 +14,7 @@ import { import { EntityManager } from "@mikro-orm/postgresql" import { IndexData, IndexRelation } from "@models" import { asValue } from "awilix" -import { dbTestUtilFactory } from "medusa-test-utils" -import { initDb } from "medusa-test-utils/dist/medusa-test-runner-utils/use-db" +import { TestDatabaseUtils, initDb } from "medusa-test-utils" import * as path from "path" import { EventBusServiceMock } from "../__fixtures__" import { dbName } from "../__fixtures__/medusa-config" @@ -25,7 +24,7 @@ const queryMock = { graph: jest.fn(), } -const dbUtils = dbTestUtilFactory() +const dbUtils = TestDatabaseUtils.dbTestUtilFactory() jest.setTimeout(300000) diff --git a/packages/modules/index/integration-tests/__tests__/query-builder.spec.ts b/packages/modules/index/integration-tests/__tests__/query-builder.spec.ts index 807456f1c5..3780b361c1 100644 --- a/packages/modules/index/integration-tests/__tests__/query-builder.spec.ts +++ b/packages/modules/index/integration-tests/__tests__/query-builder.spec.ts @@ -14,8 +14,7 @@ import { import { EntityManager } from "@mikro-orm/postgresql" import { IndexData, IndexRelation } from "@models" import { asValue } from "awilix" -import { dbTestUtilFactory } from "medusa-test-utils" -import { initDb } from "medusa-test-utils/dist/medusa-test-runner-utils/use-db" +import { TestDatabaseUtils, initDb } from "medusa-test-utils" import path from "path" import { EventBusServiceMock } from "../__fixtures__" import { dbName } from "../__fixtures__/medusa-config" @@ -25,7 +24,7 @@ const queryMock = jest.fn().mockReturnValue({ graph: jest.fn(), }) -const dbUtils = dbTestUtilFactory() +const dbUtils = TestDatabaseUtils.dbTestUtilFactory() jest.setTimeout(300000) diff --git a/packages/modules/inventory-next/src/services/inventory-module.ts b/packages/modules/inventory-next/src/services/inventory-module.ts index 63890f47e1..afeb8462e2 100644 --- a/packages/modules/inventory-next/src/services/inventory-module.ts +++ b/packages/modules/inventory-next/src/services/inventory-module.ts @@ -1045,7 +1045,7 @@ export default class InventoryModuleService ): Promise { const [inventoryLevel] = await this.listInventoryLevels( { inventory_item_id: inventoryItemId, location_id: locationId }, - { take: null }, + {}, context ) diff --git a/packages/modules/notification/src/services/notification-module-service.ts b/packages/modules/notification/src/services/notification-module-service.ts index 63c513e833..60a222c5d1 100644 --- a/packages/modules/notification/src/services/notification-module-service.ts +++ b/packages/modules/notification/src/services/notification-module-service.ts @@ -121,7 +121,7 @@ export default class NotificationModuleService { idempotency_key: idempotencyKeys, }, - { take: null }, + {}, context ) diff --git a/packages/modules/order/integration-tests/__tests__/create-order.ts b/packages/modules/order/integration-tests/__tests__/create-order.ts index e8fc192695..f44aae134e 100644 --- a/packages/modules/order/integration-tests/__tests__/create-order.ts +++ b/packages/modules/order/integration-tests/__tests__/create-order.ts @@ -384,7 +384,6 @@ moduleIntegrationTestRunner({ { select: ["id"], relations: ["items"], - take: null, } ) expect(orders.length).toEqual(1) @@ -398,7 +397,6 @@ moduleIntegrationTestRunner({ { select: ["items.quantity"], relations: ["items"], - take: null, } ) expect(orders2.length).toEqual(0) @@ -414,7 +412,6 @@ moduleIntegrationTestRunner({ { select: ["id"], relations: ["items.detail"], - take: null, } ) expect(orders3.length).toEqual(1) @@ -430,7 +427,6 @@ moduleIntegrationTestRunner({ { select: ["id"], relations: ["items.detail"], - take: null, } ) expect(orders4.length).toEqual(0) diff --git a/packages/modules/order/src/services/order-module-service.ts b/packages/modules/order/src/services/order-module-service.ts index 04d1f94c08..e31bb5c03e 100644 --- a/packages/modules/order/src/services/order-module-service.ts +++ b/packages/modules/order/src/services/order-module-service.ts @@ -2678,7 +2678,6 @@ export default class OrderModuleService< : transactionData.order_id, }, { - take: null, select: ["id", "version"], }, sharedContext @@ -2726,7 +2725,6 @@ export default class OrderModuleService< }, { select: ["order_id", "version", "amount"], - take: null, }, sharedContext ) @@ -2752,7 +2750,6 @@ export default class OrderModuleService< id: transactionIds, }, { - take: null, select: ["order_id", "amount"], }, sharedContext @@ -2787,7 +2784,6 @@ export default class OrderModuleService< { select: ["order_id", "amount"], withDeleted: true, - take: null, }, sharedContext ) @@ -2820,7 +2816,7 @@ export default class OrderModuleService< { order_id: transactionData.map((trx) => trx.order_id), }, - { take: null }, + {}, sharedContext ) diff --git a/packages/modules/payment/src/loaders/providers.ts b/packages/modules/payment/src/loaders/providers.ts index 0fb1dd9621..b657918718 100644 --- a/packages/modules/payment/src/loaders/providers.ts +++ b/packages/modules/payment/src/loaders/providers.ts @@ -57,7 +57,7 @@ const registerProvidersInDb = async ({ const existingProviders = await paymentProviderService.list( { id: providersToLoad }, - { take: null } + {} ) const upsertData: CreatePaymentProviderDTO[] = [] diff --git a/packages/modules/pricing/src/services/pricing-module.ts b/packages/modules/pricing/src/services/pricing-module.ts index 2b3067ad3c..3ec63f5a1b 100644 --- a/packages/modules/pricing/src/services/pricing-module.ts +++ b/packages/modules/pricing/src/services/pricing-module.ts @@ -292,7 +292,7 @@ export default class PricingModuleService // We use the price rules to get the right preferences for the price const priceRulesForPrices = await this.priceRuleService_.list( { price_id: priceIds }, - { take: null } + {} ) const priceRulesPriceMap = groupBy(priceRulesForPrices, "price_id") @@ -947,7 +947,7 @@ export default class PricingModuleService ) { const priceSets = await this.listPriceSets( { id: input.map((d) => d.priceSetId) }, - { take: null, relations: ["prices", "prices.price_rules"] }, + { relations: ["prices", "prices.price_rules"] }, sharedContext ) @@ -1201,7 +1201,7 @@ export default class PricingModuleService ): Promise { const priceLists = await this.listPriceLists( { id: data.map((p) => p.price_list_id) }, - { take: null, relations: ["prices", "prices.price_rules"] }, + { relations: ["prices", "prices.price_rules"] }, sharedContext ) @@ -1257,7 +1257,7 @@ export default class PricingModuleService ): Promise { const priceLists = await this.listPriceLists( { id: data.map((p) => p.price_list_id) }, - { take: null, relations: ["prices", "prices.price_rules"] }, + { relations: ["prices", "prices.price_rules"] }, sharedContext ) diff --git a/packages/modules/product/src/services/product-module-service.ts b/packages/modules/product/src/services/product-module-service.ts index b5a29f7a8a..eeb7ff91b0 100644 --- a/packages/modules/product/src/services/product-module-service.ts +++ b/packages/modules/product/src/services/product-module-service.ts @@ -204,7 +204,6 @@ export default class ProductModuleService product_id: [...new Set(data.map((v) => v.product_id!))], }, { - take: null, relations: ["values"], }, sharedContext @@ -326,7 +325,7 @@ export default class ProductModuleService const variantIdsToUpdate = data.map(({ id }) => id) const variants = await this.productVariantService_.list( { id: variantIdsToUpdate }, - { take: null }, + {}, sharedContext ) if (variants.length !== data.length) { @@ -354,7 +353,7 @@ export default class ProductModuleService new Set(variantsWithProductId.map((v) => v.product_id!)) ), }, - { take: null, relations: ["values"] }, + { relations: ["values"] }, sharedContext ) @@ -791,7 +790,7 @@ export default class ProductModuleService const dbOptions = await this.productOptionService_.list( { id: data.map(({ id }) => id) }, - { take: null, relations: ["values"] }, + { relations: ["values"] }, sharedContext ) @@ -1553,7 +1552,7 @@ export default class ProductModuleService if (product.variants?.length) { allOptions = await this.productOptionService_.list( { product_id: upsertedProduct.id }, - { take: null, relations: ["values"] }, + { relations: ["values"] }, sharedContext ) } @@ -1641,7 +1640,7 @@ export default class ProductModuleService if (productData.options?.length) { const dbOptions = await this.productOptionService_.list( { product_id: productData.id }, - { take: null, relations: ["values"] }, + { relations: ["values"] }, sharedContext ) diff --git a/packages/modules/promotion/src/services/promotion-module.ts b/packages/modules/promotion/src/services/promotion-module.ts index 06436fe631..a3c7d84166 100644 --- a/packages/modules/promotion/src/services/promotion-module.ts +++ b/packages/modules/promotion/src/services/promotion-module.ts @@ -138,7 +138,6 @@ export default class PromotionModuleService { code: promotionCodes }, { relations: ["campaign", "campaign.budget"], - take: null, }, sharedContext ) @@ -245,7 +244,6 @@ export default class PromotionModuleService }, { relations: ["campaign", "campaign.budget"], - take: null, }, sharedContext ) @@ -352,7 +350,7 @@ export default class PromotionModuleService ? [] : await this.listPromotions( { is_automatic: true }, - { select: ["code"], take: null }, + { select: ["code"] }, sharedContext ) @@ -410,7 +408,6 @@ export default class PromotionModuleService "campaign", "campaign.budget", ], - take: null, } ) @@ -564,7 +561,6 @@ export default class PromotionModuleService "campaign", "campaign.budget", ], - take: null, }, sharedContext ) @@ -830,7 +826,6 @@ export default class PromotionModuleService "campaign", "campaign.budget", ], - take: null, }, sharedContext ) @@ -1275,7 +1270,6 @@ export default class PromotionModuleService { id: createdCampaigns.map((p) => p!.id) }, { relations: ["budget", "promotions"], - take: null, }, sharedContext ) @@ -1385,7 +1379,6 @@ export default class PromotionModuleService { id: updatedCampaigns.map((p) => p!.id) }, { relations: ["budget", "promotions"], - take: null, }, sharedContext ) @@ -1405,7 +1398,7 @@ export default class PromotionModuleService const existingCampaigns = await this.listCampaigns( { id: campaignIds }, - { relations: ["budget"], take: null }, + { relations: ["budget"] }, sharedContext ) @@ -1489,7 +1482,7 @@ export default class PromotionModuleService const campaign = await this.campaignService_.retrieve(id, {}, sharedContext) const promotionsToAdd = await this.promotionService_.list( { id: promotionIds, campaign_id: null }, - { take: null, relations: ["application_method"] }, + { relations: ["application_method"] }, sharedContext ) @@ -1552,7 +1545,7 @@ export default class PromotionModuleService await this.campaignService_.retrieve(id, {}, sharedContext) const promotionsToRemove = await this.promotionService_.list( { id: promotionIds }, - { take: null }, + {}, sharedContext ) diff --git a/packages/modules/region/integration-tests/__tests__/region-module.spec.ts b/packages/modules/region/integration-tests/__tests__/region-module.spec.ts index d734ba1bd9..72a011f5ce 100644 --- a/packages/modules/region/integration-tests/__tests__/region-module.spec.ts +++ b/packages/modules/region/integration-tests/__tests__/region-module.spec.ts @@ -43,7 +43,7 @@ moduleIntegrationTestRunner({ }) it("should create countries on application start", async () => { - const countries = await service.listCountries({}, { take: null }) + const countries = await service.listCountries({}, {}) expect(countries.length).toEqual(250) }) diff --git a/packages/modules/region/src/services/region-module.ts b/packages/modules/region/src/services/region-module.ts index 7282110448..2ed6781753 100644 --- a/packages/modules/region/src/services/region-module.ts +++ b/packages/modules/region/src/services/region-module.ts @@ -323,7 +323,7 @@ export default class RegionModuleService const countriesInDb = await this.countryService_.list( { iso_2: uniqueCountries }, - { select: ["iso_2", "region_id"], take: null }, + { select: ["iso_2", "region_id"] }, sharedContext ) const countryCodesInDb = countriesInDb.map((c) => c.iso_2.toLowerCase())