test(): Test the create product workflow compensation (#4716)
**What** Integration tests to validate the workflow compensation. Also, fix the transaction state when the workflow is compensating and some steps does not have any compensation
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
export * from "./create-products"
|
||||
export * from "./cart"
|
||||
export * from "./product"
|
||||
|
||||
+38
-70
@@ -1,19 +1,18 @@
|
||||
import { InputAlias, Workflows } from "../definitions"
|
||||
import { InputAlias, Workflows } from "../../definitions"
|
||||
import {
|
||||
TransactionStepsDefinition,
|
||||
WorkflowManager,
|
||||
} from "@medusajs/orchestration"
|
||||
import { exportWorkflow, pipe } from "../helper"
|
||||
import { aggregateData, exportWorkflow, pipe } from "../../helper"
|
||||
|
||||
import { ProductTypes, WorkflowTypes } from "@medusajs/types"
|
||||
import {
|
||||
InventoryHandlers,
|
||||
MiddlewaresHandlers,
|
||||
ProductHandlers,
|
||||
} from "../handlers"
|
||||
import { aggregateData } from "../helper/aggregate"
|
||||
} from "../../handlers"
|
||||
|
||||
export enum Actions {
|
||||
export enum CreateProductsActions {
|
||||
prepare = "prepare",
|
||||
createProducts = "createProducts",
|
||||
attachToSalesChannel = "attachToSalesChannel",
|
||||
@@ -21,34 +20,29 @@ export enum Actions {
|
||||
createPrices = "createPrices",
|
||||
createInventoryItems = "createInventoryItems",
|
||||
attachInventoryItems = "attachInventoryItems",
|
||||
result = "result",
|
||||
}
|
||||
|
||||
export const workflowSteps: TransactionStepsDefinition = {
|
||||
next: {
|
||||
action: Actions.prepare,
|
||||
action: CreateProductsActions.prepare,
|
||||
noCompensation: true,
|
||||
next: {
|
||||
action: Actions.createProducts,
|
||||
action: CreateProductsActions.createProducts,
|
||||
next: [
|
||||
{
|
||||
action: Actions.attachShippingProfile,
|
||||
action: CreateProductsActions.attachShippingProfile,
|
||||
saveResponse: false,
|
||||
},
|
||||
{
|
||||
action: Actions.attachToSalesChannel,
|
||||
action: CreateProductsActions.attachToSalesChannel,
|
||||
saveResponse: false,
|
||||
},
|
||||
{
|
||||
action: Actions.createPrices,
|
||||
action: CreateProductsActions.createPrices,
|
||||
next: {
|
||||
action: Actions.createInventoryItems,
|
||||
action: CreateProductsActions.createInventoryItems,
|
||||
next: {
|
||||
action: Actions.attachInventoryItems,
|
||||
next: {
|
||||
action: Actions.result,
|
||||
noCompensation: true,
|
||||
},
|
||||
action: CreateProductsActions.attachInventoryItems,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -59,7 +53,7 @@ export const workflowSteps: TransactionStepsDefinition = {
|
||||
|
||||
const handlers = new Map([
|
||||
[
|
||||
Actions.prepare,
|
||||
CreateProductsActions.prepare,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
@@ -69,17 +63,17 @@ const handlers = new Map([
|
||||
},
|
||||
},
|
||||
aggregateData(),
|
||||
MiddlewaresHandlers.createProductsPrepareData
|
||||
ProductHandlers.createProductsPrepareData
|
||||
),
|
||||
},
|
||||
],
|
||||
[
|
||||
Actions.createProducts,
|
||||
CreateProductsActions.createProducts,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
invoke: {
|
||||
from: Actions.prepare,
|
||||
from: CreateProductsActions.prepare,
|
||||
},
|
||||
},
|
||||
aggregateData(),
|
||||
@@ -88,7 +82,7 @@ const handlers = new Map([
|
||||
compensate: pipe(
|
||||
{
|
||||
invoke: {
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias: ProductHandlers.removeProducts.aliases.products,
|
||||
},
|
||||
},
|
||||
@@ -98,16 +92,16 @@ const handlers = new Map([
|
||||
},
|
||||
],
|
||||
[
|
||||
Actions.attachShippingProfile,
|
||||
CreateProductsActions.attachShippingProfile,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
invoke: [
|
||||
{
|
||||
from: Actions.prepare,
|
||||
from: CreateProductsActions.prepare,
|
||||
},
|
||||
{
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias:
|
||||
ProductHandlers.attachShippingProfileToProducts.aliases
|
||||
.products,
|
||||
@@ -121,10 +115,10 @@ const handlers = new Map([
|
||||
{
|
||||
invoke: [
|
||||
{
|
||||
from: Actions.prepare,
|
||||
from: CreateProductsActions.prepare,
|
||||
},
|
||||
{
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias:
|
||||
ProductHandlers.detachShippingProfileFromProducts.aliases
|
||||
.products,
|
||||
@@ -137,16 +131,16 @@ const handlers = new Map([
|
||||
},
|
||||
],
|
||||
[
|
||||
Actions.attachToSalesChannel,
|
||||
CreateProductsActions.attachToSalesChannel,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
invoke: [
|
||||
{
|
||||
from: Actions.prepare,
|
||||
from: CreateProductsActions.prepare,
|
||||
},
|
||||
{
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias:
|
||||
ProductHandlers.attachSalesChannelToProducts.aliases.products,
|
||||
},
|
||||
@@ -159,10 +153,10 @@ const handlers = new Map([
|
||||
{
|
||||
invoke: [
|
||||
{
|
||||
from: Actions.prepare,
|
||||
from: CreateProductsActions.prepare,
|
||||
},
|
||||
{
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias:
|
||||
ProductHandlers.detachSalesChannelFromProducts.aliases.products,
|
||||
},
|
||||
@@ -174,12 +168,12 @@ const handlers = new Map([
|
||||
},
|
||||
],
|
||||
[
|
||||
Actions.createInventoryItems,
|
||||
CreateProductsActions.createInventoryItems,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
invoke: {
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias: InventoryHandlers.createInventoryItems.aliases.products,
|
||||
},
|
||||
},
|
||||
@@ -189,7 +183,7 @@ const handlers = new Map([
|
||||
compensate: pipe(
|
||||
{
|
||||
invoke: {
|
||||
from: Actions.createInventoryItems,
|
||||
from: CreateProductsActions.createInventoryItems,
|
||||
alias:
|
||||
InventoryHandlers.removeInventoryItems.aliases.inventoryItems,
|
||||
},
|
||||
@@ -200,12 +194,12 @@ const handlers = new Map([
|
||||
},
|
||||
],
|
||||
[
|
||||
Actions.attachInventoryItems,
|
||||
CreateProductsActions.attachInventoryItems,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
invoke: {
|
||||
from: Actions.createInventoryItems,
|
||||
from: CreateProductsActions.createInventoryItems,
|
||||
alias:
|
||||
InventoryHandlers.attachInventoryItems.aliases.inventoryItems,
|
||||
},
|
||||
@@ -216,7 +210,7 @@ const handlers = new Map([
|
||||
compensate: pipe(
|
||||
{
|
||||
invoke: {
|
||||
from: Actions.createInventoryItems,
|
||||
from: CreateProductsActions.createInventoryItems,
|
||||
alias:
|
||||
InventoryHandlers.detachInventoryItems.aliases.inventoryItems,
|
||||
},
|
||||
@@ -227,16 +221,16 @@ const handlers = new Map([
|
||||
},
|
||||
],
|
||||
[
|
||||
Actions.createPrices,
|
||||
CreateProductsActions.createPrices,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
invoke: [
|
||||
{
|
||||
from: Actions.prepare,
|
||||
from: CreateProductsActions.prepare,
|
||||
},
|
||||
{
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias:
|
||||
ProductHandlers.updateProductsVariantsPrices.aliases.products,
|
||||
},
|
||||
@@ -249,10 +243,10 @@ const handlers = new Map([
|
||||
{
|
||||
invoke: [
|
||||
{
|
||||
from: Actions.prepare,
|
||||
from: CreateProductsActions.prepare,
|
||||
},
|
||||
{
|
||||
from: Actions.createProducts,
|
||||
from: CreateProductsActions.createProducts,
|
||||
alias:
|
||||
ProductHandlers.updateProductsVariantsPrices.aliases.products,
|
||||
},
|
||||
@@ -264,32 +258,6 @@ const handlers = new Map([
|
||||
),
|
||||
},
|
||||
],
|
||||
[
|
||||
Actions.result,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
invoke: [
|
||||
{
|
||||
from: Actions.prepare,
|
||||
},
|
||||
{
|
||||
from: Actions.createProducts,
|
||||
alias: "products",
|
||||
},
|
||||
],
|
||||
},
|
||||
async ({ data }) => {
|
||||
return {
|
||||
alias: ProductHandlers.listProducts.aliases.ids,
|
||||
value: data.products.map((product) => product.id),
|
||||
}
|
||||
},
|
||||
aggregateData(),
|
||||
ProductHandlers.listProducts
|
||||
),
|
||||
},
|
||||
],
|
||||
])
|
||||
|
||||
WorkflowManager.register(Workflows.CreateProducts, workflowSteps, handlers)
|
||||
@@ -297,4 +265,4 @@ WorkflowManager.register(Workflows.CreateProducts, workflowSteps, handlers)
|
||||
export const createProducts = exportWorkflow<
|
||||
WorkflowTypes.ProductWorkflow.CreateProductsWorkflowInputDTO,
|
||||
ProductTypes.ProductDTO[]
|
||||
>(Workflows.CreateProducts, Actions.result)
|
||||
>(Workflows.CreateProducts, CreateProductsActions.createProducts)
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./create-products"
|
||||
Reference in New Issue
Block a user