Skip to content
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(order): add support for setPurchaseOrderNumber order update action #221

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/green-brooms-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/commercetools-mock": minor
---

add support for "setPurchaseOrderNumber" order update action
9 changes: 9 additions & 0 deletions src/repositories/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
OrderSetDeliveryCustomFieldAction,
OrderSetLocaleAction,
OrderSetOrderNumberAction,
OrderSetPurchaseOrderNumberAction,
OrderSetShippingAddressAction,
OrderSetStoreAction,
OrderTransitionStateAction,
Expand Down Expand Up @@ -227,6 +228,14 @@ export class OrderUpdateHandler
resource.orderNumber = orderNumber;
}

setPurchaseOrderNumber(
context: RepositoryContext,
resource: Writable<Order>,
{ purchaseOrderNumber }: OrderSetPurchaseOrderNumberAction,
) {
resource.purchaseOrderNumber = purchaseOrderNumber;
}

setShippingAddress(
context: RepositoryContext,
resource: Writable<Order>,
Expand Down
16 changes: 16 additions & 0 deletions src/services/order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ describe("Order Update Actions", () => {
expect(response.body.orderNumber).toBe("5000123");
});

test("setPurchaseOrderNumber", async () => {
assert(order, "order not created");

const response = await supertest(ctMock.app)
.post(`/dummy/orders/${order.id}`)
.send({
version: 1,
actions: [
{ action: "setPurchaseOrderNumber", purchaseOrderNumber: "abc123" },
],
});
expect(response.status).toBe(200);
expect(response.body.version).toBe(2);
expect(response.body.purchaseOrderNumber).toBe("abc123");
});

test("changeOrderState", async () => {
assert(order, "order not created");

Expand Down