Comparing version 3.0.0 to 3.0.1
72
main.js
@@ -11,4 +11,3 @@ /** | ||
var https = require('https'), | ||
_ = require('underscore'); | ||
var https = require('https'); | ||
@@ -39,3 +38,3 @@ /** | ||
if (!key) { | ||
return; | ||
return {}; | ||
} | ||
@@ -56,3 +55,3 @@ var apiKey = key; | ||
// Make sure path starts with a slash | ||
if (path.substr(0, 1) != '/') { | ||
if (path.substr(0, 1) !== '/') { | ||
path = '/' + path; | ||
@@ -119,3 +118,3 @@ } | ||
if (!_.isFunction(callback)) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
@@ -133,3 +132,3 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 201) { | ||
if (!body.meta || !body.meta.code || body.meta.code !== 201) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
@@ -140,3 +139,3 @@ return; | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
@@ -175,14 +174,17 @@ return; | ||
if (!_.isFunction(callback)) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
// Default to all fields if none are provided | ||
fields = fields || []; | ||
if (Array.isArray(fields)) { | ||
fields = fields.join(','); | ||
} else { | ||
return 'Invalid Parameter type: fields, expect an Array'; | ||
} | ||
if (fields) { | ||
fields = 'fields=' + fields; | ||
} | ||
request('GET', '/trackings/' + slug + '/' + tracking_number, | ||
{fields: fields}, function(err, body) { | ||
request('GET', '/trackings/' + slug + '/' + tracking_number + '?' + fields, | ||
{}, function(err, body) { | ||
@@ -195,3 +197,3 @@ if (err) { | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
@@ -202,3 +204,3 @@ return; | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
@@ -221,3 +223,3 @@ return; | ||
if (!_.isFunction(callback)) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
@@ -234,3 +236,3 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
@@ -241,3 +243,3 @@ return; | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data != 'object') { | ||
if (!body.data || typeof body.data !== 'object') { | ||
callback('Invalid response body'); | ||
@@ -249,2 +251,3 @@ return; | ||
callback(null, body.data); | ||
return; | ||
}); | ||
@@ -274,3 +277,3 @@ }, | ||
if (!_.isFunction(callback)) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
@@ -288,3 +291,3 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
@@ -295,3 +298,3 @@ return; | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
@@ -323,3 +326,3 @@ return; | ||
if (!_.isFunction(callback)) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
@@ -337,3 +340,3 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
@@ -344,3 +347,3 @@ return; | ||
// Check for valid data contents | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking != 'object') { | ||
if (!body.data || !body.data.tracking || typeof body.data.tracking !== 'object') { | ||
callback('Invalid response body'); | ||
@@ -362,3 +365,3 @@ return; | ||
if (!_.isFunction(callback)) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
@@ -375,3 +378,3 @@ } | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
@@ -382,3 +385,3 @@ return; | ||
// Check for valid data contents | ||
if (!body.data || typeof body.data != 'object') { | ||
if (!body.data || typeof body.data !== 'object') { | ||
callback('Invalid response body'); | ||
@@ -409,13 +412,18 @@ return; | ||
if (!_.isFunction(callback)) { | ||
if (typeof callback !== 'function') { | ||
return 'Missing Required Parameter: callback'; | ||
} | ||
fields = fields || []; | ||
if (Array.isArray(fields)) { | ||
fields = fields.join(','); | ||
} else { | ||
return 'Invalid Parameter type: fields, expect an Array'; | ||
} | ||
if (fields) { | ||
fields = 'fields=' + fields; | ||
} | ||
request('GET', '/last_checkpoint/' + slug + '/' + tracking_number, | ||
{fields: fields}, function(err, body) { | ||
request('GET', '/last_checkpoint/' + slug + '/' + tracking_number + '?' + fields, | ||
{}, function(err, body) { | ||
@@ -428,3 +436,3 @@ if (err) { | ||
// Check for valid meta code | ||
if (!body.meta || !body.meta.code || body.meta.code != 200) { | ||
if (!body.meta || !body.meta.code || body.meta.code !== 200) { | ||
callback(body.meta.code + ': ' + body.meta.error_message, body.data); | ||
@@ -435,3 +443,3 @@ return; | ||
// Check for valid data contents | ||
if (!body.data || !body.data.checkpoint || typeof body.data.checkpoint != 'object') { | ||
if (!body.data || !body.data.checkpoint || typeof body.data.checkpoint !== 'object') { | ||
callback('Invalid response body'); | ||
@@ -438,0 +446,0 @@ return; |
{ | ||
"name": "aftership", | ||
"description": "AfterShip NodeJS API Wrapper", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"homepage": "https://github.com/AfterShip/aftership-nodejs", | ||
@@ -18,3 +18,2 @@ "repository": { | ||
"dependencies": { | ||
"underscore": "latest" | ||
}, | ||
@@ -21,0 +20,0 @@ "devDependencies": { |
@@ -13,3 +13,3 @@ Install | ||
- Paste your API key in ```test/tests.js``` | ||
- If you desire, update test tracking numbers in ```test/test.js``` | ||
- If you desire, update test tracking numbers in ```test/local.js``` | ||
@@ -21,11 +21,8 @@ To test, run | ||
``` | ||
NOTE: Once tracking numbers have been added to your account, the tests in track.js will fail. | ||
In case there is any fail tests, please make sure to delete the testing tracking numbers from your aftership account before a new test. | ||
If this is the case, you can test everything else by commenting out the ```track.js``` line in ```test/tests.js``` | ||
or remove the tracking number in aftership.com account. | ||
Use | ||
@@ -52,4 +49,3 @@ ========= | ||
err: the error message | ||
count: The number of couriers count | ||
couriers: the array of available couriers | ||
result: the couriers object | ||
@@ -61,4 +57,5 @@ ``` | ||
``` | ||
Aftership.couriers(function(err, count, couriers) { | ||
console.log('Support Courier: ' + count); | ||
Aftership.couriers(function(err, result) { | ||
console.log('Support courier count: ' + result.total); | ||
console.log('Couriers: ' + result.couriers); | ||
}); | ||
@@ -90,3 +87,3 @@ | ||
``` | ||
function(err, tracking_number, options) | ||
function(err, result) | ||
@@ -98,7 +95,7 @@ ``` | ||
``` | ||
Aftership.createTracking('1Z21E98F0314447088', {slug: 'ups'}, function(err, tracking_number, tracking_detail) { | ||
Aftership.createTracking('1Z21E98F0314447088', {slug: 'ups'}, function(err, result) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log('Created the tracking: ' + tracking_number); | ||
console.log('Created the tracking: ' + result); | ||
} | ||
@@ -118,3 +115,3 @@ }); | ||
options: An object with options to limit results | ||
fields: Array of fields to return | ||
https://www.aftership.com/docs/api/3.0/tracking/get-trackings | ||
@@ -126,3 +123,3 @@ ``` | ||
``` | ||
function(err, data, trackings) | ||
function(err, results) | ||
@@ -134,8 +131,8 @@ ``` | ||
``` | ||
Aftership.trackings({}, function(err, data, trackings) { | ||
Aftership.trackings({}, [], function(err, results) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log('Total Trackings in query: ' + data.count); | ||
console.log(trackings); | ||
console.log('Total Trackings in query: ' + results.count); | ||
console.log(results); | ||
} | ||
@@ -163,3 +160,3 @@ }); | ||
function(err, tracking) | ||
function(err, result) | ||
@@ -172,7 +169,7 @@ ``` | ||
Aftership.tracking('ups', '1Z21E98F0314447088', [], function(err, tracking) { | ||
Aftership.tracking('ups', '1Z21E98F0314447088', ['tracking_number','slug','checkpoints'], function(err, result) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(tracking); | ||
console.log(result); | ||
} | ||
@@ -201,3 +198,3 @@ }); | ||
``` | ||
function(err, updated_tracking) | ||
function(err, result) | ||
@@ -211,7 +208,7 @@ ``` | ||
Aftership.updateTracking('ups', '1Z21E98F0314447088', {title: 'My Shipment'}, | ||
function(err, updated_tracking) { | ||
function(err, result) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(updated_tracking); | ||
console.log(result); | ||
} | ||
@@ -239,3 +236,3 @@ }); | ||
``` | ||
function(err, tag, last_checkpoint) | ||
function(err, result) | ||
@@ -247,7 +244,7 @@ ``` | ||
``` | ||
Aftership.last_checkpoint('ups', '1Z21E98F0314447088', [], function(err, tag, last_checkpoint) { | ||
Aftership.last_checkpoint('ups', '1Z21E98F0314447088', ['tracking_number','slug','checkpoints'], function(err, result) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(last_checkpoint); | ||
console.log(result); | ||
} | ||
@@ -271,3 +268,1 @@ }); | ||
[Intrakr]: http://intrakr.com | ||
/****************************************** | ||
* Set your API key here for testing | ||
******************************************/ | ||
GLOBAL.apiKey = 'e9f201df-91f2-4f13-9a64-3ad64826d47d'; // please use your AfterShip api key | ||
GLOBAL.apiKey = '9e8639c6-7a83-4123-b61e-c3c3ef6c1da5'; // please use your AfterShip api key | ||
@@ -25,5 +25,3 @@ /****************************************** | ||
'couriers.js', | ||
'track.js', | ||
'trackings.js', | ||
'delete_trackings.js' | ||
'trackings.js' | ||
]; | ||
@@ -30,0 +28,0 @@ |
if (!GLOBAL.apiKey) { | ||
console.log('No API Key Provided'); | ||
process.exit(1); | ||
console.log('No API Key Provided'); | ||
process.exit(1); | ||
} | ||
@@ -9,170 +9,315 @@ | ||
exports.Track = { | ||
exports.CreateTracking = { | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.tracking(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.createTracking(), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.tracking('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.createTracking('foo'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (no fields)': function(test) { | ||
test.expect(1); | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.tracking('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.createTracking('foo', {}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (w/ fields)': function(test) { | ||
test.expect(1); | ||
'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'); | ||
test.equal(Aftership.tracking('ups', '1234', []), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.done(); | ||
}); | ||
}, | ||
'Ok': function(test) { | ||
test.expect(6); | ||
'Ok (w/ slug tnt)': function(test) { | ||
test.expect(5); | ||
// UPS | ||
Aftership.tracking('ups', GLOBAL.tracking.ups, null, 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.ok(result.tracking.checkpoints); | ||
test.notEqual(typeof(result.tracking.active), 'undefined'); | ||
// 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'); | ||
test.done(); | ||
}); | ||
} | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug fedex)': function(test) { | ||
test.expect(5); | ||
// 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'); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug ups)': function(test) { | ||
test.expect(5); | ||
// 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'); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug toll-global-express)': function(test) { | ||
test.expect(5); | ||
// 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'); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok (w/ slug dhl)': function(test) { | ||
test.expect(5); | ||
// 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(); | ||
}); | ||
}, | ||
'Ok (w/ slug usps)': function(test) { | ||
test.expect(5); | ||
// 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(); | ||
}); | ||
} | ||
}; | ||
exports.Tracking = { | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.tracking(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.tracking('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'No Callback (no fields)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.tracking('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (w/ fields)': function(test) { | ||
test.expect(7); | ||
// 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'); | ||
test.done(); | ||
}); | ||
}, | ||
'Ok': function(test) { | ||
test.expect(6); | ||
// UPS | ||
Aftership.tracking('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.ok(result.tracking.checkpoints); | ||
test.equal(typeof result.tracking.active, 'boolean'); | ||
test.done(); | ||
}); | ||
} | ||
}; | ||
exports.Trackings = { | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.trackings(), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.trackings(), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.trackings({}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.trackings({}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'OK': function(test) { | ||
test.expect(5); | ||
'OK': function(test) { | ||
test.expect(5); | ||
Aftership.trackings({}, function(err, results) { | ||
test.equal(err, null); | ||
test.ok(Array.isArray(results.trackings)); | ||
Aftership.trackings({}, function(err, results) { | ||
test.equal(err, null); | ||
test.ok(Array.isArray(results.trackings)); | ||
// Check for a few meta parameters | ||
test.equal(typeof results.limit, 'number'); | ||
test.equal(typeof results.slug, 'string'); | ||
// 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'); | ||
// We should have at least 1 entry, check it | ||
test.equal(typeof results.trackings[0].tracking_number, 'string'); | ||
test.done(); | ||
test.done(); | ||
}); | ||
} | ||
}); | ||
} | ||
// 'OK (filtering)': function(test) { | ||
// test.expect(8); | ||
// 'OK (filtering)': function(test) { | ||
// test.expect(8); | ||
// Aftership.trackings({limit: 1}, function(err, meta, trackings) { | ||
// test.equal(err, null); | ||
// test.equal(typeof meta, 'object'); | ||
// test.ok(Array.isArray(trackings)); | ||
// 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); | ||
// // Make sure trackings array was removed from meta data | ||
// test.ok(!meta.trackings); | ||
// // Check for a few meta parameters | ||
// test.equal(typeof meta.limit, 'number'); | ||
// test.equal(meta.limit, 1); | ||
// test.equal(trackings.length, 1); | ||
// // Check for a few meta parameters | ||
// test.equal(typeof meta.limit, 'number'); | ||
// test.equal(meta.limit, 1); | ||
// test.equal(trackings.length, 1); | ||
// // We should have at least 1 entry, check it | ||
// test.equal(typeof trackings[0].tracking_number, 'string'); | ||
// // We should have at least 1 entry, check it | ||
// test.equal(typeof trackings[0].tracking_number, 'string'); | ||
// test.done(); | ||
// test.done(); | ||
// }); | ||
// } | ||
// }); | ||
// } | ||
}; | ||
exports['Update Tracking'] = { | ||
exports.UpdateTracking = { | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.updateTracking(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.updateTracking(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.updateTracking('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.updateTracking('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
'No Callback (no options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.updateTracking('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.updateTracking('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
'No Callback (w/ options)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.updateTracking('ups', '1234', {}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.updateTracking('ups', '1234', {}), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Ok': function(test) { | ||
test.expect(5); | ||
'Ok': function(test) { | ||
test.expect(5); | ||
// 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'); | ||
// 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 (with change)': function(test) { | ||
test.expect(5); | ||
'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'); | ||
// 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(); | ||
}); | ||
} | ||
}; | ||
@@ -183,45 +328,187 @@ | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
'No Slug': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.last_checkpoint(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.last_checkpoint(), 'Missing Required Parameter: slug'); | ||
test.done(); | ||
}, | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
'No Tracking Number': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.last_checkpoint('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.last_checkpoint('ups'), 'Missing Required Parameter: tracking number'); | ||
test.done(); | ||
}, | ||
'No Callback (no fields)': function(test) { | ||
test.expect(1); | ||
'No Callback (no fields)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.last_checkpoint('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.last_checkpoint('ups', '1234'), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'No Callback (w/ fields)': function(test) { | ||
test.expect(1); | ||
'No Callback (w/ fields)': function(test) { | ||
test.expect(1); | ||
test.equal(Aftership.last_checkpoint('ups', '1234', []), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
test.equal(Aftership.last_checkpoint('ups', '1234', []), 'Missing Required Parameter: callback'); | ||
test.done(); | ||
}, | ||
'Ok': function(test) { | ||
test.expect(3); | ||
'Ok with fields': function(test) { | ||
test.expect(4); | ||
// UPS | ||
Aftership.last_checkpoint('ups', GLOBAL.tracking.ups, null, function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.checkpoint, 'object'); | ||
test.equal(typeof result.checkpoint.tag, 'string'); | ||
// 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'); | ||
test.done(); | ||
}); | ||
} | ||
test.done(); | ||
}); | ||
}, | ||
'Ok': function(test) { | ||
test.expect(2); | ||
// UPS | ||
Aftership.last_checkpoint('ups', GLOBAL.tracking.ups, [], function(err, result) { | ||
test.equal(err, null); | ||
test.equal(typeof result.checkpoint, 'object'); | ||
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
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
30723
0
797
7
253
- Removedunderscore@latest
- Removedunderscore@1.13.7(transitive)