diff --git a/src/resources/orders.js b/src/resources/orders.js index 9f4d98f..7334981 100644 --- a/src/resources/orders.js +++ b/src/resources/orders.js @@ -178,6 +178,34 @@ class Orders { validationContext: utils.CustomInternalPostProcessing.fromJsonWithStatus, }, callback) } + + /** + * Update an Order + * + * @see {@link https://route4me.io/docs/#update-an-order} + * @category Orders + * @since 0.1.11 + * + * @param {number} id - Order ID + * @param {jsonschema:Orders.Order} data - Order data + * @param {module:route4me-node~RequestCallback} [callback] + */ + update(id, data, callback) { + const qs = { + "redirect": 0, + } + const body = utils.clone(data) + body["order_id"] = Number(id) + + return this.r._makeRequest({ + method: "PUT", + path: "/api.v4/order.php", + qs, + body, + validationContext: "Orders.Order", + }, callback) + } + } module.exports = Orders diff --git a/test/resources/orders.spec.js b/test/resources/orders.spec.js index 94eb665..db77d4f 100644 --- a/test/resources/orders.spec.js +++ b/test/resources/orders.spec.js @@ -175,6 +175,56 @@ describe(helper.toSuiteName(__filename), () => { }) }) + describe("update", () => { + beforeEach(() => { + saMock.put("*", (r) => { + req = r + req.method = "PUT" + return { body: { } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderId = "7205711" + const data = { + "order_id": "34", + "address_2": "Lviv", + "EXT_FIELD_custom_data": [ + { + "customer_no": 11 + } + ], + "EXT_FIELD_phone": "032268593" + } + + it("should call route4me", (done) => { + resource.update(orderId, data, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "PUT", "https://route4me.com/api.v4/order.php", { + "redirect": "0", + }, { + "order_id": 7205711, + "address_2": "Lviv", + "EXT_FIELD_custom_data": [ + { + "customer_no": 11 + } + ], + "EXT_FIELD_phone": "032268593" + } + ) + + done() + }) + }) + }) + describe("remove", () => { beforeEach(() => { saMock.del("*", (r) => {