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