Comparing version 3.0.1 to 4.1.1
553
main.js
/** | ||
* NodeJS interface for the AfterShip API. | ||
* From docs here: https://www.aftership.com/docs/api/3.0 | ||
* From docs here: https://www.aftership.com/docs/api/4.0 | ||
* | ||
* @author Kirk Morales (kirk@intrakr.com) | ||
* @author Kirk Morales (kirk@intrakr.com), Bossa (github.com/BossaGroove) | ||
* @copyright Copyright (C) 2013 | ||
@@ -11,13 +11,32 @@ * @license GNU General Public License, version 2 (see LICENSE.md) | ||
var https = require('https'); | ||
/** | ||
* | ||
* Error Type | ||
* 600, 'UnhandledError' | ||
* 601, 'ParseResponseError', 'Could not parse response.' | ||
* 602, 'MissingParameter', 'Missing Required Parameter: tracking number.' | ||
* 603, 'ResponseError', 'Invalid response body.' | ||
*/ | ||
var _ = require('lodash'); | ||
/** | ||
* Hostname for AfterShip API. | ||
* @type {string} | ||
* @const | ||
* @private | ||
*/ | ||
var REQUEST_HOSTNAME = 'api.aftership.com'; | ||
var request_hostname = process.env.AFTERSHIP_NODEJS_SDK_HOST || 'api.aftership.com'; | ||
/** | ||
* Port for AfterShip API. | ||
* @type {number} | ||
* @private | ||
*/ | ||
var request_post = process.env.AFTERSHIP_NODEJS_SDK_PORT || 443; | ||
var protocol = ((request_post === 443) ? 'https' : 'http'); | ||
var request = require('request'); | ||
/** | ||
* Path for AfterShip API. | ||
@@ -28,26 +47,65 @@ * @type {string} | ||
*/ | ||
var API_PATH = '/v3'; | ||
var API_PATH = '/v4'; | ||
/** | ||
* timeout of each request in milliseconds | ||
* @const | ||
* @type {number} | ||
*/ | ||
var TIMEOUT = 30000; | ||
/** | ||
* Initializes the AfterShip plugin. | ||
* @param {string} key | ||
* @param {string} api_key - AfterShip api key | ||
* @return {Object.<string,function>} | ||
*/ | ||
module.exports = function(key) { | ||
module.exports = function(api_key) { | ||
'use strict'; | ||
// Require API key | ||
if (!key) { | ||
if (!api_key) { | ||
return {}; | ||
} | ||
var apiKey = key; | ||
/** | ||
* Return the error object for callback use | ||
* @param code {!number} - meta.code | ||
* @param type {!string}- meta.type | ||
* @param message {!string} - meta.message | ||
* @returns {{code: *, type: *, message: *}} | ||
* @private | ||
*/ | ||
function _getError(code, type, message) { | ||
return { | ||
code: code, | ||
type: type, | ||
message: message | ||
} | ||
} | ||
/** | ||
* serial object to url query string | ||
* @param obj {Object} - hash | ||
* @returns {string} - output serialized string | ||
* @private | ||
*/ | ||
function _serialize(obj) { | ||
var str = []; | ||
for(var key in obj) | ||
if (obj.hasOwnProperty(key)) { | ||
str.push(encodeURIComponent(key) + "=" + encodeURIComponent(obj[key])); | ||
} | ||
return str.join("&"); | ||
} | ||
/** | ||
* Performs an API request. | ||
* @param {string} method The HTTP method. | ||
* @param {string} path The HTTP path to append to the AfterShip default. | ||
* @param {Object} data Body for POST requests. | ||
* @param {function(?string, object=)} callback | ||
* @param method {string} - method The HTTP method. | ||
* @param path {string} - path The HTTP path to append to the AfterShip default. | ||
* @param data {Object} - data Body for POST requests. | ||
* @param callback {function(Object, Object=)} - callback | ||
* @private | ||
*/ | ||
function request(method, path, data, callback) { | ||
function _call(method, path, data, callback) { | ||
@@ -63,65 +121,62 @@ // Make sure path starts with a slash | ||
var asReq = https.request({ | ||
hostname: REQUEST_HOSTNAME, | ||
path: API_PATH + path, | ||
var request_option = { | ||
url: protocol + '://' + request_hostname + ':' + request_post + API_PATH + path, | ||
method: method, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': data.length, | ||
'aftership-api-key': apiKey | ||
} | ||
}, function(asRes) { | ||
var body = ''; | ||
'aftership-api-key': api_key | ||
}, | ||
timeout: TIMEOUT, | ||
body: data | ||
}; | ||
// Capture the response chunks | ||
asRes.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
request(request_option, function(err, response, body) { | ||
// Called when request is complete | ||
asRes.on('end', function() { | ||
var return_err = null; | ||
var return_body = null; | ||
//don't put callback inside try catch to prevent catching user's throw | ||
try { | ||
body = JSON.parse(body); | ||
if (!body || !body.meta) { | ||
callback('Could not parse response'); | ||
return; | ||
return_err = _getError(601, 'ParseResponseError', 'Could not parse response.'); | ||
} else { | ||
return_body = body; | ||
} | ||
} catch (e) { | ||
//console.log(e.stack); | ||
return_err = _getError(601, 'ParseResponseError', 'Could not parse response.'); | ||
} | ||
callback(null, body); | ||
}); | ||
callback(return_err, return_body); | ||
}); | ||
} | ||
// Capture any errors | ||
asReq.on('error', function(e) { | ||
callback(e.message); | ||
}); | ||
return { | ||
asReq.write(data); | ||
asReq.end(); | ||
} | ||
return { | ||
/** | ||
* create a new tracking_number. | ||
* @param {string} tracking_number The number to track. Default: DHL. | ||
* @param {Object=} options Additional options to attach. | ||
* @param {function(?string, string=, Array=)} callback | ||
* Create a new tracking_number | ||
* @param {string} tracking_number - The tracking number to track. | ||
* @param {Object=} params - Additional options to attach. | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'createTracking': function(tracking_number, options, callback) { | ||
'createTracking': function(tracking_number, params, callback) { | ||
options = options || {}; | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
if (!callback) { | ||
callback = params; | ||
params = {}; | ||
} | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
if (!_.isString(tracking_number)) { | ||
callback(_getError(602, 'MissingParameter', 'Missing Required Parameter: tracking number.')); | ||
} | ||
options.tracking_number = tracking_number; | ||
params.tracking_number = tracking_number; | ||
request('POST', '/trackings', {tracking: options}, function(err, body) { | ||
_call('POST', '/trackings', {tracking: params}, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
callback(err, null); | ||
return; | ||
@@ -131,16 +186,15 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 201) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
if (!body.meta || !body.meta.code) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
if (!(body.meta.code === 201 || body.meta.code === 202)) { | ||
callback(body.meta, body.data); | ||
return; | ||
} | ||
// Check that it was activated | ||
if (!body.data.tracking.active) { | ||
callback('Tracking not active'); | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
@@ -154,74 +208,75 @@ } | ||
/** | ||
* Tracks a specific tracking number. | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to return: https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
* Get a tracking number with options | ||
* @param {string} slug - slug of the tracking number | ||
* @param {string} tracking_number - number to get | ||
* @param {Object|function(Object, Object=)} options hash | ||
* https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number | ||
* | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'tracking': function(slug, tracking_number, fields, callback) { | ||
'getTracking': function(slug, tracking_number, options, callback) { | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
if (!callback) { | ||
callback = options; | ||
options = {}; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
if (!_.isString(tracking_number)) { | ||
callback(_getError(602, 'MissingParameter', 'Missing Required Parameter: tracking number.')); | ||
} | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
if (!_.isString(slug)) { | ||
callback(_getError(602, 'MissingParameter', 'Missing Required Parameter: tracking number.')); | ||
} | ||
if (Array.isArray(fields)) { | ||
fields = fields.join(','); | ||
} else { | ||
return 'Invalid Parameter type: fields, expect an Array'; | ||
if (Array.isArray(options.fields)) { | ||
options.fields = options.fields.join(','); | ||
} | ||
if (fields) { | ||
fields = 'fields=' + fields; | ||
} | ||
request('GET', '/trackings/' + slug + '/' + tracking_number + '?' + fields, | ||
{}, function(err, body) { | ||
_call('GET', '/trackings/' + slug + '/' + tracking_number + '?' + _serialize(options), {}, function(err, body) { | ||
if (err) { | ||
callback(err, null); | ||
return; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
if (body.meta.code !== 200) { | ||
callback(body.meta, body.data); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
} | ||
// Return the time and checkpoints | ||
callback(null, body.data); | ||
}); | ||
// Return the time and checkpoints | ||
callback(null, body.data); | ||
}); | ||
return null; | ||
}, | ||
/** | ||
* Gets all trackings in account. | ||
* @param {object} options Defined here: https://www.aftership.com/docs/api/3.0/tracking/get-trackings | ||
* @param {function(?string, Object=)} callback | ||
* Gets all tracking numbers in account. | ||
* @param {Object|function} options - Defined here: | ||
* https://www.aftership.com/docs/api/3.0/tracking/get-trackings | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'trackings': function(options, callback) { | ||
options = options || {}; | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
'getTrackings': function(options, callback) { | ||
if (!callback) { | ||
callback = options; | ||
options = {}; | ||
} | ||
request('GET', '/trackings', options, function(err, body) { | ||
_call('GET', '/trackings', options, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
callback(err, null); | ||
return; | ||
@@ -231,10 +286,15 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
if (!body.meta || !body.meta.code) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
if (body.meta.code !== 200) { | ||
callback(body.meta, body.data); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data !== 'object') { | ||
callback('Invalid response body'); | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
@@ -245,3 +305,2 @@ } | ||
callback(null, body.data); | ||
return; | ||
}); | ||
@@ -257,42 +316,69 @@ }, | ||
* https://www.aftership.com/docs/api/3.0/tracking/put-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'updateTracking': function(slug, tracking_number, options, callback) { | ||
_call('PUT', '/trackings/' + slug + '/' + tracking_number, {tracking: options}, function(err, body) { | ||
if (err) { | ||
callback(err, null); | ||
return; | ||
} | ||
options = options || {}; | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
} | ||
callback(null, body.data); | ||
}); | ||
}, | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
/** | ||
* Delete a specific tracking number. | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Object|function(Object, Object=)} required_fields - required fields object | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'deleteTracking': function(slug, tracking_number, required_fields, callback) { | ||
if (!callback) { | ||
callback = required_fields; | ||
required_fields = {}; | ||
} | ||
request('PUT', '/trackings/' + slug + '/' + tracking_number, | ||
{tracking: options}, function(err, body) { | ||
_call('DELETE', '/trackings/' + slug + '/' + tracking_number + '?' + _serialize(required_fields), {}, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
if (err) { | ||
callback(err, null); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
if (body.meta.code !== 200) { | ||
callback(body.meta, body.data); | ||
return; | ||
} | ||
callback(null, body.data); | ||
}); | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
} | ||
// Return the tracking number and slug | ||
callback(null, body.data); | ||
}); | ||
}, | ||
@@ -302,45 +388,49 @@ | ||
/** | ||
* Delete a specific tracking number. | ||
* Get the last checkpoint information of a tracking number | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to return: https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number | ||
* @param {function(?string, Object=)} callback | ||
* @param {Array|string|function(Object, Object=)} fields Fields to update: https://www.aftership.com/docs/api/3.0/last_checkpoint | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'deleteTracking': function(slug, tracking_number, callback) { | ||
'getLastCheckpoint': function(slug, tracking_number, fields, callback) { | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
if (!callback) { | ||
callback = fields; | ||
fields = []; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
if (Array.isArray(fields)) { | ||
fields = fields.join(','); | ||
} | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
if (fields.length > 0) { | ||
fields = 'fields=' + fields; | ||
} | ||
request('DELETE', '/trackings/' + slug + '/' + tracking_number, | ||
{}, function(err, body) { | ||
_call('GET', '/last_checkpoint/' + slug + '/' + tracking_number + '?' + fields, {}, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
if (err) { | ||
callback(err, null); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
if (body.meta.code !== 200) { | ||
callback(body.meta, body.data); | ||
return; | ||
} | ||
// Return the tracking number and slug | ||
callback(null, body.data); | ||
}); | ||
// Check for valid data contents | ||
if (!body.data || !body.data.checkpoint || typeof body.data.checkpoint !== 'object') { | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
} | ||
callback(null, body.data); | ||
}); | ||
}, | ||
@@ -351,14 +441,8 @@ | ||
* Gets all available couriers. | ||
* @param {function(?string, Object=)} callback | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'couriers': function(callback) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
request('GET', '/couriers', {}, function(err, body) { | ||
'getCouriers': function(callback) { | ||
_call('GET', '/couriers', {}, function(err, body) { | ||
if (err) { | ||
callback(err); | ||
callback(err, null); | ||
return; | ||
@@ -368,10 +452,15 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
if (!body.meta || !body.meta.code) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
if (body.meta.code !== 200) { | ||
callback(body.meta, body.data); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data !== 'object') { | ||
callback('Invalid response body'); | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
@@ -384,56 +473,60 @@ } | ||
/** | ||
* Get the last checkpoint information of a tracking number | ||
* @param {string} slug | ||
* @param {string} tracking_number | ||
* @param {Array|string} fields Fields to update: https://www.aftership.com/docs/api/3.0/last_checkpoint | ||
* @param {function(?string, Object=)} callback | ||
* Detect the courier for given tracking number | ||
* @param {string} tracking_number - tracking number to be detected | ||
* @param {Object|function(Object, Object=)} required_fields - optional, hash of required fields | ||
* possible values: {"tracking_account_number": "", "tracking_postal_code": "", "tracking_ship_date": ""} | ||
* @param {string|function(Object, Object=)=} detect_mode - optional, accept "strict" or "tracking_number" | ||
* @param {function(Object, Object=)} callback - callback function | ||
*/ | ||
'last_checkpoint': function(slug, tracking_number, fields, callback) { | ||
if (!slug) { | ||
return 'Missing Required Parameter: slug'; | ||
'detectCouriers': function(tracking_number, required_fields, detect_mode, callback) { | ||
if (!callback) { | ||
callback = detect_mode; | ||
detect_mode = 'tracking_number'; | ||
} | ||
if (!tracking_number) { | ||
return 'Missing Required Parameter: tracking number'; | ||
if (!callback) { | ||
callback = required_fields; | ||
required_fields = {}; | ||
} | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
var param = { | ||
tracking: { | ||
tracking_number: tracking_number, | ||
tracking_account_number: required_fields.tracking_account_number, | ||
tracking_postal_code: required_fields.tracking_postal_code, | ||
tracking_ship_date: required_fields.tracking_ship_date, | ||
tracking_key: required_fields.tracking_key, | ||
detect_mode: detect_mode | ||
} | ||
}; | ||
_call('POST', '/couriers/detect/', param, function(err, body) { | ||
if (err) { | ||
callback(err, null); | ||
return; | ||
} | ||
if (Array.isArray(fields)) { | ||
fields = fields.join(','); | ||
} else { | ||
return 'Invalid Parameter type: fields, expect an Array'; | ||
} | ||
if (fields) { | ||
fields = 'fields=' + fields; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code) { | ||
callback(body.meta, null); | ||
return; | ||
} | ||
request('GET', '/last_checkpoint/' + slug + '/' + tracking_number + '?' + fields, | ||
{}, function(err, body) { | ||
if (body.meta.code !== 200) { | ||
callback(body.meta, body.data); | ||
return; | ||
} | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.couriers || typeof body.data.couriers !== 'object') { | ||
callback(_getError(603, 'ResponseError', 'Invalid response body.')); | ||
return; | ||
} | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
return; | ||
} | ||
callback(null, body.data); | ||
}); | ||
} | ||
// Check for valid data contents | ||
if (!body.data || !body.data.checkpoint || typeof body.data.checkpoint !== 'object') { | ||
callback('Invalid response body'); | ||
return; | ||
} | ||
callback(null, body.data); | ||
}); | ||
} | ||
}; | ||
@@ -440,0 +533,0 @@ }; |
{ | ||
"name": "aftership", | ||
"description": "AfterShip NodeJS API Wrapper", | ||
"version": "3.0.1", | ||
"version": "4.1.1", | ||
"homepage": "https://github.com/AfterShip/aftership-nodejs", | ||
@@ -18,2 +18,4 @@ "repository": { | ||
"dependencies": { | ||
"lodash": "2.4.1", | ||
"request": "2.39.0" | ||
}, | ||
@@ -20,0 +22,0 @@ "devDependencies": { |
@@ -241,2 +241,3 @@ Install | ||
License | ||
@@ -243,0 +244,0 @@ ========= |
@@ -10,19 +10,41 @@ if (!GLOBAL.apiKey) { | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
'OK': function(test) { | ||
Aftership.getCouriers(function(err, result) { | ||
test.expect(2); | ||
test.equal(Aftership.couriers(), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.done(); | ||
}); | ||
}, | ||
'OK': function(test) { | ||
test.expect(2); | ||
'Detect Courier': function(test) { | ||
Aftership.detectCouriers('906587618687', function(err, result) { | ||
test.expect(2); | ||
Aftership.couriers(function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.total, 33); | ||
test.done(); | ||
}); | ||
}, | ||
'Detect Courier strict': function(test) { | ||
Aftership.detectCouriers('906587618687', {}, 'strict', function(err, result) { | ||
test.expect(2); | ||
test.equal(err, null); | ||
test.equal(result.total, 33); | ||
test.done(); | ||
}); | ||
}, | ||
'Detect Courier strict with postal code': function(test) { | ||
Aftership.detectCouriers('906587618687', {'tracking_postal_code': 'DA15BU'}, 'strict', function(err, result) { | ||
test.expect(2); | ||
test.equal(err, null); | ||
test.equal(result.total, 33); | ||
test.done(); | ||
}); | ||
} | ||
}; |
/****************************************** | ||
* Set your API key here for testing | ||
******************************************/ | ||
GLOBAL.apiKey = '9e8639c6-7a83-4123-b61e-c3c3ef6c1da5'; // please use your AfterShip api key | ||
GLOBAL.apiKey = process.env.AFTERSHIP_NODEJS_SDK_API_KEY || ''; // please use your AfterShip api key | ||
@@ -11,8 +11,12 @@ /****************************************** | ||
GLOBAL.tracking = { | ||
'dhl': '4681442382', | ||
'fedex': '573191403485', | ||
'tnt': '881232984', | ||
'toll-global-express': '813081390262', | ||
'ups': '1Z5V572E0365305588', | ||
'usps': '9405509699937485290971' | ||
'dhl': '1100677045', | ||
'fedex': '618320505092', | ||
'tnt': 'GE171378685WW', | ||
'toll-global-express': '813007861271', | ||
'ups': '1Z01Y69E6644338280', | ||
'usps': '9374869903500183656767', | ||
'dx': { | ||
tracking_number: '1551540939', | ||
tracking_postal_code: 'NR172BS' | ||
} | ||
}; | ||
@@ -45,3 +49,4 @@ | ||
// Choose appropriate reporter | ||
var reporter; | ||
var reporter, i; | ||
if (argv.verbose) { | ||
@@ -51,6 +56,5 @@ reporter = require('nodeunit').reporters.default; | ||
// Add directory to each item | ||
for (var i = 0; i < tests.length; i++) { | ||
for (i = 0; i < tests.length; i++) { | ||
tests[i] = 'test/' + tests[i]; | ||
} | ||
} else { | ||
@@ -60,3 +64,3 @@ reporter = require('nodeunit'); | ||
// Add directory to each item | ||
for (var i = 0; i < tests.length; i++) { | ||
for (i = 0; i < tests.length; i++) { | ||
tests[i] = __dirname + '/' + tests[i]; | ||
@@ -68,5 +72,4 @@ } | ||
reporter.run(tests, null); | ||
} else { | ||
reporter.runFiles(tests); | ||
} | ||
} |
@@ -8,506 +8,436 @@ if (!GLOBAL.apiKey) { | ||
var create_tracking = true; | ||
var get_tracking = true; | ||
var get_trackings = true; | ||
var update_tracking = true; | ||
var checkpoint = true; | ||
var delete_tracking = true; | ||
exports.CreateTracking = { | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
if (create_tracking) { | ||
exports.CreateTracking = { | ||
test.equal(Aftership.createTracking(), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'Ok (no slug)': function(test) { | ||
test.expect(5); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.usps, {}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
// Make sure it auto-detected the slug | ||
test.equal(result.tracking.slug, 'usps'); | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
test.done(); | ||
}); | ||
}, | ||
test.equal(Aftership.createTracking('foo'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Error (duplicate)': function(test) { | ||
test.expect(3); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.usps, {}, function(err, result) { | ||
test.equal(err.code, 4003); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.equal(typeof result, 'object'); | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
test.done(); | ||
}); | ||
}, | ||
test.equal(Aftership.createTracking('foo', {}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Ok (no slug)': function(test) { | ||
test.expect(5); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.usps, {}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
// Make sure it auto-detected the slug | ||
test.equal(result.tracking.slug, 'usps'); | ||
'Ok (w/ slug tnt)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// tnt | ||
Aftership.createTracking(GLOBAL.tracking.tnt, {slug: 'tnt'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.tnt); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'tnt'); | ||
'Ok (w/ slug tnt)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// tnt | ||
Aftership.createTracking(GLOBAL.tracking.tnt, {slug: 'tnt'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.tnt); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'tnt'); | ||
'Ok (w/ slug fedex)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// Fedex | ||
Aftership.createTracking(GLOBAL.tracking.fedex, {slug: 'fedex'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.fedex); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'fedex'); | ||
'Ok (w/ slug fedex)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// Fedex | ||
Aftership.createTracking(GLOBAL.tracking.fedex, {slug: 'fedex'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.fedex); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'fedex'); | ||
'Ok (w/ slug ups)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// Fedex | ||
Aftership.createTracking(GLOBAL.tracking.ups, {slug: 'ups'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'ups'); | ||
'Ok (w/ slug ups)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// Fedex | ||
Aftership.createTracking(GLOBAL.tracking.ups, {slug: 'ups'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'ups'); | ||
'Ok (w/ slug toll-global-express)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// toll-global-express | ||
Aftership.createTracking(GLOBAL.tracking['toll-global-express'], {slug: 'toll-global-express'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking['toll-global-express']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'toll-global-express'); | ||
'Ok (w/ slug toll-global-express)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// toll-global-express | ||
Aftership.createTracking(GLOBAL.tracking['toll-global-express'], {slug: 'toll-global-express'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking['toll-global-express']); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'toll-global-express'); | ||
'Ok (w/ slug dhl)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// dhl | ||
Aftership.createTracking(GLOBAL.tracking.dhl, {slug: 'dhl'}, function(err, result) { | ||
test.ok(!err); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dhl); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'dhl'); | ||
'Ok (w/ slug dhl)': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// dhl | ||
Aftership.createTracking(GLOBAL.tracking.dhl, {slug: 'dhl'}, function(err, result) { | ||
test.ok(!err); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dhl); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'dhl'); | ||
test.done(); | ||
}); | ||
}, | ||
'Error (w/ slug usps)': function(test) { | ||
test.expect(6); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.usps, {slug: 'usps'}, function(err, result) { | ||
// as the tracking is already created in w/o slug, there should be error return | ||
'Ok (w/ slug usps)': function(test) { | ||
test.expect(5); | ||
test.notEqual(err, ''); | ||
test.equal(err.code, 4003); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.equal(typeof result, 'object'); | ||
test.equal(typeof result.tracking.checkpoints, 'undefined'); | ||
test.equal(result.tracking.slug, 'usps'); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.usps, {slug: 'usps'}, function(err, result) { | ||
// as the tracking is already created in w/o slug, there should be error return | ||
test.notEqual(err, ''); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.equal(typeof result, 'object'); | ||
test.equal(typeof result.tracking.checkpoints, 'undefined'); | ||
test.equal(result.tracking.slug, 'usps'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
'Ok (w/ slug dx)': function(test) { | ||
test.expect(5); | ||
// usps | ||
Aftership.createTracking(GLOBAL.tracking.dx.tracking_number, {slug: 'dx', tracking_postal_code: GLOBAL.tracking.dx.tracking_postal_code}, function(err, result) { | ||
exports.Tracking = { | ||
test.notEqual(err, ''); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dx.tracking_number); | ||
test.equal(typeof result, 'object'); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(result.tracking.slug, 'dx'); | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
//wait 15 seconds for letting crawlers process | ||
setTimeout(function(){ | ||
test.done(); | ||
}, 10000); | ||
test.equal(Aftership.tracking(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
}); | ||
} | ||
}; | ||
} | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
if (get_tracking) { | ||
exports.Tracking = { | ||
'Ok ups': function(test) { | ||
test.expect(6); | ||
test.equal(Aftership.tracking('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
// UPS | ||
Aftership.getTracking('ups', GLOBAL.tracking.ups, {}, function(err, result) { | ||
'No Callback (no fields)': function(test) { | ||
test.expect(1); | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(typeof result.tracking.active, 'boolean'); | ||
test.equal(Aftership.tracking('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'No Callback (w/ fields)': function(test) { | ||
test.expect(7); | ||
'Ok ups limited fields': function(test) { | ||
test.expect(6); | ||
// UPS | ||
Aftership.tracking('ups', GLOBAL.tracking.ups, ['tracking_number', 'slug'], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(typeof result.tracking.checkpoints, 'undefined'); | ||
test.equal(typeof result.tracking.active, 'undefined'); | ||
test.equal(typeof result.tracking.tag, 'undefined'); | ||
// UPS | ||
Aftership.getTracking('ups', GLOBAL.tracking.ups, {fields: ['slug', 'tracking_number']}, function(err, result) { | ||
test.done(); | ||
}); | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(typeof result.tracking.checkpoints, 'undefined'); | ||
test.equal(typeof result.tracking.active, 'undefined'); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok': function(test) { | ||
test.expect(6); | ||
'Ok ups limited fields 2': function(test) { | ||
test.expect(6); | ||
// UPS | ||
Aftership.tracking('ups', GLOBAL.tracking.ups, [], function(err, result) { | ||
// UPS | ||
Aftership.getTracking('ups', GLOBAL.tracking.ups, {fields: 'slug,tracking_number'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(typeof result.tracking.active, 'boolean'); | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(typeof result.tracking.checkpoints, 'undefined'); | ||
test.equal(typeof result.tracking.active, 'undefined'); | ||
test.done(); | ||
}); | ||
} | ||
test.done(); | ||
}); | ||
}, | ||
}; | ||
exports.Trackings = { | ||
'OK (DX)': function(test) { | ||
test.expect(6); | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
Aftership.getTracking('dx', GLOBAL.tracking.dx.tracking_number, { tracking_postal_code: GLOBAL.tracking.dx.tracking_postal_code }, function(err, result) { | ||
test.equal(Aftership.trackings(), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'dx'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dx.tracking_number); | ||
test.ok(result.tracking.checkpoints); | ||
test.equal(typeof result.tracking.active, 'boolean'); | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
//wait 7 seconds for algolia | ||
setTimeout(function(){ | ||
test.done(); | ||
}, 7000); | ||
}); | ||
} | ||
}; | ||
} | ||
test.equal(Aftership.trackings({}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'OK': function(test) { | ||
test.expect(5); | ||
if (get_trackings) { | ||
exports.Trackings = { | ||
Aftership.trackings({}, function(err, results) { | ||
test.equal(err, null); | ||
test.ok(Array.isArray(results.trackings)); | ||
'OK': function(test) { | ||
test.expect(5); | ||
// Check for a few meta parameters | ||
test.equal(typeof results.limit, 'number'); | ||
test.equal(typeof results.slug, 'string'); | ||
Aftership.getTrackings({}, function(err, results) { | ||
// We should have at least 1 entry, check it | ||
test.equal(typeof results.trackings[0].tracking_number, 'string'); | ||
test.equal(err, null); | ||
test.ok(Array.isArray(results.trackings)); | ||
test.done(); | ||
// Check for a few meta parameters | ||
test.equal(typeof results.limit, 'number'); | ||
test.equal(typeof results.slug, 'string'); | ||
}); | ||
} | ||
// We should have at least 1 entry, check it | ||
test.equal(typeof results.trackings[0].tracking_number, 'string'); | ||
// 'OK (filtering)': function(test) { | ||
// test.expect(8); | ||
test.done(); | ||
// Aftership.trackings({limit: 1}, function(err, meta, trackings) { | ||
// test.equal(err, null); | ||
// test.equal(typeof meta, 'object'); | ||
// test.ok(Array.isArray(trackings)); | ||
}); | ||
} | ||
}; | ||
} | ||
// // Make sure trackings array was removed from meta data | ||
// test.ok(!meta.trackings); | ||
if (update_tracking) { | ||
exports.UpdateTracking = { | ||
'Ok': function(test) { | ||
test.expect(5); | ||
// // Check for a few meta parameters | ||
// test.equal(typeof meta.limit, 'number'); | ||
// test.equal(meta.limit, 1); | ||
// test.equal(trackings.length, 1); | ||
// UPS | ||
Aftership.updateTracking('ups', GLOBAL.tracking.ups, {}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.notEqual(typeof(result.tracking.active), 'undefined'); | ||
// // We should have at least 1 entry, check it | ||
// test.equal(typeof trackings[0].tracking_number, 'string'); | ||
test.done(); | ||
}); | ||
}, | ||
// test.done(); | ||
'Ok (with change)': function(test) { | ||
test.expect(5); | ||
// }); | ||
// } | ||
// UPS | ||
Aftership.updateTracking('ups', GLOBAL.tracking.ups, {title: 'Foobar'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(result.tracking.title, 'Foobar'); | ||
}; | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
} | ||
exports.UpdateTracking = { | ||
if (checkpoint) { | ||
exports.Checkpoint = { | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
'Ok with fields': function(test) { | ||
test.expect(4); | ||
test.equal(Aftership.updateTracking(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
// UPS | ||
Aftership.getLastCheckpoint('ups', GLOBAL.tracking.ups, ['message'], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.checkpoint, 'object'); | ||
test.equal(typeof result.checkpoint.tag, 'undefined'); | ||
test.equal(typeof result.checkpoint.country_iso3, 'undefined'); | ||
test.done(); | ||
}); | ||
}, | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
'Ok': function(test) { | ||
test.expect(2); | ||
test.equal(Aftership.updateTracking('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
// UPS | ||
Aftership.getLastCheckpoint('ups', GLOBAL.tracking.ups, [], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.checkpoint, 'object'); | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
} | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
if (delete_tracking) { | ||
exports.DeleteTracking = { | ||
test.equal(Aftership.updateTracking('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Tracking Number is not exist': function(test) { | ||
test.expect(1); | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
// UPS | ||
Aftership.deleteTracking('ups', '12345677654', function(err, result) { | ||
test.equal(err.code, 4004); | ||
test.done(); | ||
}); | ||
}, | ||
test.equal(Aftership.updateTracking('ups', '1234', {}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Ok Delete dhl': function(test) { | ||
test.expect(4); | ||
'Ok': function(test) { | ||
test.expect(5); | ||
// dhl | ||
Aftership.deleteTracking('dhl', GLOBAL.tracking.dhl, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'dhl'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dhl); | ||
// UPS | ||
Aftership.updateTracking('ups', GLOBAL.tracking.ups, {}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.notEqual(typeof(result.tracking.active), 'undefined'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok Delete fedex': function(test) { | ||
test.expect(4); | ||
'Ok (with change)': function(test) { | ||
test.expect(5); | ||
// fedex | ||
Aftership.deleteTracking('fedex', GLOBAL.tracking.fedex, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'fedex'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.fedex); | ||
// UPS | ||
Aftership.updateTracking('ups', GLOBAL.tracking.ups, {title: 'Foobar'}, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(result.tracking.title, 'Foobar'); | ||
test.done(); | ||
}); | ||
}, | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
'Ok Delete tnt': function(test) { | ||
test.expect(4); | ||
// tnt | ||
Aftership.deleteTracking('tnt', GLOBAL.tracking.tnt, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'tnt'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.tnt); | ||
exports.Checkpoint = { | ||
test.done(); | ||
}); | ||
}, | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
'Ok Delete toll-global-express': function(test) { | ||
test.expect(4); | ||
test.equal(Aftership.last_checkpoint(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
// toll-global-express | ||
Aftership.deleteTracking('toll-global-express', GLOBAL.tracking['toll-global-express'], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'toll-global-express'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking['toll-global-express']); | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
test.done(); | ||
}); | ||
}, | ||
test.equal(Aftership.last_checkpoint('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'Ok Delete ups': function(test) { | ||
test.expect(4); | ||
'No Callback (no fields)': function(test) { | ||
test.expect(1); | ||
// UPS | ||
Aftership.deleteTracking('ups', GLOBAL.tracking.ups, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.equal(Aftership.last_checkpoint('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'No Callback (w/ fields)': function(test) { | ||
test.expect(1); | ||
'Ok Delete usps': function(test) { | ||
test.expect(4); | ||
test.equal(Aftership.last_checkpoint('ups', '1234', []), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
// usps | ||
Aftership.deleteTracking('usps', GLOBAL.tracking.usps, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'usps'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
'Ok with fields': function(test) { | ||
test.expect(4); | ||
test.done(); | ||
}); | ||
}, | ||
// UPS | ||
Aftership.last_checkpoint('ups', GLOBAL.tracking.ups, ['message'], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.checkpoint, 'object'); | ||
test.equal(typeof result.checkpoint.tag, 'undefined'); | ||
test.equal(typeof result.checkpoint.country_iso3, 'undefined'); | ||
'Ok Delete dx': function(test) { | ||
test.expect(5); | ||
test.done(); | ||
}); | ||
}, | ||
// usps | ||
Aftership.deleteTracking('dx', GLOBAL.tracking.dx.tracking_number, {tracking_postal_code: GLOBAL.tracking.dx.tracking_postal_code}, function(err, result) { | ||
'Ok': function(test) { | ||
test.expect(2); | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'dx'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dx.tracking_number); | ||
test.equal(result.tracking.tracking_postal_code, GLOBAL.tracking.dx.tracking_postal_code); | ||
// UPS | ||
Aftership.last_checkpoint('ups', GLOBAL.tracking.ups, [], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.checkpoint, 'object'); | ||
test.done(); | ||
}); | ||
} | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
exports.DeleteTracking = { | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.deleteTracking(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.deleteTracking('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'No Callback (no fields)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.deleteTracking('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (w/ fields)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.deleteTracking('ups', '1234', []), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Tracking Number is not exist': function(test) { | ||
test.expect(3); | ||
// UPS | ||
Aftership.deleteTracking('ups', '12345677654', function(err, result) { | ||
test.equal(err, '404: Tracking is not exist.'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, '12345677654'); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok Delete dhl': function(test) { | ||
test.expect(4); | ||
// dhl | ||
Aftership.deleteTracking('dhl', GLOBAL.tracking.dhl, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'dhl'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.dhl); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok Delete fedex': function(test) { | ||
test.expect(4); | ||
// fedex | ||
Aftership.deleteTracking('fedex', GLOBAL.tracking.fedex, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'fedex'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.fedex); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok Delete tnt': function(test) { | ||
test.expect(4); | ||
// tnt | ||
Aftership.deleteTracking('tnt', GLOBAL.tracking.tnt, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'tnt'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.tnt); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok Delete toll-global-express': function(test) { | ||
test.expect(4); | ||
// toll-global-express | ||
Aftership.deleteTracking('toll-global-express', GLOBAL.tracking['toll-global-express'], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'toll-global-express'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking['toll-global-express']); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok Delete ups': function(test) { | ||
test.expect(4); | ||
// UPS | ||
Aftership.deleteTracking('ups', GLOBAL.tracking.ups, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'ups'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.ups); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok Delete usps': function(test) { | ||
test.expect(4); | ||
// usps | ||
Aftership.deleteTracking('usps', GLOBAL.tracking.usps, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.tracking, 'object'); | ||
test.equal(result.tracking.slug, 'usps'); | ||
test.equal(result.tracking.tracking_number, GLOBAL.tracking.usps); | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
}; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
33238
8
866
254
0
2
3
+ Addedlodash@2.4.1
+ Addedrequest@2.39.0
+ Addedasn1@0.1.11(transitive)
+ Addedassert-plus@0.1.5(transitive)
+ Addedasync@0.9.2(transitive)
+ Addedaws-sign2@0.5.0(transitive)
+ Addedboom@0.4.2(transitive)
+ Addedcombined-stream@0.0.7(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedctype@0.5.3(transitive)
+ Addeddelayed-stream@0.0.5(transitive)
+ Addedforever-agent@0.5.2(transitive)
+ Addedform-data@0.1.4(transitive)
+ Addedhawk@1.1.1(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedhttp-signature@0.10.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedlodash@2.4.1(transitive)
+ Addedmime@1.2.11(transitive)
+ Addedmime-types@1.0.2(transitive)
+ Addednode-uuid@1.4.8(transitive)
+ Addedoauth-sign@0.3.0(transitive)
+ Addedqs@0.6.6(transitive)
+ Addedrequest@2.39.0(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedtldts@6.1.61(transitive)
+ Addedtldts-core@6.1.61(transitive)
+ Addedtough-cookie@5.0.0(transitive)
+ Addedtunnel-agent@0.4.3(transitive)