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,
|
||||
|
||||
Reference in New Issue
Block a user