diff --git a/book/en/SUMMARY.md b/book/en/SUMMARY.md index 985a7d6..3c034c7 100644 --- a/book/en/SUMMARY.md +++ b/book/en/SUMMARY.md @@ -40,8 +40,9 @@ * [AddressBookV5](code/AddressBookV5.md) * [AutomaticTerritories](code/AutomaticTerritories.md) - * [Schedules](code/Schedules.md) + * [OrdersV5](code/OrdersV5.md) * [PodWorkflow](code/PodWorkflow.md) + * [Schedules](code/Schedules.md) * [TeamManagement](code/TeamManagement.md) * [VehiclesV5](code/VehiclesV5.md) diff --git a/book/en/code/Orders.md b/book/en/code/Orders.md index aa9a167..47a12cd 100644 --- a/book/en/code/Orders.md +++ b/book/en/code/Orders.md @@ -79,56 +79,56 @@ Create an Order ### orders.get(id, [callback]) -Get an Order Details +Get an Order Details by ID or by UUID **See**: [https://route4me.io/docs/#get-an-order-details](https://route4me.io/docs/#get-an-order-details) -**Since**: 0.1.11 +**Since**: 1.1.0 | Param | Type | Description | | --- | --- | --- | -| id | number | Order ID | +| id | number \| string | Order ID as number or order UUID as HEX-string | | [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Order> | | ### orders.list([ids], [callback]) -Get all the orders created under the specific Route4Me account +Get all the orders created under the specific Route4Me account by IDs or by UUIDs **See**: [https://route4me.io/docs/#get-orders-with-details](https://route4me.io/docs/#get-orders-with-details) -**Since**: 0.1.11 +**Since**: 1.1.0 | Param | Type | Description | | --- | --- | --- | -| [ids] | number \| string \| Array.<number> \| Array.<string> | Order IDs in one of the following form: * CSV-string * one ID as string * one ID as number * array of strings * array of numbers If you want to load all Orders: * **Don't pass** this parameter * **OR** pass `ids=undefined` * **OR** pass `ids=false` | +| [ids] | number \| string \| Array.<number> \| Array.<string> | Order IDs or order UUIDs in one of the following form: * one UUID as HEX-string * UUIDs as CSV-HEX-string * UUIDs as array of HEX-strings * one ID as number * IDs as array of numbers If you want to load all Orders: * **Don't pass** this parameter * **OR** pass `ids=undefined` * **OR** pass `ids=false` | | [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Orders> | [callback] | ### orders.remove(ids, [callback]) -Remove an Order +Remove Orders by ID or by UUID **See**: [https://route4me.io/docs/#remove-an-order](https://route4me.io/docs/#remove-an-order) -**Since**: 0.1.11 +**Since**: 1.1.0 | Param | Type | Description | | --- | --- | --- | -| ids | number \| string \| Array.<number> \| Array.<string> | Order ID/IDs to remove in one of the following form: * CSV-string * one ID as string * one ID as number * array of strings * array of numbers | +| ids | number \| string \| Array.<number> \| Array.<string> | Order IDs or order UUIDs in one of the following form: * one UUID as HEX-string * UUIDs as CSV-HEX-string * UUIDs as array of HEX-strings * one ID as number * IDs as array of numbers | | [callback] | module:route4me-node~RequestCallback | | ### orders.update(id, data, [callback]) -Update an Order +Update an Order by ID or by UUID **See**: [https://route4me.io/docs/#update-an-order](https://route4me.io/docs/#update-an-order) -**Since**: 0.1.11 +**Since**: 1.1.0 | Param | Type | Description | | --- | --- | --- | -| id | number | Order ID | +| id | number \| string | Order ID as number or order UUID as HEX-string | | data | jsonschema:Orders.Order | Order data | | [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Order> | | diff --git a/book/en/code/OrdersV5.md b/book/en/code/OrdersV5.md new file mode 100644 index 0000000..0591a17 --- /dev/null +++ b/book/en/code/OrdersV5.md @@ -0,0 +1,402 @@ + + +## OrdersV5 ℗ + +Orders facility + +**Category**: OrdersV5 +**Access**: private +**See**: [https://route4me.io/docs/#orders](https://route4me.io/docs/#orders) +**Since**: 1.1.0 + +* [OrdersV5](#OrdersV5) ℗ + * [new OrdersV5(requestManager)](#new_OrdersV5_new) + * [.create(data, [callback])](#OrdersV5+create) + * [.get(id, [callback])](#OrdersV5+get) + * [.update(id, data, [callback])](#OrdersV5+update) + * [.remove(id, [callback])](#OrdersV5+remove) + * [.search(data, [callback])](#OrdersV5+search) + * [.batchUpdateByFilters(params, [callback])](#OrdersV5+batchUpdateByFilters) + * [.batchRemove(orderIds, [callback])](#OrdersV5+batchRemove) + * [.batchUpdate(orderIds, data, [callback])](#OrdersV5+batchUpdate) + * [.batchCreate(orders, [callback])](#OrdersV5+batchCreate) + * [.getOrderCustomFields([callback])](#OrdersV5+getOrderCustomFields) + * [.createOrderCustomField(data, [callback])](#OrdersV5+createOrderCustomField) + * [.updateOrderCustomField(uuid, data, [callback])](#OrdersV5+updateOrderCustomField) + * [.removeOrderCustomField(uuid, [callback])](#OrdersV5+removeOrderCustomField) + + + +### new OrdersV5(requestManager) + +Constructor + +**Returns**: Orders - - Orders facility + +| Param | Type | Description | +| --- | --- | --- | +| requestManager | RequestManager | Request Manager | + + + +### ordersV5.create(data, [callback]) + +Create single order + +**See**: [https://route4me.io/docs/#create-an-order](https://route4me.io/docs/#create-an-order) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| data | Object | Parameters of order to create | +| [data.member_id] | Number | Order owner ID. | +| [data.address_1] | String | The order Address line 1. | +| [data.address_2] | String | The order Address line 2. | +| [data.address_alias] | String | Address alias. | +| [data.address_city] | String | The city the address is located in. | +| [data.address_state] | String | The state the address is located in. | +| [data.address_zip] | String | The zip code the address is located in. | +| [data.address_country] | String | The country the address is located in. | +| data.address_geo | Object | GPS coords of address. | +| [data.address_geo.lat] | Number | Latitude. | +| [data.address_geo.lng] | Number | Longitude. | +| data.curbside_geo | Object | Curbside GPS coords of address. | +| [data.curbside_geo.lat] | Number | Curbside latitude. | +| [data.curbside_geo.lng] | Number | Curbside longitude. | +| [data.date_scheduled_for] | String | Date scheduled. Possible formats: YY-MM-DD, YYMMDD, ISO 8601 | +| [data.order_status_id] | Number | Order status ID. | +| [data.is_pending] | Boolean | If true, the order is pending. | +| [data.is_accepted] | Boolean | If true, the order is accepted. | +| [data.is_started] | Boolean | If true, the order is started. | +| [data.is_completed] | Boolean | If true, the order is completed. | +| [data.is_validated] | Boolean | If true, the order is validated. | +| [data.phone] | String | The phone number. | +| [data.first_name] | String | The first name. | +| [data.last_name] | String | The last name. | +| [data.email] | String | E-mail. | +| [data.custom_data] | Object | Order custom data. | +| [data.custom_data.barcode] | String | Tracking number for order. | +| [data.custom_data.airbillno] | String | Additional tracking number for order. | +| [data.custom_data.sorted_on_date] | String | Datetime String with "T" delimiter, ISO 8601. | +| [data.custom_data.sorted_on_utc] | Number | Timestamp only; replaced data in `sorted_on_date` property. | +| data.local_time_windows | Array.<Object> | Array of Time Window objects. | +| data.local_time_windows.start | Number | Start of Time Window, unix timestamp. | +| data.local_time_windows.end | Number | End of Time Window, unix timestamp. | +| [data.local_timezone_string] | String | Local timezone String | +| [data.service_time] | Number | Consumed service time. | +| [data.color] | String | Color of an address, e.g., 'FF0000'. | +| [data.tracking_number] | String | Tracking number | +| [data.address_stop_type] | String | The type of stop that this is one of 'DELIVERY', 'PICKUP', 'BREAK', 'MEETUP', 'SERVICE', 'VISIT' or 'DRIVEBY'. | +| [data.last_status] | Number | | +| [data.weight] | Number | Weight of the cargo. | +| [data.cost] | Number | Cost of the cargo. | +| [data.revenue] | Number | The total revenue for the order. | +| [data.cube] | Number | The cubic volume of the cargo. | +| [data.pieces] | Number | The item quantity of the cargo. | +| [data.group] | String | The group. | +| data.address_priority | Number | Priority of address 0 is the highest priority, n has higher priority than n + 1 | +| data.address_customer_po | String | The customer purchase order for the address, length <= 50. | +| data.custom_fields | Array.<Object> | Array of Custom Fields objects. | +| data.custom_fields.order_custom_field_uuid | String | HEX-String. | +| data.custom_fields.order_custom_field_value | String | Value of Custom Fields. | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Order> | | + +**Example** *(Sample input)* +```javascript + + const data = { + "address_1": "1358 E Luzerne St, Philadelphia, PA 19124, US", + "address_alias": "Auto test address", + "address_city": "Philadelphia", + "address_geo": { + "lat": "48.335991", + "lng": "31.18287", + }, + "phone": "380380380380", + "first_name": "Igor", + "last_name": "Progman", + "email": "progman@gmail.com", + "custom_data": { + "barcode": "12345678901", + "sorted_on_utc": "1702744115" + } + }; +``` + + +### ordersV5.get(id, [callback]) + +Show single order by its id + +**See**: [https://route4me.io/docs/#get-an-order-details](https://route4me.io/docs/#get-an-order-details) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| id | String | Order ID, HEX-String | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Order> | | + + + +### ordersV5.update(id, data, [callback]) + +Update single order by its id + +**See**: [https://route4me.io/docs/#update-an-order](https://route4me.io/docs/#update-an-order) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| id | String | Order ID, HEX-String | +| data | Object | Parameters of order to update, look for more information in create() | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Order> | | + +**Example** *(Sample input)* +```javascript + +const id = "CCCCCA90F77841C693C656123F346AAA"; +const data = { + "first_name": "John", + "last_name": "Doe", + "email": "John@company.com", +}; +``` + + +### ordersV5.remove(id, [callback]) + +Delete (soft) single order by its id + +**See**: [https://route4me.io/docs/#remove-an-order](https://route4me.io/docs/#remove-an-order) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| id | String | Order ID, HEX-String | +| [callback] | module:route4me-node~RequestCallback | | + + + +### ordersV5.search(data, [callback]) + +Search orders in ElasticSearch storage or in Spanner database + +**See**: [https://route4me.io/docs/#search-orders](https://route4me.io/docs/#search-orders) +**Since**: 1.1.0 + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| data | Object | | Search and filter parameters. | +| [data.order_ids] | Array.<String> | | Array of order ids, HEX-Strings. | +| data.return_provided_fields_as_map | Boolean | | | +| data.orderBy | Array.<Object> | | Sort and direction parameters. | +| orderBy.0 | String | | The name of the sort field, this is one of 'address_alias', 'first_name', 'last_name', 'phone', 'is_pending', 'is_validated', 'is_accepted', 'is_completed', 'scheduled_for', 'day_added' | +| [orderBy.1] | String | 'asc' | Sorting direction, this is one of 'asc', 'ASC', 'desc', 'DESC' | +| data.limit | Number | | = 30 - The number of orders per page. | +| data.offset | Number | | = 0 - The requested page. | +| data.fields | Array.<String> | | An array of returned fields, this is one of 'order_uuid', 'member_id', 'address_1', 'address_2', 'address_alias', 'address_city', 'address_state', 'address_zip', 'address_country', 'coordinates', 'curbside_coordinates', 'updated_timestamp', 'created_timestamp', 'day_added', 'scheduled_for', 'order_status_id', 'is_pending', 'is_started', 'is_completed', 'is_validated', 'phone', 'first_name', 'last_name', 'email', 'custom_data', 'local_time_windows', 'local_timezone', 'service_time', 'color', 'icon', 'last_visited_timestamp', 'visited_count', 'in_route_count', 'last_routed_timestamp', 'tracking_number', 'organization_id', 'root_member_id', 'address_stop_type', 'last_status', 'sorted_day_id', 'weight', 'cost', 'revenue', 'cube', 'pieces', 'done_day_id', 'possession_day_id', 'group', 'workflow_uuid', 'address_priority' | +| data.addition | Array.<String> | | An array of additional returned fields, this is one of 'territory_ids', 'aggregation_ids' | +| [data.search] | Object | | Search parameters. | +| [data.search.query] | String | | The string to query to ElasticSearch. If set the `matches` and `terms` sections will be ignored. | +| [data.search.matches] | Object | | The object to query to ElasticSearch. | +| [data.search.matches.custom_data] | Object | | Order custom data. | +| [data.search.matches.custom_data.barcode] | String | | Tracking number for order. | +| [data.search.matches.custom_data.airbillno] | String | | Additional tracking number for order. | +| [data.search.matches.custom_data.sorted_on_date] | String | | Datetime String with "T" delimiter, ISO 8601. | +| [data.search.matches.custom_data.sorted_on_utc] | Number | | Timestamp only; replaced data in `sorted_on_date` property. | +| [data.search.matches.first_name] | String | | The first name. | +| [data.search.matches.last_name] | String | | The last name. | +| [data.search.matches.email] | String | | E-mail. | +| [data.search.matches.phone] | String | | The phone number. | +| [data.search.matches.address_1] | String | | The order Address line 1. | +| [data.search.matches.address_alias] | String | | Address alias. | +| [data.search.matches.address_zip] | String | | The zip code of the address. | +| [data.search.terms] | Object | | The object to query to ElasticSearch. | +| [data.search.terms.custom_data] | Object | | Order custom data. | +| [data.search.terms.custom_data.barcode] | String | | Tracking number for order. | +| [data.search.terms.custom_data.airbillno] | String | | Additional tracking number for order. | +| [data.search.terms.custom_data.sorted_on_date] | String | | Datetime String with "T" delimiter, ISO 8601. | +| [data.search.terms.custom_data.sorted_on_utc] | Number | | Timestamp only; replaced data in `sorted_on_date` property. | +| [data.search.terms.first_name] | String | | The first name. | +| [data.search.terms.last_name] | String | | The last name. | +| [data.search.terms.email] | String | | E-mail. | +| [data.search.terms.phone] | String | | The phone number. | +| [data.search.terms.address_1] | String | | The order Address line 1. | +| [data.search.terms.address_alias] | String | | Address alias. | +| [data.search.terms.address_zip] | String | | The zip code the address is located in. | +| [data.filters] | Object | | Filter parameters. | +| [data.filters.order_ids] | Array.<String> | | Array of included order ids, HEX-Strings. | +| [data.filters.excluded_ids] | Array.<String> | | Array of excluded order ids, HEX-Strings. | +| [data.filters.tracking_numbers] | Array.<String> | | Array of tracking number of orders. | +| [data.filters.only_geocoded] | Boolean | | | +| [data.filters.updated_timestamp] | Number \| String \| Object | | Can be unix timestamp or ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. | +| [data.filters.created_timestamp] | Number \| String \| Object | | Can be unix timestamp or ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. | +| [data.filters.scheduled_for] | Number \| String \| Object | | Can be unix timestamp or ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. | +| [data.filters.only_unscheduled] | Boolean | | | +| [data.filters.day_added] | Number \| String \| Object | | Can be unix timestamp or ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. | +| [data.filters.sorted_on] | Number \| String \| Object | | Can be unix timestamp or ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. | +| [data.filters.address_stop_types] | Array.<String> | | Array of stop type names, possible values 'DELIVERY', 'PICKUP', 'BREAK', 'MEETUP', 'SERVICE', 'VISIT' or 'DRIVEBY'. | +| [data.filters.last_statuses] | Array.<Number> | | Array of statuses. | +| [data.filters.territory_ids] | Array.<Number> | | Array of territory ids. | +| [data.filters.done_day] | String | | | +| [data.filters.possession_day] | String | | | +| [data.filters.groups] | Array.<String> | | | +| [data.filters.display] | String | 'all' | Filtering by the in_route_count field, is one of 'routed', 'unrouted', 'all' | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.List> | | | + +**Example** *(Sample input)* +```javascript + + const data = { + filters: { + order_ids: [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + } + }; +``` + + +### ordersV5.batchUpdateByFilters(params, [callback]) + +Update the batch of orders (asynchronous, by filters) + +**See**: [https://route4me.io/docs/#update-an-order](https://route4me.io/docs/#update-an-order) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| params | Object | Batch update parameters. | +| params.data | Object | Order values for batch update, look for more information in create() | +| params.search | Object | Search parameters for batch update, look for more information in search() | +| params.filters | Object | Filter parameters for batch update, look for more information in search() | +| [callback] | module:route4me-node~RequestCallback | | + + + +### ordersV5.batchRemove(orderIds, [callback]) + +Delete the batch of orders + +**See**: [https://route4me.io/docs/#remove-an-order](https://route4me.io/docs/#remove-an-order) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| orderIds | Array.<String> | Array of Order IDs, HEX-Strings. | +| [callback] | module:route4me-node~RequestCallback | | + + + +### ordersV5.batchUpdate(orderIds, data, [callback]) + +Update the batch of orders by ids + +**See**: [https://route4me.io/docs/#update-an-order](https://route4me.io/docs/#update-an-order) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| orderIds | Array.<String> | Array of Order IDs, HEX-Strings. | +| data | Object | Order values for batch update, look for more information in create() | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.List> | | + + + +### ordersV5.batchCreate(orders, [callback]) + +Create the batch of orders + +**See**: [https://route4me.io/docs/#update-an-order](https://route4me.io/docs/#update-an-order) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| orders | Array.<Object> | Array of Order values for batch create, look for more information in create() | +| [callback] | module:route4me-node~RequestCallback | | + + + +### ordersV5.getOrderCustomFields([callback]) + +Get a list of Order Custom Fields + +**See**: [https://route4me.io/docs/#get-an-order-details](https://route4me.io/docs/#get-an-order-details) +**Since**: 1.1.0 + +| Param | Type | +| --- | --- | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Response> | + + + +### ordersV5.createOrderCustomField(data, [callback]) + +Create one Order Custom Field + +**See**: [https://route4me.io/docs/#create-an-order-custom-fields](https://route4me.io/docs/#create-an-order-custom-fields) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| data | Object | Params of Order custom field | +| data.order_custom_field_name | String | Name, max 128 characters. | +| data.order_custom_field_type | String | Type, max 128 characters. | +| data.order_custom_field_label | String | Label, max 128 characters. | +| data.order_custom_field_type_info | Object | Info, as JSON Object max 4096 characters. | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Response> | | + +**Example** *(Sample input)* +```javascript + + const orderTypeCheckbox = { + order_custom_field_name: "CustomField4", + order_custom_field_label: "Custom Field 4", + order_custom_field_type: "checkbox", + order_custom_field_type_info: { short_label: "cFl4" } + } + + const = orderTypeDropdown = { + order_custom_field_name: "TEST", + order_custom_field_label: "MENU", + order_custom_field_type: "dropdown", + order_custom_field_short_caption: "MENU", + order_custom_field_type_info: { + short_caption: "MENU", + allowed_values: ["10", "30", "50", “100”] + } + } +``` + + +### ordersV5.updateOrderCustomField(uuid, data, [callback]) + +Update one Order Custom Fields + +**See**: [https://route4me.io/docs/#update-an-order-custom-fields](https://route4me.io/docs/#update-an-order-custom-fields) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| uuid | Number | OrderCustomField ID, HEX-string. | +| data | Object | Params of Order custom field | +| data.order_custom_field_type | String | Type, max 128 characters. | +| data.order_custom_field_label | String | Label, max 128 characters. | +| data.order_custom_field_type_info | Object | Info, as JSON Object max 4096 characters. | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Response> | | + + + +### ordersV5.removeOrderCustomField(uuid, [callback]) + +Remove an Order Custom Fields + +**See**: [https://route4me.io/docs/#remove-user-custom-field](https://route4me.io/docs/#remove-user-custom-field) +**Since**: 1.1.0 + +| Param | Type | Description | +| --- | --- | --- | +| uuid | Number | OrderCustomField ID, HEX-string. | +| [callback] | module:route4me-node~RequestCallback.<jsonschema:Orders.Response> | | + diff --git a/book/en/code/Route4Me.md b/book/en/code/Route4Me.md index 5ff07c9..dfe6c95 100644 --- a/book/en/code/Route4Me.md +++ b/book/en/code/Route4Me.md @@ -96,6 +96,7 @@ Main members of the instanse of `Route4Me` class: * [Notes ](Notes) * [Optimizations ](Optimizations) * [Orders ](Orders) +* [OrdersV5 ](OrdersV5) * [OrderCustomFields ](OrderCustomFields) * [PodWorkflow ](PodWorkflow) * [Routes ](Routes) @@ -140,6 +141,7 @@ For most use cases it is necessary: * [.Notes](#Route4Me+Notes) : Notes * [.Optimizations](#Route4Me+Optimizations) : Optimizations * [.Orders](#Route4Me+Orders) : Orders + * [.OrdersV5](#Route4Me+OrdersV5) : OrdersV5 * [.PodWorkflow](#Route4Me+PodWorkflow) : PodWorkflow * [.Routes](#Route4Me+Routes) : Routes * [.Schedules](#Route4Me+Schedules) : Schedules @@ -248,6 +250,13 @@ Create new API client **Orders** related API calls **Since**: 0.1.11 + + +### route4Me.OrdersV5 : OrdersV5 + +**OrdersV5** related API calls + +**Since**: 1.1.0 ### route4Me.PodWorkflow : PodWorkflow diff --git a/examples/Orders/get-order-by-uuid-promise.js b/examples/Orders/get-order-by-uuid-promise.js new file mode 100644 index 0000000..934b06c --- /dev/null +++ b/examples/Orders/get-order-by-uuid-promise.js @@ -0,0 +1,88 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + + // To use the Promise style instead of the Callback style send promise=true as an option. + const route4me = new Route4Me(apiKey, { promise: true }) + + const data = { + address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US", + address_alias: "Auto test address", + address_city: "Philadelphia", + EXT_FIELD_first_name: "John", + EXT_FIELD_last_name: "Doe", + EXT_FIELD_email: "some@company.com", + EXT_FIELD_phone: "380380380380" + }; + + let order_uuid = undefined; + let order_by_id = undefined; + + // create Order + route4me.Orders.create(data) + .then(data => { + expect(data).exist + + const order_id = data.order_id; + order_uuid = data.order_uuid; + console.log(`Create Order with id='${order_id}' and uuid='${order_uuid}'`); + + // get Order by ID + return route4me.Orders.get(order_id) + }).then(data => { + order_by_id = data; + console.log(`Read Order by id, id='${order_by_id.order_id}' and uuid='${order_by_id.order_uuid}`); + + // get Order by UUID + return route4me.Orders.get(order_uuid) + }).then(order_by_uuid => { + console.log(`Read Order by uuid, id='${order_by_uuid.order_id}' and uuid='${order_by_uuid.order_uuid}`); + + // compare Orders + if(JSON.stringify(order_by_id) == JSON.stringify(order_by_uuid)) { + console.log("The Orders are equal."); + } else { + console.log("The Orders are not equal."); + } + + // delete Order by UUID + return route4me.Orders.remove(order_uuid) + }).then(data => { + if(data) { + console.log(`Order with uuid=${order_uuid} was deleted successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not deleted.`); + } + }).catch(err => { + expect(err).exist + // console.log("Error ", err); + + if(order_uuid) { + route4me.Orders.remove(order_uuid) + .then(data => { + if(data) { + console.log(`Order with uuid=${order_uuid} was cleaned up successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not cleaned up.`); + } + }).catch(err => { + console.log("Error: cleanup, " + err); + }); + } + }); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/Orders/get-order-by-uuid-sync.js b/examples/Orders/get-order-by-uuid-sync.js new file mode 100644 index 0000000..b7894ea --- /dev/null +++ b/examples/Orders/get-order-by-uuid-sync.js @@ -0,0 +1,85 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + + // To use the Promise style instead of the Callback style send promise=true as an option. + const route4me = new Route4Me(apiKey, { promise: true }); + + (async () => { + const data = { + address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US", + address_alias: "Auto test address", + address_city: "Philadelphia", + EXT_FIELD_first_name: "John", + EXT_FIELD_last_name: "Doe", + EXT_FIELD_email: "some@company.com", + EXT_FIELD_phone: "380380380380" + }; + + let order_uuid = undefined; + + try { + // create Order + const order = await route4me.Orders.create(data); + expect(order).exist + + const order_id = order.order_id; + order_uuid = order.order_uuid; + console.log(`Create Order with id='${order_id}' and uuid='${order_uuid}'`); + + // get Order by ID + const order_by_id = await route4me.Orders.get(order_id); + console.log(`Read Order by id, id='${order_by_id.order_id}' and uuid='${order_by_id.order_uuid}`); + + // get Order by UUID + const order_by_uuid = await route4me.Orders.get(order_uuid); + console.log(`Read Order by uuid, id='${order_by_uuid.order_id}' and uuid='${order_by_uuid.order_uuid}`); + + // compare Orders + if(JSON.stringify(order_by_id) == JSON.stringify(order_by_uuid)) { + console.log("The Orders are equal."); + } else { + console.log("The Orders are not equal."); + } + + // delete Order by UUID + if(await route4me.Orders.remove(order_uuid)) { + console.log(`Order with uuid=${order_uuid} was deleted successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not deleted.`); + } + } + catch(err) { + expect(err).exist + // console.log("Error ", err); + + if(order_uuid) { + try { + if(await route4me.Orders.remove(order_uuid)) { + console.log(`Order with uuid=${order_uuid} was cleaned up successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not cleaned up.`); + } + } + catch(err) { + console.log("Error: cleanup, " + err); + } + } + } + })(); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/Orders/get-order-by-uuid.js b/examples/Orders/get-order-by-uuid.js new file mode 100644 index 0000000..f743ae9 --- /dev/null +++ b/examples/Orders/get-order-by-uuid.js @@ -0,0 +1,103 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + const route4me = new Route4Me(apiKey) + + function cleanup(err, cleanup_uuid) { + debug("error ", err) + expect(err).exist + + if(cleanup_uuid) { + route4me.Orders.remove(cleanup_uuid, (err, data) => { + if(err) { + console.log("Error: cleanup, " + err); + return; + } + if(data) { + console.log(`Order with uuid=${cleanup_uuid} was cleaned up successful.`); + } else { + console.log(`Order with uuid=${cleanup_uuid} was not cleaned up.`); + } + }); + } + } + + const data = { + address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US", + address_alias: "Auto test address", + address_city: "Philadelphia", + EXT_FIELD_first_name: "John", + EXT_FIELD_last_name: "Doe", + EXT_FIELD_email: "some@company.com", + EXT_FIELD_phone: "380380380380" + }; + + // create order + route4me.Orders.create(data, (err, data) => { + debug("error ", err) + expect(err).is.null + expect(res).exist + + if(err) { + cleanup(err); + return; + } + + const order_id = data.order_id; + const order_uuid = data.order_uuid; + console.log(`Create Order with id='${order_id}' and uuid='${order_uuid}'`); + + // get Order by ID + route4me.Orders.get(order_id, (err, order_by_id) => { + if(err) { + cleanup(err, order_by_id.order_id); + return; + } + console.log(`Read Order by id, id='${order_by_id.order_id}' and uuid='${order_by_id.order_uuid}`); + + // get Order by UUID + route4me.Orders.get(order_uuid, (err, order_by_uuid) => { + if(err) { + cleanup(err, order_by_uuid.order_id); + return; + } + console.log(`Read Order by uuid, id='${order_by_uuid.order_id}' and uuid='${order_by_uuid.order_uuid}`); + + // compare Orders + if(JSON.stringify(order_by_id) == JSON.stringify(order_by_uuid)) { + console.log("The Orders are equal."); + } else { + console.log("The Orders are not equal."); + } + + // delete Order by UUID + route4me.Orders.remove(order_uuid, (err, data) => { + if(err) { + cleanup(err); + return; + } + if(data) { + console.log(`Order with uuid=${order_uuid} was deleted successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not deleted.`); + } + }); + }); + }); + }); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/OrdersV5/custom-fields-promise.js b/examples/OrdersV5/custom-fields-promise.js new file mode 100644 index 0000000..4869e8d --- /dev/null +++ b/examples/OrdersV5/custom-fields-promise.js @@ -0,0 +1,75 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + + // To use the Promise style instead of the Callback style send promise=true as an option. + const route4me = new Route4Me(apiKey, { promise: true }) + + const data = { + order_custom_field_name: "CustomField_15", + order_custom_field_label: "Custom Field 15", + order_custom_field_type: "checkbox", + order_custom_field_type_info: { short_label: "cFl_15" } + }; + + let ocf_uuid = undefined; + + // create CustomUserField + route4me.OrdersV5.createOrderCustomField(data) + .then(data => { + expect(data).exist + ocf_uuid = data.data.order_custom_field_uuid; + console.log(`Create CustomUserField with uuid='${ocf_uuid}'`); + + // read list of CustomUserFields + return route4me.OrdersV5.getOrderCustomFields(); + }).then(data => { + console.log(`Read CustomUserFields list the length is '${data.data.length}'`); + + const found_res = data.data.find(item => item.order_custom_field_uuid === ocf_uuid); + if(found_res) { + console.log(`Found CustomUserField with uuid ${ocf_uuid} label is '${found_res.order_custom_field_label}'`); + + // update CustomUserFields + const { order_custom_field_uuid, ...update_ocf } = found_res; + update_ocf.order_custom_field_label = "Custom Field 16"; + return route4me.OrdersV5.updateOrderCustomField(ocf_uuid, update_ocf); + } else { + throw new Error(`CustomUserField with uuid ${ocf_uuid} not found.'`); + } + }).then(data => { + console.log(`Update CustomUserField label is '${data.data.order_custom_field_label}'`); + + // delete CustomUserFields + return route4me.OrdersV5.removeOrderCustomField(ocf_uuid); + }).then(data => { + console.log(`CustomUserField with uuid=${ocf_uuid} was deleted successful.`); + }).catch(err => { + expect(err).exist + // console.log("Error ", err); + + if(ocf_uuid) { + route4me.OrdersV5.removeOrderCustomField(ocf_uuid) + .then(data => { + console.log(`CustomUserField with uuid=${ocf_uuid} was cleaned up successful.`); + }).catch(err => { + console.log("Error: cleanup, " + err); + }) + } + }); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/OrdersV5/custom-fields-sync.js b/examples/OrdersV5/custom-fields-sync.js new file mode 100644 index 0000000..3124bdd --- /dev/null +++ b/examples/OrdersV5/custom-fields-sync.js @@ -0,0 +1,77 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + + // To use the Promise style instead of the Callback style send promise=true as an option. + const route4me = new Route4Me(apiKey, { promise: true }); + + (async () => { + let ocf_uuid = undefined; + + const data = { + order_custom_field_name: "CustomField_15", + order_custom_field_label: "Custom Field 15", + order_custom_field_type: "checkbox", + order_custom_field_type_info: { short_label: "cFl_15" } + }; + + try { + // create CustomUserField + const custom_field = await route4me.OrdersV5.createOrderCustomField(data); + expect(custom_field).exist + + ocf_uuid = custom_field.data.order_custom_field_uuid; + console.log(`Create CustomUserField with uuid='${ocf_uuid}'`); + + // read list of CustomUserFields + const custom_fields = await route4me.OrdersV5.getOrderCustomFields(); + console.log(`Read CustomUserFields list the length is '${custom_fields.data.length}'`); + + const found_res = custom_fields.data.find(item => item.order_custom_field_uuid === ocf_uuid); + if(found_res) { + console.log(`Found CustomUserField with uuid ${ocf_uuid} label is '${found_res.order_custom_field_label}'`); + + // update CustomUserFields + const { order_custom_field_uuid, ...update_ocf } = found_res; + update_ocf.order_custom_field_label = "Custom Field 16"; + const update_field = await route4me.OrdersV5.updateOrderCustomField(ocf_uuid, update_ocf); + console.log(`Update CustomUserField label is '${update_field.data.order_custom_field_label}'`); + + // delete CustomUserFields + await route4me.OrdersV5.removeOrderCustomField(ocf_uuid); + console.log(`CustomUserField with uuid=${ocf_uuid} was deleted successful.`); + } else { + console.log(`CustomUserField with uuid ${ocf_uuid} not found.'`); + } + } + catch(err) { + expect(err).exist + // console.log("Error ", err); + + if(ocf_uuid) { + try { + await route4me.OrdersV5.removeOrderCustomField(ocf_uuid); + console.log(`CustomUserField with uuid=${ocf_uuid} was cleaned up successful.`); + } + catch(err) { + console.log("Error: cleanup, " + err); + } + } + } + })(); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/OrdersV5/custom-fields.js b/examples/OrdersV5/custom-fields.js new file mode 100644 index 0000000..33e71d5 --- /dev/null +++ b/examples/OrdersV5/custom-fields.js @@ -0,0 +1,97 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + const route4me = new Route4Me(apiKey) + + function cleanup(err, cleanup_uuid) { + debug("error ", err) + expect(err).exist + + if(cleanup_uuid) { + route4me.OrdersV5.removeOrderCustomField(cleanup_uuid, (err, data) => { + if(err) { + console.log("Error: cleanup, " + err); + return; + } + if(data) { + console.log(`CustomUserField with uuid=${cleanup_uuid} was cleaned up successful.`); + } else { + console.log(`CustomUserField with uuid=${cleanup_uuid} was not cleaned up.`); + } + }); + } + } + + const data = { + order_custom_field_name: "CustomField_15", + order_custom_field_label: "Custom Field 15", + order_custom_field_type: "checkbox", + order_custom_field_type_info: { short_label: "cFl_15" } + }; + + // create CustomUserField + route4me.OrdersV5.createOrderCustomField(data, (err, data) => { + debug("error ", err) + expect(err).is.null + expect(res).exist + + if(err) { + cleanup(err); + return; + } + + const ocf_uuid = data.data.order_custom_field_uuid; + console.log(`Create CustomUserField with uuid='${ocf_uuid}'`); + + // read list of CustomUserFields + route4me.OrdersV5.getOrderCustomFields((err, data) => { + if(err) { + cleanup(err, ocf_uuid); + return; + } + console.log(`Read CustomUserFields list the length is '${data.data.length}'`); + + const found_res = data.data.find(item => item.order_custom_field_uuid === ocf_uuid); + if(found_res) { + console.log(`Found CustomUserField with uuid ${ocf_uuid} label is '${found_res.order_custom_field_label}'`); + + // update CustomUserFields + const { order_custom_field_uuid, ...update_ocf } = found_res; + update_ocf.order_custom_field_label = "Custom Field 16"; + route4me.OrdersV5.updateOrderCustomField(ocf_uuid, update_ocf, (err, data) => { + if(err) { + cleanup(err, ocf_uuid); + return; + } + console.log(`Update CustomUserField label is '${data.data.order_custom_field_label}'`); + + // delete CustomUserFields + route4me.OrdersV5.removeOrderCustomField(ocf_uuid, (err, data) => { + if(err) { + cleanup(err); + return; + } + console.log(`CustomUserField with uuid=${ocf_uuid} was deleted successful.`); + }); + }); + } else { + console.log(`CustomUserField with uuid ${ocf_uuid} not found.'`); + } + }); + }); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/OrdersV5/full-flow-promise.js b/examples/OrdersV5/full-flow-promise.js new file mode 100644 index 0000000..4684332 --- /dev/null +++ b/examples/OrdersV5/full-flow-promise.js @@ -0,0 +1,84 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + + // To use the Promise style instead of the Callback style send promise=true as an option. + const route4me = new Route4Me(apiKey, { promise: true }) + + const data = { + address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US", + address_alias: "Auto test address", + address_city: "Philadelphia", + address_geo: { + lat: "48.335991", + lng: "31.18287", + }, + phone: "380380380380", + first_name: "John", + last_name: "Doe", + email: "some@company.com" + }; + + let order_uuid = undefined; + + // create order + route4me.OrdersV5.create(data) + .then(data => { + expect(data).exist + order_uuid = data.order_uuid; + console.log(`Create Order with uuid='${order_uuid}'`); + + // read order + return route4me.OrdersV5.get(order_uuid); + }).then(data => { + console.log(`Read Order first_name is '${data.first_name}'`); + + // update order + const order_data = { + first_name: "Jane" + }; + return route4me.OrdersV5.update(order_uuid, order_data); + }).then(data => { + console.log(`Update Order first_name is '${data.first_name}'`); + + // delete order + return route4me.OrdersV5.remove(order_uuid); + }).then(data => { + expect(data).exist + if(data) { + console.log(`Order with uuid=${order_uuid} was deleted successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not deleted.`); + } + }).catch(err => { + expect(err).exist + // console.log("Error ", err); + + if(order_uuid) { + route4me.OrdersV5.remove(order_uuid).then(data => { + if(data) { + console.log(`Order with uuid=${order_uuid} was cleaned up successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not cleaned up.`); + } + }).catch(err => { + console.log("Error: cleanup, " + err); + }); + } + }); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/OrdersV5/full-flow-sync.js b/examples/OrdersV5/full-flow-sync.js new file mode 100644 index 0000000..4a93fa5 --- /dev/null +++ b/examples/OrdersV5/full-flow-sync.js @@ -0,0 +1,84 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + + // To use the Promise style instead of the Callback style send promise=true as an option. + const route4me = new Route4Me(apiKey, { promise: true }); + + (async () => { + let order_uuid = undefined; + + const data = { + address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US", + address_alias: "Auto test address", + address_city: "Philadelphia", + address_geo: { + lat: "48.335991", + lng: "31.18287", + }, + phone: "380380380380", + first_name: "John", + last_name: "Doe", + email: "some@company.com" + }; + + try { + // create order + const order = await route4me.OrdersV5.create(data); + expect(order).exist + + order_uuid = order.order_uuid; + console.log(`Create Order with uuid='${order_uuid}'`); + + // read order + const read_order = await route4me.OrdersV5.get(order_uuid); + console.log(`Read Order first_name is '${read_order.first_name}'`); + + // update order + const order_data = { + first_name: "Jane" + }; + const update_order = await route4me.OrdersV5.update(order_uuid, order_data); + console.log(`Update Order first_name is '${update_order.first_name}'`); + + // delete order + if(await route4me.OrdersV5.remove(order_uuid)) { + console.log(`Order with uuid=${order_uuid} was deleted successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not deleted.`); + } + } + catch(err) { + expect(err).exist + // console.log("Error ", err); + + if(order_uuid) { + try { + if(await route4me.OrdersV5.remove(order_uuid)) { + console.log(`Order with uuid=${order_uuid} was cleaned up successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not cleaned up.`); + } + } + catch(err) { + console.log("Error: cleanup, " + err); + } + } + } + })(); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/examples/OrdersV5/full-flow.js b/examples/OrdersV5/full-flow.js new file mode 100644 index 0000000..74f9522 --- /dev/null +++ b/examples/OrdersV5/full-flow.js @@ -0,0 +1,102 @@ +"use strict" + +const path = require("path") +const chai = require("chai") +const debug = require("debug")("route4me-node:examples") +require("../init-examples-suite") +const helper = require("../../test/helper") + +helper.describeIntegration(helper.toSuiteName(__filename), function T() { + this.timeout(5000) + this.slow(3000) + it(path.basename(__filename), (done) => { + const expect = chai.expect + const apiKey = "11111111111111111111111111111111" + const route4me = new Route4Me(apiKey) + + function cleanup(err, cleanup_uuid) { + debug("error ", err) + expect(err).exist + + if(cleanup_uuid) { + route4me.OrdersV5.remove(cleanup_uuid, (err, data) => { + if(err) { + console.log("Error: cleanup, " + err); + return; + } + if(data) { + console.log(`Order with uuid=${cleanup_uuid} was cleaned up successful.`); + } else { + console.log(`Order with uuid=${cleanup_uuid} was not cleaned up.`); + } + }); + } + } + + const data = { + address_1: "1358 E Luzerne St, Philadelphia, PA 19124, US", + address_alias: "Auto test address", + address_city: "Philadelphia", + address_geo: { + lat: "48.335991", + lng: "31.18287", + }, + phone: "380380380380", + first_name: "John", + last_name: "Doe", + email: "some@company.com" + }; + + // create order + route4me.OrdersV5.create(data, (err, data) => { + debug("error ", err) + expect(err).is.null + expect(res).exist + + if(err) { + cleanup(err); + return; + } + + const order_uuid = data.order_uuid; + console.log(`Create Order with uuid='${order_uuid}'`); + + // read order + route4me.OrdersV5.get(order_uuid, (err, data) => { + if(err) { + cleanup(err, order_uuid); + return; + } + console.log(`Read Order first_name is '${data.first_name}'`); + + // update order + const order_data = { + first_name: "Jane" + }; + route4me.OrdersV5.update(order_uuid, order_data, (err, data) => { + if(err) { + cleanup(err, order_uuid); + return; + } + console.log(`Update Order first_name is '${data.first_name}'`); + + // delete order + route4me.OrdersV5.remove(order_uuid, (err, data) => { + if(err) { + cleanup(err); + return; + } + if(data) { + console.log(`Order with uuid=${order_uuid} was deleted successful.`); + } else { + console.log(`Order with uuid=${order_uuid} was not deleted.`); + } + }); + }); + }); + }); + + // TODO: remove `done` call from examples + done() + }) +}) diff --git a/package.json b/package.json index 108e37e..79e9c02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "route4me-nodejs-sdk", - "version": "1.0.28", + "version": "1.1.0", "description": "Access Route4Me's logistics-as-a-service API using our Node.js SDK", "main": "src/index.js", "browser": "src/route4me.js", diff --git a/src/request-manager.js b/src/request-manager.js index 1ef5752..d5c0d37 100644 --- a/src/request-manager.js +++ b/src/request-manager.js @@ -252,7 +252,7 @@ class RequestManager { if (form) { req.type("multipart/form-data") .field(form) - } else { + } else if (body) { req.type("application/json") .send(body) } diff --git a/src/resources/orders-v5.js b/src/resources/orders-v5.js new file mode 100644 index 0000000..7463f4a --- /dev/null +++ b/src/resources/orders-v5.js @@ -0,0 +1,516 @@ +"use strict" + +const utils = require("./../utils") + +/** + * Orders facility + * + * @category OrdersV5 + */ +class OrdersV5 { + /** + * Constructor + * + * @see {@link https://route4me.io/docs/#orders} + * @since 1.1.0 + * @private + * + * @param {RequestManager} requestManager - Request Manager + * @return {Orders} - Orders facility + */ + constructor(requestManager) { + this.r = requestManager + } + + /** + * Create single order + * + * @example Sample input + * + const data = { + "address_1": "1358 E Luzerne St, Philadelphia, PA 19124, US", + "address_alias": "Auto test address", + "address_city": "Philadelphia", + "address_geo": { + "lat": "48.335991", + "lng": "31.18287", + }, + "phone": "380380380380", + "first_name": "Igor", + "last_name": "Progman", + "email": "progman@gmail.com", + "custom_data": { + "barcode": "12345678901", + "sorted_on_utc": "1702744115" + } + }; + * + * @see {@link https://route4me.io/docs/#create-an-order} + * @since 1.1.0 + * + * @param {Object} data - Parameters of order to create + * @param {Number} [data.member_id] - Order owner ID. + * @param {String} [data.address_1] - The order Address line 1. + * @param {String} [data.address_2] - The order Address line 2. + * @param {String} [data.address_alias] - Address alias. + * @param {String} [data.address_city] - The city the address is located in. + * @param {String} [data.address_state] - The state the address is located in. + * @param {String} [data.address_zip] - The zip code the address is located in. + * @param {String} [data.address_country] - The country the address is located in. + * @param {Object} data.address_geo - GPS coords of address. + * @param {Number} [data.address_geo.lat] - Latitude. + * @param {Number} [data.address_geo.lng] - Longitude. + * @param {Object} data.curbside_geo - Curbside GPS coords of address. + * @param {Number} [data.curbside_geo.lat] - Curbside latitude. + * @param {Number} [data.curbside_geo.lng] - Curbside longitude. + * @param {String} [data.date_scheduled_for] - Date scheduled. + * Possible formats: YY-MM-DD, YYMMDD, ISO 8601 + * + * @param {Number} [data.order_status_id] - Order status ID. + * @param {Boolean} [data.is_pending] - If true, the order is pending. + * @param {Boolean} [data.is_accepted] - If true, the order is accepted. + * @param {Boolean} [data.is_started] - If true, the order is started. + * @param {Boolean} [data.is_completed] - If true, the order is completed. + * @param {Boolean} [data.is_validated] - If true, the order is validated. + * @param {String} [data.phone] - The phone number. + * @param {String} [data.first_name] - The first name. + * @param {String} [data.last_name] - The last name. + * @param {String} [data.email] - E-mail. + * @param {Object} [data.custom_data] - Order custom data. + * @param {String} [data.custom_data.barcode] - Tracking number for order. + * @param {String} [data.custom_data.airbillno] - Additional tracking number for order. + * @param {String} [data.custom_data.sorted_on_date] - Datetime String with "T" delimiter, + * ISO 8601. + * @param {Number} [data.custom_data.sorted_on_utc] - Timestamp only; replaced data in + * `sorted_on_date` property. + * + * @param {Object[]} data.local_time_windows - Array of Time Window objects. + * @param {Number} data.local_time_windows.start - Start of Time Window, unix timestamp. + * @param {Number} data.local_time_windows.end - End of Time Window, unix timestamp. + * @param {String} [data.local_timezone_string] - Local timezone String + * @param {Number} [data.service_time] - Consumed service time. + * @param {String} [data.color] - Color of an address, e.g., 'FF0000'. + * @param {String} [data.tracking_number] - Tracking number + * @param {String} [data.address_stop_type] - The type of stop that this is + * one of 'DELIVERY', 'PICKUP', 'BREAK', 'MEETUP', 'SERVICE', 'VISIT' or 'DRIVEBY'. + * + * @param {Number} [data.last_status] + * @param {Number} [data.weight] - Weight of the cargo. + * @param {Number} [data.cost] - Cost of the cargo. + * @param {Number} [data.revenue] - The total revenue for the order. + * @param {Number} [data.cube] - The cubic volume of the cargo. + * @param {Number} [data.pieces] - The item quantity of the cargo. + * @param {String} [data.group] - The group. + * @param {Number} data.address_priority - Priority of address + * 0 is the highest priority, n has higher priority than n + 1 + * + * @param {String} data.address_customer_po - The customer purchase order for + * the address, length <= 50. + * + * @param {Object[]} data.custom_fields - Array of Custom Fields objects. + * @param {String} data.custom_fields.order_custom_field_uuid - HEX-String. + * @param {String} data.custom_fields.order_custom_field_value - Value of Custom Fields. + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + create(data, callback) { + return this.r._makeRequest5({ + method: "POST", + path: "/api/v5.0/orders-platform/create", + body: data, + validationContext: "Orders.Order", + }, callback) + } + + /** + * Show single order by its id + * + * @see {@link https://route4me.io/docs/#get-an-order-details} + * @since 1.1.0 + * + * @param {String} id - Order ID, HEX-String + * @param {module:route4me-node~RequestCallback} [callback] + */ + get(id, callback) { + return this.r._makeRequest5({ + method: "GET", + path: `/api/v5.0/orders-platform/${id}`, + validationContext: "Orders.Order", + }, callback) + } + + /** + * Update single order by its id + * + * @example Sample input + * + * const id = "CCCCCA90F77841C693C656123F346AAA"; + * const data = { + * "first_name": "John", + * "last_name": "Doe", + * "email": "John@company.com", + * }; + * + * @see {@link https://route4me.io/docs/#update-an-order} + * @since 1.1.0 + * + * @param {String} id - Order ID, HEX-String + * @param {Object} data - Parameters of order to update, look for more + * information in create() + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + update(id, data, callback) { + return this.r._makeRequest5({ + method: "PUT", + path: `/api/v5.0/orders-platform/${id}`, + body: data, + validationContext: "Orders.Order", + }, callback) + } + + /** + * Delete (soft) single order by its id + * + * @see {@link https://route4me.io/docs/#remove-an-order} + * @since 1.1.0 + * + * @param {String} id - Order ID, HEX-String + * @param {module:route4me-node~RequestCallback} [callback] + */ + remove(id, callback) { + return this.r._makeRequest5({ + method: "DELETE", + path: `/api/v5.0/orders-platform/${id}`, + validationContext: utils.CustomInternalPostProcessing.fromJsonWithStatus, + }, callback) + } + + /** + * Search orders in ElasticSearch storage or in Spanner database + * + * @example Sample input + * + const data = { + filters: { + order_ids: [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + } + }; + * + * @see {@link https://route4me.io/docs/#search-orders} + * @since 1.1.0 + * + * @param {Object} data - Search and filter parameters. + * @param {String[]} [data.order_ids] - Array of order ids, HEX-Strings. + * @param {Boolean} data.return_provided_fields_as_map + * @param {Object[]} data.orderBy - Sort and direction parameters. + * @param {String} orderBy.0 - The name of the sort field, this is + * one of 'address_alias', 'first_name', 'last_name', 'phone', 'is_pending', 'is_validated', + * 'is_accepted', 'is_completed', 'scheduled_for', 'day_added' + * + * @param {String} [orderBy.1 = 'asc'] - Sorting direction, this is + * one of 'asc', 'ASC', 'desc', 'DESC' + * + * @param {Number} data.limit = 30 - The number of orders per page. + * @param {Number} data.offset = 0 - The requested page. + * @param {String[]} data.fields - An array of returned fields, this is + * one of 'order_uuid', 'member_id', 'address_1', 'address_2', 'address_alias', 'address_city', + * 'address_state', 'address_zip', 'address_country', 'coordinates', 'curbside_coordinates', + * 'updated_timestamp', 'created_timestamp', 'day_added', 'scheduled_for', 'order_status_id', + * 'is_pending', 'is_started', 'is_completed', 'is_validated', 'phone', 'first_name', + * 'last_name', 'email', 'custom_data', 'local_time_windows', 'local_timezone', 'service_time', + * 'color', 'icon', 'last_visited_timestamp', 'visited_count', 'in_route_count', + * 'last_routed_timestamp', 'tracking_number', 'organization_id', 'root_member_id', + * 'address_stop_type', 'last_status', 'sorted_day_id', 'weight', 'cost', 'revenue', 'cube', + * 'pieces', 'done_day_id', 'possession_day_id', 'group', 'workflow_uuid', 'address_priority' + * + * @param {String[]} data.addition - An array of additional returned fields, + * this is one of 'territory_ids', 'aggregation_ids' + * + * @param {Object} [data.search] - Search parameters. + * @param {String} [data.search.query] - The string to query to ElasticSearch. + * If set the `matches` and `terms` sections will be ignored. + * + * @param {Object} [data.search.matches] - The object to query + * to ElasticSearch. + * @param {Object} [data.search.matches.custom_data] - Order custom data. + * @param {String} [data.search.matches.custom_data.barcode] - Tracking number for order. + * @param {String} [data.search.matches.custom_data.airbillno] - Additional tracking number + * for order. + * @param {String} [data.search.matches.custom_data.sorted_on_date] - Datetime String + * with "T" delimiter, ISO 8601. + * @param {Number} [data.search.matches.custom_data.sorted_on_utc] - Timestamp only; replaced + * data in `sorted_on_date` property. + * @param {String} [data.search.matches.first_name] - The first name. + * @param {String} [data.search.matches.last_name] - The last name. + * @param {String} [data.search.matches.email] - E-mail. + * @param {String} [data.search.matches.phone] - The phone number. + * @param {String} [data.search.matches.address_1] - The order Address line 1. + * @param {String} [data.search.matches.address_alias] - Address alias. + * @param {String} [data.search.matches.address_zip] - The zip code of the address. + * + * @param {Object} [data.search.terms] - The object to query + * to ElasticSearch. + * @param {Object} [data.search.terms.custom_data] - Order custom data. + * @param {String} [data.search.terms.custom_data.barcode] - Tracking number for order. + * @param {String} [data.search.terms.custom_data.airbillno] - Additional tracking number + * for order. + * @param {String} [data.search.terms.custom_data.sorted_on_date] - Datetime String + * with "T" delimiter, ISO 8601. + * @param {Number} [data.search.terms.custom_data.sorted_on_utc] - Timestamp only; replaced + * data in `sorted_on_date` property. + * @param {String} [data.search.terms.first_name] - The first name. + * @param {String} [data.search.terms.last_name] - The last name. + * @param {String} [data.search.terms.email] - E-mail. + * @param {String} [data.search.terms.phone] - The phone number. + * @param {String} [data.search.terms.address_1] - The order Address line 1. + * @param {String} [data.search.terms.address_alias] - Address alias. + * @param {String} [data.search.terms.address_zip] - The zip code the address is located in. + * + * @param {Object} [data.filters] - Filter parameters. + * @param {String[]} [data.filters.order_ids] - Array of included order ids, HEX-Strings. + * @param {String[]} [data.filters.excluded_ids] - Array of excluded order ids, HEX-Strings. + * @param {String[]} [data.filters.tracking_numbers] - Array of tracking number of orders. + * @param {Boolean} [data.filters.only_geocoded] + * @param {Number|String|Object} [data.filters.updated_timestamp] - Can be unix timestamp or + * ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. + * + * @param {Number|String|Object} [data.filters.created_timestamp] - Can be unix timestamp or + * ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. + * + * @param {Number|String|Object} [data.filters.scheduled_for] - Can be unix timestamp or + * ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. + * + * @param {Boolean} [data.filters.only_unscheduled] + * @param {Number|String|Object} [data.filters.day_added] - Can be unix timestamp or + * ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. + * + * @param {Number|String|Object} [data.filters.sorted_on] - Can be unix timestamp or + * ISO 8601 or Object {"start": "timestamp or ISO 8601", "end": "timestamp or ISO 8601"}. + * + * @param {String[]}[data.filters.address_stop_types] - Array of stop type names, + * possible values 'DELIVERY', 'PICKUP', 'BREAK', 'MEETUP', 'SERVICE', 'VISIT' or 'DRIVEBY'. + * + * @param {Number[]} [data.filters.last_statuses] - Array of statuses. + * @param {Number[]} [data.filters.territory_ids] - Array of territory ids. + * @param {String} [data.filters.done_day] + * @param {String} [data.filters.possession_day] + * @param {String[]} [data.filters.groups] + * @param {String} [data.filters.display= 'all'] - Filtering by the + * in_route_count field, is one of 'routed', 'unrouted', 'all' + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + search(data, callback) { + let body = data || {} + let cb = callback + + if (undefined === cb && "function" === typeof body) { + cb = body + body = null + } + + return this.r._makeRequest5({ + method: "POST", + path: "/api/v5.0/orders-platform", + body, + validationContext: "Orders.List", + }, cb) + } + + /** + * Update the batch of orders (asynchronous, by filters) + * + * @see {@link https://route4me.io/docs/#update-an-order} + * @since 1.1.0 + * + * @param {Object} params - Batch update parameters. + * @param {Object} params.data - Order values for batch update, look for more + * information in create() + * + * @param {Object} params.search - Search parameters for batch update, + * look for more information in search() + * + * @param {Object} params.filters - Filter parameters for batch update, + * look for more information in search() + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + batchUpdateByFilters(params, callback) { + return this.r._makeRequest5({ + method: "PUT", + path: "/api/v5.0/orders-platform/batch-update/filter", + body: params, + validationContext: "utils.CustomInternalPostProcessing.fromJsonWithStatus", + }, callback) + } + + /** + * Delete the batch of orders + * + * @see {@link https://route4me.io/docs/#remove-an-order} + * @since 1.1.0 + * + * @param {String[]} orderIds - Array of Order IDs, HEX-Strings. + * @param {module:route4me-node~RequestCallback} [callback] + */ + batchRemove(orderIds, callback) { + return this.r._makeRequest5({ + method: "POST", + path: "/api/v5.0/orders-platform/batch-delete", + body: { order_ids: orderIds }, + validationContext: utils.CustomInternalPostProcessing.fromJsonWithStatus, + }, callback) + } + + /** + * Update the batch of orders by ids + * + * @see {@link https://route4me.io/docs/#update-an-order} + * @since 1.1.0 + * + * @param {String[]} orderIds - Array of Order IDs, HEX-Strings. + * @param {Object} data - Order values for batch update, look for more + * information in create() + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + batchUpdate(orderIds, data, callback) { + return this.r._makeRequest5({ + method: "POST", + path: "/api/v5.0/orders-platform/batch-update", + body: { + order_ids: orderIds, + data + }, + validationContext: "Orders.List", + }, callback) + } + + /** + * Create the batch of orders + * + * @see {@link https://route4me.io/docs/#update-an-order} + * @since 1.1.0 + * + * @param {Object[]} orders - Array of Order values for batch create, + * look for more information in create() + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + batchCreate(orders, callback) { + return this.r._makeRequest5({ + method: "POST", + path: "/api/v5.0/orders-platform/batch-create", + body: { data: orders }, + validationContext: utils.CustomInternalPostProcessing.fromJsonWithStatus, + }, callback) + } + + /** + * Get a list of Order Custom Fields + * + * @see {@link https://route4me.io/docs/#get-an-order-details} + * @since 1.1.0 + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + getOrderCustomFields(callback) { + return this.r._makeRequest5({ + method: "GET", + path: "/api/v5.0/orders-platform/order-custom-user-fields", + validationContext: "Orders.Response", + }, callback) + } + + /** + * Create one Order Custom Field + * + * @example Sample input + * + const orderTypeCheckbox = { + order_custom_field_name: "CustomField4", + order_custom_field_label: "Custom Field 4", + order_custom_field_type: "checkbox", + order_custom_field_type_info: { short_label: "cFl4" } + } + + const = orderTypeDropdown = { + order_custom_field_name: "TEST", + order_custom_field_label: "MENU", + order_custom_field_type: "dropdown", + order_custom_field_short_caption: "MENU", + order_custom_field_type_info: { + short_caption: "MENU", + allowed_values: ["10", "30", "50", “100”] + } + } + * + * @see {@link https://route4me.io/docs/#create-an-order-custom-fields} + * @since 1.1.0 + * + * @param {Object} data - Params of Order custom field + * @param {String} data.order_custom_field_name - Name, max 128 characters. + * @param {String} data.order_custom_field_type - Type, max 128 characters. + * @param {String} data.order_custom_field_label - Label, max 128 characters. + * @param {Object} data.order_custom_field_type_info - Info, as JSON Object + * max 4096 characters. + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + createOrderCustomField(data, callback) { + return this.r._makeRequest5({ + method: "POST", + path: "/api/v5.0/orders-platform/order-custom-user-fields", + body: data, + validationContext: "OrderCustomFields.Response", + }, callback) + } + + /** + * Update one Order Custom Fields + * + * @see {@link https://route4me.io/docs/#update-an-order-custom-fields} + * @since 1.1.0 + * + * @param {Number} uuid - OrderCustomField ID, HEX-string. + * @param {Object} data - Params of Order custom field + * @param {String} data.order_custom_field_type - Type, max 128 characters. + * @param {String} data.order_custom_field_label - Label, max 128 characters. + * @param {Object} data.order_custom_field_type_info - Info, as JSON Object + * max 4096 characters. + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + updateOrderCustomField(uuid, data, callback) { + return this.r._makeRequest5({ + method: "PUT", + path: `/api/v5.0/orders-platform/order-custom-user-fields/${uuid}`, + body: data, + validationContext: "OrderCustomFields.Response", + }, callback) + } + + /** + * Remove an Order Custom Fields + * + * @see {@link https://route4me.io/docs/#remove-user-custom-field} + * @since 1.1.0 + * + * @param {Number} uuid - OrderCustomField ID, HEX-string. + * + * @param {module:route4me-node~RequestCallback} [callback] + */ + removeOrderCustomField(uuid, callback) { + return this.r._makeRequest5({ + method: "DELETE", + path: `/api/v5.0/orders-platform/order-custom-user-fields/${uuid}`, + validationContext: "OrderCustomFields.Response", + }, callback) + } +} + +module.exports = OrdersV5 diff --git a/src/resources/orders.js b/src/resources/orders.js index cb5c5b1..c9c813c 100644 --- a/src/resources/orders.js +++ b/src/resources/orders.js @@ -114,40 +114,38 @@ class Orders { } /** - * Get an Order Details + * Get an Order Details by ID or by UUID * * @see {@link https://route4me.io/docs/#get-an-order-details} - * @since 0.1.11 + * @since 1.1.0 * - * @param {number} id - Order ID + * @param {number|string} id - Order ID as number or order UUID as HEX-string * @param {module:route4me-node~RequestCallback} [callback] */ get(id, callback) { - const pureId = Number(id) - return this.r._makeRequest({ method: "GET", path: "/api.v4/order.php", qs: { - "order_id": pureId, + "order_id": id, }, validationContext: "Orders.Order", }, callback) } /** - * Get all the orders created under the specific Route4Me account + * Get all the orders created under the specific Route4Me account by IDs or by UUIDs * * @see {@link https://route4me.io/docs/#get-orders-with-details} - * @since 0.1.11 + * @since 1.1.0 * - * @param {number|string|Array|Array} [ids] - Order IDs in one + * @param {number|string|Array|Array} [ids] - Order IDs or order UUIDs in one * of the following form: - * * CSV-string - * * one ID as string + * * one UUID as HEX-string + * * UUIDs as CSV-HEX-string + * * UUIDs as array of HEX-strings * * one ID as number - * * array of strings - * * array of numbers + * * IDs as array of numbers * * If you want to load all Orders: * * **Don't pass** this parameter @@ -168,13 +166,8 @@ class Orders { const qs = {} - if (pureIds || 0 === pureIds) { - if (pureIds instanceof Array) { - qs["order_id"] = pureIds.toString() - } else { - pureIds = utils.toIntArray(pureIds) - qs["order_id"] = pureIds - } + if (pureIds) { + qs["order_id"] = pureIds.toString() } return this.r._makeRequest({ @@ -186,29 +179,27 @@ class Orders { } /** - * Remove an Order + * Remove Orders by ID or by UUID * * @see {@link https://route4me.io/docs/#remove-an-order} - * @since 0.1.11 + * @since 1.1.0 * - * @param {number|string|Array|Array} ids - Order ID/IDs to remove in one + * @param {number|string|Array|Array} ids - Order IDs or order UUIDs in one * of the following form: - * * CSV-string - * * one ID as string + * * one UUID as HEX-string + * * UUIDs as CSV-HEX-string + * * UUIDs as array of HEX-strings * * one ID as number - * * array of strings - * * array of numbers + * * IDs as array of numbers * * @param {module:route4me-node~RequestCallback} [callback] */ remove(ids, callback) { - const pureIds = utils.toIntArray(ids) - const qs = { "redirect": 0, } const body = { - "order_ids": pureIds + "order_ids": utils.toStringArray(ids) } return this.r._makeRequest({ @@ -221,12 +212,12 @@ class Orders { } /** - * Update an Order + * Update an Order by ID or by UUID * * @see {@link https://route4me.io/docs/#update-an-order} - * @since 0.1.11 + * @since 1.1.0 * - * @param {number} id - Order ID + * @param {number|string} id - Order ID as number or order UUID as HEX-string * @param {jsonschema:Orders.Order} data - Order data * @param {module:route4me-node~RequestCallback} [callback] */ @@ -235,7 +226,7 @@ class Orders { "redirect": 0, } const body = utils.clone(data) - body["order_id"] = Number(id) + body["order_id"] = id.toString() return this.r._makeRequest({ method: "PUT", @@ -257,7 +248,7 @@ class Orders { * @todo TODO: Handle the diffrerent format of the output (when fields are set, * see https://github.com/route4me/route4me-nodejs-sdk/issues/38) * - * @param {string|Object} criteria - Searched text or searching criteria + * @param {string|Object} criteria - Searched text or searching criteria * @param {Date} [criteria.byAddDate] - Date order was inserted * @param {Date} [criteria.byScheduledDate] - Date order was scheduled for * @param {string} [criteria.query] - The text searched for diff --git a/src/route4me.js b/src/route4me.js index 2206653..4f712c7 100644 --- a/src/route4me.js +++ b/src/route4me.js @@ -15,6 +15,7 @@ const Members = require("./resources/members") const Notes = require("./resources/notes") const Optimizations = require("./resources/optimizations") const Orders = require("./resources/orders") +const OrdersV5 = require("./resources/orders-v5") const PodWorkflow = require("./resources/proof-of-delivery-workflow") const Routes = require("./resources/routes") const Schedules = require("./resources/schedules") @@ -51,6 +52,7 @@ const RequestManager = require("./request-manager") * * [Notes ]{@link Notes} * * [Optimizations ]{@link Optimizations} * * [Orders ]{@link Orders} + * * [OrdersV5 ]{@link OrdersV5} * * [OrderCustomFields ]{@link OrderCustomFields} * * [PodWorkflow ]{@link PodWorkflow} * * [Routes ]{@link Routes} @@ -201,6 +203,12 @@ class Route4Me { * @since 0.1.11 */ this.Orders = new Orders(req) + /** + * **OrdersV5** related API calls + * @type {OrdersV5} + * @since 1.1.0 + */ + this.OrdersV5 = new OrdersV5(req) /** * **PodWorkflow** related API calls * @type {PodWorkflow} diff --git a/test/helper.js b/test/helper.js index 20a9349..637a2b6 100644 --- a/test/helper.js +++ b/test/helper.js @@ -15,9 +15,6 @@ function expectRequest(req, method, url, query, body, contentType /* , form */) expect(req).has.property("method") .and.is.equal(method) - expect(req).has.property("headers") - .that.has.property("content-type", ct) - // QUERY assertions expect(req).has.property("query") .with.property("api_key") @@ -37,11 +34,14 @@ function expectRequest(req, method, url, query, body, contentType /* , form */) // BODY assertions if (body) { + expect(req).has.property("headers") + .that.has.property("content-type", ct) + expect(req).has.property("body") .that.is.deep.equal(body) } else { expect(req).has.property("body") - .and.is.null + .and.is.deep.equal({}) } // if (form) { diff --git a/test/resources/orders-v5.spec.js b/test/resources/orders-v5.spec.js new file mode 100644 index 0000000..544f9de --- /dev/null +++ b/test/resources/orders-v5.spec.js @@ -0,0 +1,561 @@ +"use strict" + +const request = require("superagent") +const saMock = require("superagent-mocker")(request) + +const helper = require("./../helper") +const route4me = require("./../../dist") + +const testApiKey = "11111111111111111111111111111111" + + +describe(helper.toSuiteName(__filename), () => { + describe("SDK methods", () => { + const route4meClient = new route4me.Route4Me(testApiKey) + const resource = route4meClient.OrdersV5 + let req + + describe("create", () => { + beforeEach(() => { + saMock.post("*", (r) => { + req = r + req.method = "POST" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const data = { + "address_1": "1358 E Luzerne St, Philadelphia, PA 19124, US", + "cached_lat": 48.335991, + "cached_lng": 31.18287, + "address_alias": "Auto test address", + "address_city": "Philadelphia", + "first_name": "Igor", + "last_name": "Progman", + "email": "spam@route4me.com", + "phone": "380380380380", + "custom_data": [{ + "order_id": "10", + "name": "Bill Soul" + }], + } + + it("should call route4me", (done) => { + resource.create(data, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "POST", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/create", + {}, + { + "address_1": "1358 E Luzerne St, Philadelphia, PA 19124, US", + "cached_lat": 48.335991, + "cached_lng": 31.18287, + "address_alias": "Auto test address", + "address_city": "Philadelphia", + "first_name": "Igor", + "last_name": "Progman", + "email": "spam@route4me.com", + "phone": "380380380380", + "custom_data": [{ + "order_id": "10", + "name": "Bill Soul" + }], + } + ) + + done() + }) + }) + }) + + describe("get", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderId = "ABCDEF0987654321" + + it("should call route4me", (done) => { + resource.get(orderId, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/ABCDEF0987654321", + {} + ) + done() + }) + }) + }) + + describe("search", () => { + beforeEach(() => { + saMock.post("*", (r) => { + req = r + req.method = "POST" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const data = { + filters: { + order_ids: ["CCCCCA90F77841C693C656123F346AAA"] + } + } + + it("should call route4me", (done) => { + resource.search(data, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "POST", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform", + {}, + { + "filters": { + "order_ids": ["CCCCCA90F77841C693C656123F346AAA"] + } + } + ) + + done() + }) + }) + + it("should call route4me wihtout parameters", (done) => { + resource.search((err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "POST", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform", + {} + ) + + done() + }) + }) + }) + + describe("update", () => { + beforeEach(() => { + saMock.put("*", (r) => { + req = r + req.method = "PUT" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderId = "CCCCCA90F77841C693C656123F346AAA" + const data = { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + } + + it("should call route4me", (done) => { + resource.update(orderId, data, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "PUT", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/CCCCCA90F77841C693C656123F346AAA", + {}, + { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + } + ) + done() + }) + }) + }) + + describe("remove", () => { + beforeEach(() => { + saMock.del("*", (r) => { + req = r + req.method = "DELETE" + return { body: { status: true }} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderId = "CCCCCA90F77841C693C656123F346AAA" + + it("should call route4me", (done) => { + resource.remove(orderId, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "DELETE", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/CCCCCA90F77841C693C656123F346AAA", + {} + ) + done() + }) + }) + }) + + describe("batchUpdateByFilters", () => { + beforeEach(() => { + saMock.put("*", (r) => { + req = r + req.method = "PUT" + return { body: { status: true }} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const params = { + "data": { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + }, + "filters": { + "order_ids": [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + } + } + + it("should call route4me", (done) => { + resource.batchUpdateByFilters(params, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "PUT", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/batch-update/filter", + {}, + { + "data": { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + }, + "filters": { + "order_ids": [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + } + } + ) + done() + }) + }) + }) + + describe("batchRemove", () => { + beforeEach(() => { + saMock.post("*", (r) => { + req = r + req.method = "POST" + return { body: { status: true }} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + + it("should call route4me", (done) => { + resource.batchRemove(orderIds, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "POST", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/batch-delete", + {}, + { + "order_ids": [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + } + ) + done() + }) + }) + }) + + describe("batchUpdate", () => { + beforeEach(() => { + saMock.post("*", (r) => { + req = r + req.method = "POST" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const data = { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + } + const orderIds = [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + + it("should call route4me with array of ids", (done) => { + resource.batchUpdate(orderIds, data, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "POST", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/batch-update", + {}, + { + "data": { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + }, + "order_ids": [ + "CCCCCA90F77841C693C656123F346AAA", + "BBB8CA90F77841C693C656123F346AAA" + ] + } + ) + done() + }) + }) + }) + + describe("batchCreate", () => { + beforeEach(() => { + saMock.post("*", (r) => { + req = r + req.method = "POST" + return { body: { status: true }} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orders = [{ + "address_1": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + }, { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + }] + + it("should call route4me with array of ids", (done) => { + resource.batchCreate(orders, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "POST", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/batch-create", + {}, + { + "data": [{ + "address_1": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + }, { + "address_2": "Lviv", + "custom_data": [{ "customer_no": 11 }], + "phone": "032268593" + }], + } + ) + done() + }) + }) + }) + + describe("createOrderCustomField", () => { + beforeEach(() => { + saMock.post("*", (r) => { + req = r + req.method = "POST" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const data = { + "order_custom_field_name": "CustomField4", + "order_custom_field_label": "Custom Field 4", + "order_custom_field_type": "checkbox", + "order_custom_field_type_info": { "short_label": "cFl4" } + } + it(" orderCustomFields should call route4me", (done) => { + resource.createOrderCustomField(data, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "POST", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/order-custom-user-fields", + {}, + { + "order_custom_field_name": "CustomField4", + "order_custom_field_label": "Custom Field 4", + "order_custom_field_type": "checkbox", + "order_custom_field_type_info": { "short_label": "cFl4" } + } + ) + done() + }) + }) + }) + + describe("getOrderCustomFields", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + it("orderCustomFields should call route4me", (done) => { + resource.getOrderCustomFields((err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/order-custom-user-fields", + {}, + ) + done() + }) + }) + }) + + describe("updateOrderCustomField", () => { + beforeEach(() => { + saMock.put("*", (r) => { + req = r + req.method = "PUT" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const uuid = "CCCCCA90F77841C693C656123F346AAA" + const data = { + "order_custom_field_id": 922, + "order_custom_field_value": "100" + } + + it("orderCustomFields should call route4me", (done) => { + resource.updateOrderCustomField(uuid, data, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "PUT", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/order-custom-user-fields/CCCCCA90F77841C693C656123F346AAA", + {}, + { + "order_custom_field_id": 922, + "order_custom_field_value": "100" + } + ) + done() + }) + }) + }) + + describe("removeOrderCustomField", () => { + beforeEach(() => { + saMock.del("*", (r) => { + req = r + req.method = "DELETE" + return {} + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const uuid = "CCCCCA90F77841C693C656123F346AAA" + + it("orderCustomFields should call route4me", (done) => { + resource.removeOrderCustomField(uuid, (err, res) => { + expect(err).not.exist + expect(res).is.not.null + + helper.expectRequest(req, + "DELETE", + route4meClient.baseUrl5() + "/api/v5.0/orders-platform/order-custom-user-fields/CCCCCA90F77841C693C656123F346AAA", + {} + ) + done() + }) + }) + }) + }) +}) diff --git a/test/resources/orders.spec.js b/test/resources/orders.spec.js index a881753..38cbb35 100644 --- a/test/resources/orders.spec.js +++ b/test/resources/orders.spec.js @@ -76,38 +76,71 @@ describe(helper.toSuiteName(__filename), () => { }) describe("get", () => { - beforeEach(() => { - saMock.get("*", (r) => { - req = r - req.method = "GET" - return { body: {} } + describe("order by ID as number", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return { body: {} } + }) }) - }) - afterEach(() => { - saMock.clearRoutes() + afterEach(() => { + saMock.clearRoutes() + }) + + const orderId = 7205711 + + it("should call route4me", (done) => { + resource.get(orderId, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl() + "/api.v4/order.php", + { "order_id": "7205711" }, + null + ) + done() + }) + }) }) - const orderId = 7205711 + describe("order by UUID as string", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return { body: {} } + }) + }) - it("should call route4me", (done) => { - resource.get(orderId, (err, res) => { - expect(err).not.exist - expect(res).exist + afterEach(() => { + saMock.clearRoutes() + }) - helper.expectRequest(req, - "GET", - route4meClient.baseUrl() + "/api.v4/order.php", - { "order_id": "7205711" }, - null - ) - done() + const orderId = "AAAAACB6FBA530A80000000000DDDDDD" + + it("should call route4me", (done) => { + resource.get(orderId, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl() + "/api.v4/order.php", + { "order_id": "AAAAACB6FBA530A80000000000DDDDDD" }, + null + ) + done() + }) }) }) }) describe("list", () => { - describe("for one item", () => { + describe("for one item ID as string", () => { beforeEach(() => { saMock.get("*", (r) => { req = r @@ -140,7 +173,40 @@ describe(helper.toSuiteName(__filename), () => { }) }) - describe("for N items as string", () => { + describe("for one item ID as number", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return { body: { "order_id": 7205711 } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = 7205711 + + it("should call route4me and receive an array", (done) => { + resource.list(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl() + "/api.v4/order.php", + { "order_id": "7205711" }, + null + ) + + expect(res).is.an("array") + done() + }) + }) + }) + + describe("for N items ID as CSV-string", () => { beforeEach(() => { saMock.get("*", (r) => { req = r @@ -155,6 +221,39 @@ describe(helper.toSuiteName(__filename), () => { const orderIds = "7205711, 7205712" + it("should call route4me and receive an array", (done) => { + resource.list(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl() + "/api.v4/order.php", + { "order_id": "7205711, 7205712" }, + null + ) + + expect(res).is.an("array") + done() + }) + }) + }) + + describe("for N items ID as Array of string", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return { body: { "results": [{ }, { }], "total": 2 } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = ["7205711", "7205712"] + it("should call route4me and receive an array", (done) => { resource.list(orderIds, (err, res) => { expect(err).not.exist @@ -173,7 +272,7 @@ describe(helper.toSuiteName(__filename), () => { }) }) - describe("for N items as Array", () => { + describe("for N items ID as Array on number", () => { beforeEach(() => { saMock.get("*", (r) => { req = r @@ -206,6 +305,105 @@ describe(helper.toSuiteName(__filename), () => { }) }) + describe("for one item UUID as string", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return { body: { "order_id": 7205711 } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = "AAAAACB6FBA530A80000000000DDDDDD" + + it("should call route4me and receive an array", (done) => { + resource.list(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl() + "/api.v4/order.php", + { "order_id": "AAAAACB6FBA530A80000000000DDDDDD" }, + null + ) + + expect(res).is.an("array") + done() + }) + }) + }) + + describe("for N items UUID as CSV-string", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return { body: { "results": [{ }, { }], "total": 2 } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = "AAAAACB6FBA530A80000000000DDDDDD, AAAAABBBBBA530A80000000000DDDDDD" + + it("should call route4me and receive an array", (done) => { + resource.list(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl() + "/api.v4/order.php", + { "order_id": "AAAAACB6FBA530A80000000000DDDDDD, AAAAABBBBBA530A80000000000DDDDDD" }, + null + ) + + expect(res).is.an("array") + done() + }) + }) + }) + + describe("for N items UUID as Array of string", () => { + beforeEach(() => { + saMock.get("*", (r) => { + req = r + req.method = "GET" + return { body: { "results": [{ }, { }], "total": 2 } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = ["AAAAACB6FBA530A80000000000DDDDDD", "AAAAABBBBBA530A80000000000DDDDDD"] + + it("should call route4me and receive an array", (done) => { + resource.list(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "GET", + route4meClient.baseUrl() + "/api.v4/order.php", + { "order_id": "AAAAACB6FBA530A80000000000DDDDDD,AAAAABBBBBA530A80000000000DDDDDD" }, + null + ) + + expect(res).is.an("array") + done() + }) + }) + }) + describe("all routes", () => { beforeEach(() => { saMock.get("*", (r) => { @@ -365,78 +563,252 @@ describe(helper.toSuiteName(__filename), () => { }) describe("update", () => { - beforeEach(() => { - saMock.put("*", (r) => { - req = r - req.method = "PUT" - return { body: { } } + describe("order by ID as number", () => { + beforeEach(() => { + saMock.put("*", (r) => { + req = r + req.method = "PUT" + return { body: { } } + }) }) - }) - afterEach(() => { - saMock.clearRoutes() + 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", + route4meClient.baseUrl() + "/api.v4/order.php", + { "redirect": "0" }, + { + "order_id": "7205711", + "address_2": "Lviv", + "EXT_FIELD_custom_data": [{ "customer_no": 11 }], + "EXT_FIELD_phone": "032268593" + } + ) + done() + }) + }) }) - const orderId = "7205711" - const data = { - "order_id": "34", - "address_2": "Lviv", - "EXT_FIELD_custom_data": [ - { - "customer_no": 11 - } - ], - "EXT_FIELD_phone": "032268593" - } + describe("order by UUID as string", () => { + beforeEach(() => { + saMock.put("*", (r) => { + req = r + req.method = "PUT" + return { body: { } } + }) + }) - it("should call route4me", (done) => { - resource.update(orderId, data, (err, res) => { - expect(err).not.exist - expect(res).exist + afterEach(() => { + saMock.clearRoutes() + }) - helper.expectRequest(req, - "PUT", - route4meClient.baseUrl() + "/api.v4/order.php", - { "redirect": "0" }, + const orderId = "AAAAACB6FBA530A80000000000DDDDDD" + const data = { + "order_id": "34", + "address_2": "Lviv", + "EXT_FIELD_custom_data": [ { - "order_id": 7205711, - "address_2": "Lviv", - "EXT_FIELD_custom_data": [{ "customer_no": 11 }], - "EXT_FIELD_phone": "032268593" + "customer_no": 11 } - ) - done() + ], + "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", + route4meClient.baseUrl() + "/api.v4/order.php", + { "redirect": "0" }, + { + "order_id": "AAAAACB6FBA530A80000000000DDDDDD", + "address_2": "Lviv", + "EXT_FIELD_custom_data": [{ "customer_no": 11 }], + "EXT_FIELD_phone": "032268593" + } + ) + done() + }) }) }) }) describe("remove", () => { - beforeEach(() => { - saMock.del("*", (r) => { - req = r - req.method = "DELETE" - return { body: { "status": true } } + describe("order by ID as number", () => { + beforeEach(() => { + saMock.del("*", (r) => { + req = r + req.method = "DELETE" + return { body: { "status": true } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = 7205711 + + it("should call route4me", (done) => { + resource.remove(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "DELETE", + route4meClient.baseUrl() + "/api.v4/order.php", + { "redirect": "0" }, + { "order_ids": ["7205711"] } + ) + done() + }) }) }) - afterEach(() => { - saMock.clearRoutes() + describe("order by ID as array of numbers", () => { + beforeEach(() => { + saMock.del("*", (r) => { + req = r + req.method = "DELETE" + return { body: { "status": true } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = [7205711 , 7205713] + + it("should call route4me", (done) => { + resource.remove(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "DELETE", + route4meClient.baseUrl() + "/api.v4/order.php", + { "redirect": "0" }, + { "order_ids": ["7205711", "7205713"] } + ) + done() + }) + }) }) - const orderIds = "7205711 , 7205713" + describe("order by UUID as string", () => { + beforeEach(() => { + saMock.del("*", (r) => { + req = r + req.method = "DELETE" + return { body: { "status": true } } + }) + }) - it("should call route4me", (done) => { - resource.remove(orderIds, (err, res) => { - expect(err).not.exist - expect(res).exist + afterEach(() => { + saMock.clearRoutes() + }) - helper.expectRequest(req, - "DELETE", - route4meClient.baseUrl() + "/api.v4/order.php", - { "redirect": "0" }, - { "order_ids": [7205711, 7205713] } - ) - done() + const orderIds = "AAAAACB6FBA530A80000000000DDDDDD" + + it("should call route4me", (done) => { + resource.remove(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "DELETE", + route4meClient.baseUrl() + "/api.v4/order.php", + { "redirect": "0" }, + { "order_ids": ["AAAAACB6FBA530A80000000000DDDDDD"] } + ) + done() + }) + }) + }) + + describe("order by UUID as array of string", () => { + beforeEach(() => { + saMock.del("*", (r) => { + req = r + req.method = "DELETE" + return { body: { "status": true } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = ["AAAAACB6FBA530A80000000000DDDDDD" , "AAAAABBBBBA530A80000000000DDDDDD"] + + it("should call route4me", (done) => { + resource.remove(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "DELETE", + route4meClient.baseUrl() + "/api.v4/order.php", + { "redirect": "0" }, + { "order_ids": ["AAAAACB6FBA530A80000000000DDDDDD", "AAAAABBBBBA530A80000000000DDDDDD"] } + ) + done() + }) + }) + }) + + describe("order by UUID as CSV-string", () => { + beforeEach(() => { + saMock.del("*", (r) => { + req = r + req.method = "DELETE" + return { body: { "status": true } } + }) + }) + + afterEach(() => { + saMock.clearRoutes() + }) + + const orderIds = "AAAAACB6FBA530A80000000000DDDDDD, AAAAABBBBBA530A80000000000DDDDDD" + + it("should call route4me", (done) => { + resource.remove(orderIds, (err, res) => { + expect(err).not.exist + expect(res).exist + + helper.expectRequest(req, + "DELETE", + route4meClient.baseUrl() + "/api.v4/order.php", + { "redirect": "0" }, + { "order_ids": ["AAAAACB6FBA530A80000000000DDDDDD", "AAAAABBBBBA530A80000000000DDDDDD"] } + ) + done() + }) }) }) })