Skip to content

Commit

Permalink
updates to pitney-bowes and petty-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
antman10001 committed Aug 8, 2019
1 parent ccbf7a9 commit f0ff61d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 31 deletions.
11 changes: 6 additions & 5 deletions carriers/pitneyBowes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const PitneyBowesClient = require('pitney-bowes');
const CITY_BLACKLIST = /DISTRIBUTION CENTER|INTERNATIONAL DISTRIBUTION CENTER|NETWORK DISTRIBUTION CENTER/ig;

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

// 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 SHIPPED_TRACKING_STATUS_CODES = ['02', '07', '10', '14', '30', '81', '82', 'ACF', 'AD', 'ADU', 'DCF', 'IPS', 'OF', 'OFD', 'PC'];

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

Expand All @@ -18,7 +18,7 @@ function PitneyBowes(options) {

this.track = function(trackingNumber, callback) {
async.retry(function(callback) {
pitneyBowesClient.tracking({ trackingNumber }, callback);
pitneyBowesClient.tracking({ carrier: 'FDR', trackingNumber }, callback);
}, function(err, data) {
if (err) {
return callback(err);
Expand Down Expand Up @@ -73,7 +73,7 @@ function PitneyBowes(options) {
return callback(err);
}

data.scanDetailsList.forEach(scanDetail => {
data.scanDetailsList.reverse().forEach(scanDetail => {
const address = addresses.find(a => a && a.location === scanDetail.location);
let timezone = 'America/New_York';

Expand All @@ -92,6 +92,7 @@ function PitneyBowes(options) {
}

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

Expand All @@ -115,7 +116,7 @@ function PitneyBowes(options) {
if (!results.shippedAt && results.deliveredAt) {
results.shippedAt = results.deliveredAt;
}

results.events = results.events.reverse();
callback(null, results);
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"moment-timezone": "~0.5.25",
"node-geocoder": "~3.23.0",
"petty-cache": "^2.4.1",
"pitney-bowes": "~0.1.0",
"pitney-bowes": "~0.1.1",
"shipping-fedex": "0.2.0",
"tz-lookup": "~6.1.18",
"us-states-normalize": "~1.0.0"
Expand Down
100 changes: 75 additions & 25 deletions test/carriers/pitneyBowes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe('Newgistics', function() {
state: 'CA',
zip: null
},
date: new Date('2019-07-19T20:57:00.000Z'),
description: 'Delivered, Front Door/Porch'
date: new Date('2019-07-19T22:57:00.000Z'),
description: 'Delivered'
},
{
address: {
Expand All @@ -51,12 +51,12 @@ describe('Newgistics', function() {
zip: null
},
date: new Date('2019-07-10T16:08:00.000Z'),
description: 'Picked Up by Shipping Partner, USPS Awaiting Item'
description: 'Electronic Shipping Info Received'
}
],
deliveredAt: new Date('2019-07-19T20:57:00.000Z'),
deliveredAt: new Date('2019-07-19T22:57:00.000Z'),
url: 'https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=4207866492612927005269000029964826',
shippedAt: new Date('2019-07-19T20:57:00.000Z')
shippedAt: new Date('2019-07-19T22:57:00.000Z')
}

assert.deepStrictEqual(actual, expected);
Expand Down Expand Up @@ -85,8 +85,8 @@ describe('Newgistics', function() {
state: 'OH',
zip: null
},
date: new Date('2019-06-22T14:59:00.000Z'),
description: 'Moved, Left no Address'
date: new Date('2019-06-22T13:59:00.000Z'),
description: 'Return to Sender because the addressee moved and left no forwarding address'
},
{
address: {
Expand All @@ -95,8 +95,8 @@ describe('Newgistics', function() {
state: 'OH',
zip: null
},
date: new Date('2019-06-22T14:59:00.000Z'),
description: 'Return to Sender Processed'
date: new Date('2019-06-21T19:47:00.000Z'),
description: 'Return to Sender due to No such Number'
},
{
address: {
Expand All @@ -105,8 +105,8 @@ describe('Newgistics', function() {
state: 'OH',
zip: null
},
date: new Date('2019-06-21T20:47:00.000Z'),
description: 'No Such Number'
date: new Date('2019-06-21T13:33:00.000Z'),
description: 'Return to Sender because the addressee moved and left no forwarding address'
},
{
address: {
Expand All @@ -115,8 +115,8 @@ describe('Newgistics', function() {
state: 'OH',
zip: null
},
date: new Date('2019-06-21T14:33:00.000Z'),
description: 'Moved, Left no Address'
date: new Date('2019-06-21T11:14:00.000Z'),
description: 'Out for Delivery'
},
{
address: {
Expand All @@ -125,8 +125,8 @@ describe('Newgistics', function() {
state: 'OH',
zip: null
},
date: new Date('2019-06-21T12:14:00.000Z'),
description: 'Out for Delivery'
date: new Date('2019-06-21T11:04:00.000Z'),
description: 'Sorting Complete'
},
{
address: {
Expand All @@ -135,8 +135,8 @@ describe('Newgistics', function() {
state: 'OH',
zip: null
},
date: new Date('2019-06-21T12:04:00.000Z'),
description: 'Sorting Complete'
date: new Date('2019-06-20T14:26:00.000Z'),
description: 'Arrival at Unit'
},
{
address: {
Expand All @@ -145,8 +145,8 @@ describe('Newgistics', function() {
state: 'OH',
zip: null
},
date: new Date('2019-06-20T15:26:00.000Z'),
description: 'Arrived at Post Office'
date: new Date('2019-06-20T05:53:00.000Z'),
description: 'Pre-Shipment Info Sent to USPS, USPS Awaiting Item'
},
{
address: {
Expand All @@ -156,7 +156,17 @@ describe('Newgistics', function() {
zip: null
},
date: new Date('2019-06-20T05:44:00.000Z'),
description: 'Departed Shipping Partner Facility, USPS Awaiting Item'
description: 'In transit'
},
{
address: {
city: 'Hebron',
country: null,
state: 'KY',
zip: null
},
date: new Date('2019-06-20T05:27:00.000Z'),
description: 'In transit'
},
{
address: {
Expand All @@ -166,7 +176,27 @@ describe('Newgistics', function() {
zip: null
},
date: new Date('2019-06-19T18:12:00.000Z'),
description: 'Arrived Shipping Partner Facility, USPS Awaiting Item'
description: 'In transit'
},
{
address: {
city: 'Hebron',
country: null,
state: 'KY',
zip: null
},
date: new Date('2019-06-19T11:47:00.000Z'),
description: 'Estimated Delivery'
},
{
address: {
city: 'Hebron',
country: null,
state: 'KY',
zip: null
},
date: new Date('2019-06-19T09:05:00.000Z'),
description: 'Delivered to Partner Facility'
},
{
address: {
Expand All @@ -176,7 +206,27 @@ describe('Newgistics', function() {
zip: null
},
date: new Date('2019-06-18T23:24:00.000Z'),
description: 'Departed Shipping Partner Facility, USPS Awaiting Item'
description: 'In transit'
},
{
address: {
city: 'Grapevine',
country: null,
state: 'TX',
zip: null
},
date: new Date('2019-06-18T17:38:00.000Z'),
description: 'Enroute Processed'
},
{
address: {
city: 'Grapevine',
country: null,
state: 'TX',
zip: null
},
date: new Date('2019-06-18T17:23:00.000Z'),
description: 'Arrived at Pick-up Location'
},
{
address: {
Expand All @@ -186,7 +236,7 @@ describe('Newgistics', function() {
zip: null
},
date: new Date('2019-06-18T14:44:00.000Z'),
description: 'Arrived Shipping Partner Facility, USPS Awaiting Item'
description: 'Arrived at Shipping Facility'
},
{
address: {
Expand All @@ -196,10 +246,10 @@ describe('Newgistics', function() {
zip: null
},
date: new Date('2019-06-17T12:07:00.000Z'),
description: 'Picked Up by Shipping Partner, USPS Awaiting Item'
description: 'Electronic Shipping Info Received'
}
],
shippedAt: new Date('2019-06-18T14:44:00.000Z'),
shippedAt: new Date('2019-06-21T11:14:00.000Z'),
url: 'https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=4204540992748927005269000020006828'
};
assert.deepStrictEqual(actual, expected);
Expand Down
1 change: 1 addition & 0 deletions test/util/geography.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ describe('petty-cache', function() {

const expected = {
city: 'Carrollton',
location: 'Carrollton, TX',
state: 'TX',
timezone: 'America/Chicago'
};
Expand Down

0 comments on commit f0ff61d

Please sign in to comment.