Skip to content

Commit

Permalink
Merge 5fbf427 into 9d3c76d
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmwhitehead committed Jul 3, 2019
2 parents 9d3c76d + 5fbf427 commit e1bdf3d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
18 changes: 17 additions & 1 deletion carriers/pitneyBowes.js
Expand Up @@ -2,13 +2,21 @@ const async = require('async');
const moment = require('moment-timezone');
const PitneyBowesClient = require('pitney-bowes');

// These tracking status codes indicate the shipment was delivered
const DELIVERED_TRACKING_STATUS_CODES = ['01'];

// These tracking status codes indicate the shipment was shipped (shows movement beyond a shipping label being created)
const SHIPPED_TRACKING_STATUS_CODES = ['02', '07', '10', '14', '30', '81', '82', 'AD', 'OF', 'PC'];

const geography = require('../util/geography');

function PitneyBowes(options) {
const pitneyBowesClient = new PitneyBowesClient(options);

this.track = function(trackingNumber, callback) {
pitneyBowesClient.tracking({ trackingNumber }, function(err, data) {
async.retry(function(callback) {
pitneyBowesClient.tracking({ trackingNumber }, callback);
}, function(err, data) {
if (err) {
return callback(err);
}
Expand Down Expand Up @@ -62,6 +70,14 @@ function PitneyBowes(options) {
description: scanDetail.scanDescription
};

if (DELIVERED_TRACKING_STATUS_CODES.includes(scanDetail.scanType)) {
results.deliveredAt = new Date(event.date);
}

if (SHIPPED_TRACKING_STATUS_CODES.includes(scanDetail.scanType)) {
results.shippedAt = new Date(event.date);
}

// Use the city and state from the parsed address (for scenarios where the city includes the state like "New York, NY")
if (address) {
if (address.city) {
Expand Down
2 changes: 1 addition & 1 deletion carriers/usps.js
Expand Up @@ -12,7 +12,7 @@ const CITY_BLACKLIST = /DISTRIBUTION CENTER|NETWORK DISTRIBUTION CENTER/ig;
const DELIVERED_TRACKING_STATUS_CODES = ['01'];

// These tracking status codes indicate the shipment was shipped (shows movement beyond a shipping label being created): https://about.usps.com/publications/pub97/pub97_appi.htm
const SHIPPED_TRACKING_STATUS_CODES = ['02', '07', '10', '14', 'OF', 'PC'];
const SHIPPED_TRACKING_STATUS_CODES = ['02', '07', '10', '14', '30', '81', '82', 'AD', 'OF', 'PC'];

// The events from these tracking status codes are filtered because they do not provide any useful information: https://about.usps.com/publications/pub97/pub97_appi.htm
const TRACKING_STATUS_CODES_BLACKLIST = ['NT'];
Expand Down
17 changes: 16 additions & 1 deletion test/carriers/pitneyBowes.js
Expand Up @@ -5,6 +5,19 @@ const Bloodhound = require('../../index.js');
describe('Newgistics', function() {
this.timeout(10000);

it('should return an error for invalid base URL', function(done) {
const bloodhound = new Bloodhound({
pitneyBowes: {
baseUrl: 'https://httpbin.org/status/500#'
}
});

bloodhound.track('9400111899223837861141', 'newgistics', function(err) {
assert(err);
done();
});
});

it('4206336792748927005269000010615207', function(done) {
const bloodhound = new Bloodhound({
pitneyBowes: {
Expand Down Expand Up @@ -118,7 +131,9 @@ describe('Newgistics', function() {
date: new Date('2019-06-25T13:09:00.000Z'),
description: 'Picked Up by Shipping Partner, USPS Awaiting Item'
}
]
],
deliveredAt: new Date('2019-06-30T18:03:00.000Z'),
shippedAt: new Date('2019-06-28T21:43:00.000Z')
};

assert.deepStrictEqual(actual, expected);
Expand Down
2 changes: 1 addition & 1 deletion test/carriers/usps.js
Expand Up @@ -232,7 +232,7 @@ describe('USPS', function () {
}
],
deliveredAt: new Date('2019-07-01T19:25:00.000Z'),
shippedAt: new Date('2019-06-30T22:02:00.000Z')
shippedAt: new Date('2019-06-29T02:26:00.000Z')
}

assert.deepStrictEqual(actual, expected);
Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Expand Up @@ -3,6 +3,8 @@ const assert = require('assert');
const Bloodhound = require('../index.js');

describe('Error handling', function() {
this.timeout(10000);

const bloodhound = new Bloodhound({
fedEx: {
account_number: process.env.FEDEX_ACCOUNT_NUMBER,
Expand Down

0 comments on commit e1bdf3d

Please sign in to comment.