Skip to content

Commit

Permalink
Order: update
Browse files Browse the repository at this point in the history
see #5
  • Loading branch information
maxkoryukov committed Feb 12, 2017
1 parent 9e1c150 commit a182fba
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/resources/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<jsonschema:Orders.Order>} [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
50 changes: 50 additions & 0 deletions test/resources/orders.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit a182fba

Please sign in to comment.