chore: Resolve flaky integration tests (#7587)
This commit is contained in:
committed by
GitHub
parent
0c0c510a37
commit
337b8ce0bb
@@ -1,5 +1,5 @@
|
||||
import { LinkDefinition, RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
|
||||
@@ -12,6 +12,11 @@ export const createRemoteLinkStep = createStep(
|
||||
const link = container.resolve<RemoteLink>(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
)
|
||||
|
||||
if (!data.length) {
|
||||
return new StepResponse([], [])
|
||||
}
|
||||
|
||||
await link.create(data)
|
||||
|
||||
return new StepResponse(data, data)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { LinkDefinition, RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
|
||||
@@ -10,6 +10,11 @@ export const dismissRemoteLinkStep = createStep(
|
||||
dismissRemoteLinkStepId,
|
||||
async (data: DismissRemoteLinksStepInput, { container }) => {
|
||||
const entries = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!entries.length) {
|
||||
return new StepResponse([], [])
|
||||
}
|
||||
|
||||
const link = container.resolve<RemoteLink>(
|
||||
ContainerRegistrationKeys.REMOTE_LINK
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DeleteEntityInput, RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
|
||||
@@ -10,6 +10,11 @@ export const removeRemoteLinkStep = createStep(
|
||||
removeRemoteLinkStepId,
|
||||
async (data: RemoveRemoteLinksStepInput, { container }) => {
|
||||
const entries = Array.isArray(data) ? data : [data]
|
||||
|
||||
if (!entries.length) {
|
||||
return new StepResponse(void 0)
|
||||
}
|
||||
|
||||
const grouped: DeleteEntityInput = {}
|
||||
|
||||
for (const entry of entries) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
ids: string[]
|
||||
ids?: string[]
|
||||
}
|
||||
|
||||
export const getProductsStepId = "get-products"
|
||||
@@ -14,6 +14,10 @@ export const getProductsStep = createStep(
|
||||
ModuleRegistrationName.PRODUCT
|
||||
)
|
||||
|
||||
if (!data.ids?.length) {
|
||||
return new StepResponse([], [])
|
||||
}
|
||||
|
||||
const products = await service.list(
|
||||
{ id: data.ids },
|
||||
{ relations: ["variants"], take: null }
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService, ProductTypes } from "@medusajs/types"
|
||||
import {
|
||||
MedusaError,
|
||||
getSelectsAndRelationsFromObjectArray,
|
||||
MedusaError,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export type UpdateProductsStepInput =
|
||||
| {
|
||||
@@ -31,6 +31,10 @@ export const updateProductsStep = createStep(
|
||||
)
|
||||
}
|
||||
|
||||
if (!data.products.length) {
|
||||
return new StepResponse([], [])
|
||||
}
|
||||
|
||||
const prevData = await service.list({
|
||||
id: data.products.map((p) => p.id) as string[],
|
||||
})
|
||||
|
||||
@@ -4,9 +4,9 @@ import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ProductTypes } from "@medusajs/types"
|
||||
import { arrayDifference } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
transform,
|
||||
WorkflowData,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
createRemoteLinkStep,
|
||||
@@ -39,6 +39,10 @@ function prepareUpdateProductInput({
|
||||
input: WorkflowInput
|
||||
}): UpdateProductsStepInput {
|
||||
if ("products" in input) {
|
||||
if (!input.products.length) {
|
||||
return { products: [] }
|
||||
}
|
||||
|
||||
return {
|
||||
products: input.products.map((p) => ({
|
||||
...p,
|
||||
@@ -83,6 +87,10 @@ function prepareSalesChannelLinks({
|
||||
input: WorkflowInput
|
||||
}): Record<string, Record<string, any>>[] {
|
||||
if ("products" in input) {
|
||||
if (!input.products.length) {
|
||||
return []
|
||||
}
|
||||
|
||||
return input.products
|
||||
.filter((p) => p.sales_channels)
|
||||
.flatMap((p) =>
|
||||
@@ -121,6 +129,10 @@ function prepareToDeleteLinks({
|
||||
sales_channel_id: string
|
||||
}[]
|
||||
}) {
|
||||
if (!currentLinks.length) {
|
||||
return []
|
||||
}
|
||||
|
||||
return currentLinks.map(({ product_id, sales_channel_id }) => ({
|
||||
[Modules.PRODUCT]: {
|
||||
product_id,
|
||||
|
||||
@@ -104,6 +104,7 @@ export function medusaIntegrationTestRunner({
|
||||
) => {
|
||||
const config = originalConfigLoader(rootDirectory)
|
||||
config.projectConfig.databaseUrl = dbConfig.clientUrl
|
||||
config.projectConfig.databaseLogging = !!dbConfig.debug
|
||||
config.projectConfig.databaseDriverOptions = dbConfig.clientUrl.includes(
|
||||
"localhost"
|
||||
)
|
||||
|
||||
@@ -180,18 +180,7 @@ export class MikroOrmBaseRepository<T extends object = object>
|
||||
idsOrFilter: string[] | InternalFilterQuery,
|
||||
sharedContext: Context = {}
|
||||
): Promise<[T[], Record<string, unknown[]>]> {
|
||||
// TODO handle composite keys
|
||||
const isArray = Array.isArray(idsOrFilter)
|
||||
const filter =
|
||||
isArray || isString(idsOrFilter)
|
||||
? {
|
||||
id: {
|
||||
$in: isArray ? idsOrFilter : [idsOrFilter],
|
||||
},
|
||||
}
|
||||
: idsOrFilter
|
||||
|
||||
const query = buildQuery(filter, {
|
||||
const query = buildQuery(idsOrFilter, {
|
||||
withDeleted: true,
|
||||
})
|
||||
|
||||
@@ -761,6 +750,27 @@ export function mikroOrmBaseRepositoryFactory<T extends object = object>(
|
||||
return orderedEntities
|
||||
}
|
||||
|
||||
async restore(
|
||||
filters:
|
||||
| string
|
||||
| string[]
|
||||
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)
|
||||
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)[],
|
||||
sharedContext: Context = {}
|
||||
): Promise<[T[], Record<string, unknown[]>]> {
|
||||
if (Array.isArray(filters) && !filters.filter(Boolean).length) {
|
||||
return [[], {}]
|
||||
}
|
||||
|
||||
if (!filters) {
|
||||
return [[], {}]
|
||||
}
|
||||
|
||||
const normalizedFilters = this.normalizeFilters(filters)
|
||||
|
||||
return await super.restore(normalizedFilters, sharedContext)
|
||||
}
|
||||
|
||||
async softDelete(
|
||||
filters:
|
||||
| string
|
||||
@@ -769,6 +779,26 @@ export function mikroOrmBaseRepositoryFactory<T extends object = object>(
|
||||
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)[],
|
||||
sharedContext: Context = {}
|
||||
): Promise<[T[], Record<string, unknown[]>]> {
|
||||
if (Array.isArray(filters) && !filters.filter(Boolean).length) {
|
||||
return [[], {}]
|
||||
}
|
||||
|
||||
if (!filters) {
|
||||
return [[], {}]
|
||||
}
|
||||
|
||||
const normalizedFilters = this.normalizeFilters(filters)
|
||||
|
||||
return await super.softDelete(normalizedFilters, sharedContext)
|
||||
}
|
||||
|
||||
private normalizeFilters(
|
||||
filters:
|
||||
| string
|
||||
| string[]
|
||||
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)
|
||||
| (FilterQuery<T> & BaseFilterable<FilterQuery<T>>)[]
|
||||
) {
|
||||
const primaryKeys =
|
||||
MikroOrmAbstractBaseRepository_.retrievePrimaryKeys(entity)
|
||||
|
||||
@@ -784,7 +814,7 @@ export function mikroOrmBaseRepositoryFactory<T extends object = object>(
|
||||
}),
|
||||
}
|
||||
|
||||
return await super.softDelete(normalizedFilters, sharedContext)
|
||||
return normalizedFilters
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user