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
This commit is contained in:
Adrien de Peretti
2024-09-24 16:06:45 +02:00
committed by GitHub
parent 9e711720dd
commit 90d530565b
41 changed files with 549 additions and 224 deletions
@@ -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
)
@@ -35,10 +35,7 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
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<ICurrencyModuleService>({
it("list currencies by code", async () => {
const currenciesResult = await service.listCurrencies(
{ code: ["usd"] },
{ take: null }
{}
)
expect(currenciesResult).toEqual([
@@ -72,7 +69,7 @@ moduleIntegrationTestRunner<ICurrencyModuleService>({
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<ICurrencyModuleService>({
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<ICurrencyModuleService>({
{
code: ["usd"],
},
{ take: null }
{}
)
expect(count).toEqual(1)
@@ -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)
})
}),
@@ -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)
@@ -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)
@@ -1045,7 +1045,7 @@ export default class InventoryModuleService
): Promise<InventoryTypes.InventoryLevelDTO> {
const [inventoryLevel] = await this.listInventoryLevels(
{ inventory_item_id: inventoryItemId, location_id: locationId },
{ take: null },
{},
context
)
@@ -121,7 +121,7 @@ export default class NotificationModuleService
{
idempotency_key: idempotencyKeys,
},
{ take: null },
{},
context
)
@@ -384,7 +384,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
{
select: ["id"],
relations: ["items"],
take: null,
}
)
expect(orders.length).toEqual(1)
@@ -398,7 +397,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
{
select: ["items.quantity"],
relations: ["items"],
take: null,
}
)
expect(orders2.length).toEqual(0)
@@ -414,7 +412,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
{
select: ["id"],
relations: ["items.detail"],
take: null,
}
)
expect(orders3.length).toEqual(1)
@@ -430,7 +427,6 @@ moduleIntegrationTestRunner<IOrderModuleService>({
{
select: ["id"],
relations: ["items.detail"],
take: null,
}
)
expect(orders4.length).toEqual(0)
@@ -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
)
@@ -57,7 +57,7 @@ const registerProvidersInDb = async ({
const existingProviders = await paymentProviderService.list(
{ id: providersToLoad },
{ take: null }
{}
)
const upsertData: CreatePaymentProviderDTO[] = []
@@ -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<Price[]> {
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<Price[]> {
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
)
@@ -204,7 +204,6 @@ export default class ProductModuleService
product_id: [...new Set<string>(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
)
@@ -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
)
@@ -43,7 +43,7 @@ moduleIntegrationTestRunner<IRegionModuleService>({
})
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)
})
@@ -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())