-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core-flows,types): cancel order changes workflow #8035
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4afb7c1
chore: added order change create workflow
riqwan a27f8a0
Merge branch 'develop' into feat/order-changes
riqwan 1240862
chore: fix comments
riqwan dd62741
chore: remove redundant service + add validation on module service
riqwan af43d2e
Merge branch 'develop' into feat/order-changes
riqwan edf110a
chore: ignore fixtures folder
riqwan 65a3e3f
Merge branch 'develop' into feat/order-changes
riqwan ac28c4e
chore: cancel order changes workflow
riqwan 0d7bbce
Merge branch 'feat/order-changes' into feat/order-changes-cancel
riqwan 7ad5d7a
Merge branch 'develop' into feat/order-changes-cancel
riqwan 2441920
chore: make parameters dynamic based on inputs
riqwan 99c2020
Merge branch 'develop' into feat/order-changes-cancel
riqwan 49d54a5
chore: added order change workflow delete workflow (#8039)
riqwan 4e183e1
Merge branch 'develop' into feat/order-changes-cancel
riqwan 65527b7
chore: added decline order change workflow (#8041)
riqwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
integration-tests/modules/__tests__/order/workflows/order-change.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import { | ||
cancelOrderChangeWorkflow, | ||
cancelOrderChangeWorkflowId, | ||
createOrderChangeWorkflow, | ||
} from "@medusajs/core-flows" | ||
import { IOrderModuleService, OrderChangeDTO, OrderDTO } from "@medusajs/types" | ||
import { ModuleRegistrationName } from "@medusajs/utils" | ||
import { medusaIntegrationTestRunner } from "medusa-test-utils" | ||
import { createOrderFixture, prepareDataFixtures } from "./__fixtures__" | ||
|
||
jest.setTimeout(50000) | ||
|
||
medusaIntegrationTestRunner({ | ||
env: { MEDUSA_FF_MEDUSA_V2: true }, | ||
testSuite: ({ getContainer }) => { | ||
let container | ||
|
||
beforeAll(() => { | ||
container = getContainer() | ||
}) | ||
|
||
describe("Order change workflows", () => { | ||
let order: OrderDTO | ||
let service: IOrderModuleService | ||
|
||
describe("createOrderChangeWorkflow", () => { | ||
beforeEach(async () => { | ||
const fixtures = await prepareDataFixtures({ | ||
container, | ||
}) | ||
|
||
order = await createOrderFixture({ | ||
container, | ||
product: fixtures.product, | ||
location: fixtures.location, | ||
inventoryItem: fixtures.inventoryItem, | ||
}) | ||
}) | ||
|
||
it("should successfully create an order change", async () => { | ||
const { result } = await createOrderChangeWorkflow(container).run({ | ||
input: { | ||
order_id: order.id, | ||
}, | ||
}) | ||
|
||
expect(result).toEqual( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
order_id: order.id, | ||
}) | ||
) | ||
}) | ||
|
||
it("should throw an error when creating an order change when an active one already exists", async () => { | ||
await createOrderChangeWorkflow(container).run({ | ||
input: { | ||
order_id: order.id, | ||
}, | ||
}) | ||
|
||
const { | ||
errors: [error], | ||
} = await createOrderChangeWorkflow(container).run({ | ||
input: { | ||
order_id: order.id, | ||
}, | ||
throwOnError: false, | ||
}) | ||
|
||
expect(error.error).toEqual( | ||
expect.objectContaining({ | ||
message: `Order (${order.id}) already has an existing active order change`, | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
describe("cancelOrderChangeWorkflow", () => { | ||
let orderChange: OrderChangeDTO | ||
|
||
beforeEach(async () => { | ||
const fixtures = await prepareDataFixtures({ | ||
container, | ||
}) | ||
|
||
order = await createOrderFixture({ | ||
container, | ||
product: fixtures.product, | ||
location: fixtures.location, | ||
inventoryItem: fixtures.inventoryItem, | ||
}) | ||
|
||
const { result } = await createOrderChangeWorkflow(container).run({ | ||
input: { order_id: order.id }, | ||
}) | ||
|
||
orderChange = result | ||
service = container.resolve(ModuleRegistrationName.ORDER) | ||
}) | ||
|
||
it("should successfully cancel an order change", async () => { | ||
await cancelOrderChangeWorkflow(container).run({ | ||
input: { | ||
id: orderChange.id, | ||
canceled_by: "test", | ||
}, | ||
}) | ||
|
||
const orderChange2 = await service.retrieveOrderChange(orderChange.id) | ||
|
||
expect(orderChange2).toEqual( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
canceled_by: "test", | ||
canceled_at: expect.any(Date), | ||
}) | ||
) | ||
}) | ||
|
||
it("should throw an error when creating an order change when an active one already exists", async () => { | ||
const workflow = cancelOrderChangeWorkflow(container) | ||
|
||
workflow.appendAction("throw", cancelOrderChangeWorkflowId, { | ||
invoke: async function failStep() { | ||
throw new Error(`Fail`) | ||
}, | ||
}) | ||
|
||
const { | ||
errors: [error], | ||
} = await workflow.run({ | ||
input: { | ||
id: orderChange.id, | ||
canceled_by: "test", | ||
}, | ||
throwOnError: false, | ||
}) | ||
|
||
expect(error.error).toEqual( | ||
expect.objectContaining({ | ||
message: `Fail`, | ||
}) | ||
) | ||
|
||
const orderChange2 = await service.retrieveOrderChange(orderChange.id) | ||
|
||
expect(orderChange2).toEqual( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
canceled_by: null, | ||
canceled_at: null, | ||
}) | ||
) | ||
}) | ||
}) | ||
}) | ||
}, | ||
}) |
38 changes: 38 additions & 0 deletions
38
packages/core/core-flows/src/order/steps/cancel-order-change.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { CancelOrderChangeDTO, IOrderModuleService } from "@medusajs/types" | ||
import { ModuleRegistrationName } from "@medusajs/utils" | ||
import { createStep, StepResponse } from "@medusajs/workflows-sdk" | ||
|
||
export const cancelOrderChangeStepId = "cancel-order-change" | ||
export const cancelOrderChangeStep = createStep( | ||
cancelOrderChangeStepId, | ||
async (data: CancelOrderChangeDTO, { container }) => { | ||
const service = container.resolve<IOrderModuleService>( | ||
ModuleRegistrationName.ORDER | ||
) | ||
|
||
const dataBeforeUpdate = await service.retrieveOrderChange(data.id, { | ||
select: ["status", "metadata"], | ||
}) | ||
|
||
await service.cancelOrderChange(data) | ||
|
||
return new StepResponse(void 0, { | ||
id: data.id, | ||
status: dataBeforeUpdate.status, | ||
canceled_at: null, | ||
canceled_by: null, | ||
metadata: dataBeforeUpdate.metadata, | ||
}) | ||
}, | ||
async (rollbackData, { container }) => { | ||
if (!rollbackData) { | ||
return | ||
} | ||
|
||
const service = container.resolve<IOrderModuleService>( | ||
ModuleRegistrationName.ORDER | ||
) | ||
|
||
await service.updateOrderChanges(rollbackData) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/core/core-flows/src/order/workflows/cancel-order-change.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CancelOrderChangeDTO } from "@medusajs/types" | ||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk" | ||
import { cancelOrderChangeStep } from "../steps" | ||
|
||
export const cancelOrderChangeWorkflowId = "cancel-order-change" | ||
export const cancelOrderChangeWorkflow = createWorkflow( | ||
cancelOrderChangeWorkflowId, | ||
(input: WorkflowData<CancelOrderChangeDTO>): WorkflowData<void> => { | ||
cancelOrderChangeStep(input) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the metadata here?
that probably won't be touched if we only update the other fields no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, made it dynamic based on inputs