Skip to content

Commit

Permalink
Filtered out "Picked Up" events because their timestamps are nonsensical
Browse files Browse the repository at this point in the history
  • Loading branch information
freshlogic committed Jun 26, 2019
1 parent 9d01b58 commit c0aa37c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 187 deletions.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ const PitneyBowes = require('pitney-bowes');
// Remove these words from cities to turn cities like `FEDEX SMARTPOST INDIANAPOLIS` into `INDIANAPOLIS`
const CITY_BLACKLIST = /fedex|smartpost/ig;

// https://www.fedex.com/us/developer/webhelp/ws/2018/US/index.htm#t=wsdvg%2FTracking_Shipments.htm%23Tracking_Statusbc-5&rhtocid=_26_0_4
// These tracking status codes indicate the shipment was delivered: https://www.fedex.com/us/developer/webhelp/ws/2018/US/index.htm#t=wsdvg%2FTracking_Shipments.htm%23Tracking_Statusbc-5&rhtocid=_26_0_4
const FEDEX_DELIVERED_TRACKING_STATUS_CODES = ['DL'];

// These tracking status codes indicate the shipment was shipped (shows movement beyond a shipping label being created): https://www.fedex.com/us/developer/webhelp/ws/2018/US/index.htm#t=wsdvg%2FTracking_Shipments.htm%23Tracking_Statusbc-5&rhtocid=_26_0_4
const FEDEX_SHIPPED_TRACKING_STATUS_CODES = ['AR', 'DP', 'IT', 'OD'];

// The events from these tracking status codes are filtered because their timestamps are nonsensical: https://www.fedex.com/us/developer/webhelp/ws/2018/US/index.htm#t=wsdvg%2FTracking_Shipments.htm%23Tracking_Statusbc-5&rhtocid=_26_0_4
const FEDEX_TRACKING_STATUS_CODES_BLACKLIST = ['PU', 'PX'];

function Bloodhound(options) {
const fedEx = new FedEx(options && options.fedEx);
const pitneyBowes = new PitneyBowes(options && options.pitneyBowes);
Expand Down Expand Up @@ -55,6 +60,10 @@ function Bloodhound(options) {
}

trackReply.CompletedTrackDetails[0].TrackDetails[0].Events.forEach(e => {
if (FEDEX_TRACKING_STATUS_CODES_BLACKLIST.includes(e.EventType)) {
return;
}

if (FEDEX_DELIVERED_TRACKING_STATUS_CODES.includes(e.EventType)) {
results.deliveredAt = new Date(e.Timestamp);
}
Expand Down
189 changes: 3 additions & 186 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ describe('FedEx', function() {

const expected = {
events: [
{
date: new Date('2014-01-06T15:18:00.000Z'),
description: 'Picked up',
address: {
city: 'FLORENCE',
country: 'US',
state: 'SC',
zip: '29506'
}
},
{
date: new Date('2014-01-03T22:58:00.000Z'),
description: 'Shipment information sent to FedEx',
Expand Down Expand Up @@ -146,8 +136,7 @@ describe('FedEx', function() {
});
});

// Skipping this test because FedEx returns time in a different timezone for the "Picked Up" event
it.skip('At local FedEx facility', function(done) {
it('At local FedEx facility', function(done) {
bloodhound.track('920241085725456', 'fedex', function(err, actual) {
assert.ifError(err);

Expand Down Expand Up @@ -212,16 +201,6 @@ describe('FedEx', function() {
state: undefined,
zip: '27260'
}
},
{
date: new Date('2014-01-03T06:00:00.000Z'),
description: 'Picked up',
address: {
city: 'KERNERSVILLE',
country: 'US',
state: 'NC',
zip: '27284'
}
}
],
shippedAt: new Date('2014-01-03T22:09:00.000Z')
Expand Down Expand Up @@ -277,16 +256,6 @@ describe('FedEx', function() {
state: 'TN',
zip: '38118'
}
},
{
date: new Date('2014-01-05T17:31:00.000Z'),
description: 'Picked up',
address: {
city: 'MEMPHIS',
country: 'US',
state: 'TN',
zip: '38185'
}
}
],
shippedAt: new Date('2014-01-06T01:23:00.000Z')
Expand Down Expand Up @@ -323,16 +292,6 @@ describe('FedEx', function() {
zip: '55115'
}
},
{
date: new Date('2014-01-07T00:41:00.000Z'),
description: 'Picked up',
address: {
city: 'SAINT PAUL',
country: 'US',
state: 'MN',
zip: '55115'
}
},
{
date: new Date('2014-01-05T20:40:00.000Z'),
description: 'Shipment information sent to FedEx',
Expand Down Expand Up @@ -448,16 +407,6 @@ describe('FedEx', function() {
zip: '67226'
}
},
{
date: new Date('2013-12-31T21:21:00.000Z'),
description: 'Picked up',
address: {
city: 'WICHITA',
country: 'US',
state: 'KS',
zip: '67226'
}
},
{
date: new Date('2013-12-31T18:58:00.000Z'),
description: 'Shipment information sent to FedEx',
Expand Down Expand Up @@ -563,16 +512,6 @@ describe('FedEx', function() {
zip: '20098'
}
},
{
date: new Date('2014-02-04T16:27:00.000Z'),
description: 'Picked up',
address: {
city: 'SESTO ULTERIANO',
country: 'IT',
state: undefined,
zip: '20098'
}
},
{
date: new Date('2014-02-04T09:58:46.000Z'),
description: 'Shipment information sent to FedEx',
Expand Down Expand Up @@ -679,16 +618,6 @@ describe('FedEx', function() {
zip: '43123'
}
},
{
date: new Date('2013-12-12T19:39:00.000Z'),
description: 'Picked up',
address: {
city: 'COLUMBUS',
country: 'US',
state: 'OH',
zip: '43213'
}
},
{
date: new Date('2013-12-11T13:14:00.000Z'),
description: 'Shipment information sent to FedEx',
Expand All @@ -708,8 +637,7 @@ describe('FedEx', function() {
});
});

// Skipping this test because FedEx returns time in a different timezone for the "Picked Up" event
it.skip('Local Delivery Restriction (Delivery Exception 083)', function(done) {
it('Local Delivery Restriction (Delivery Exception 083)', function(done) {
bloodhound.track('852426136339213', 'fedex', function(err, actual) {
assert.ifError(err);

Expand Down Expand Up @@ -796,16 +724,6 @@ describe('FedEx', function() {
zip: '92154'
}
},
{
date: new Date('2013-12-19T02:23:00.000Z'),
description: 'Picked up',
address: {
city: 'SAN DIEGO',
country: 'US',
state: 'CA',
zip: '92154'
}
},
{
date: new Date('2013-12-18T05:10:00.000Z'),
description: 'In FedEx possession',
Expand Down Expand Up @@ -913,16 +831,6 @@ describe('FedEx', function() {
zip: '33172'
}
},
{
date: new Date('2014-01-13T23:00:00.000Z'),
description: 'Picked up',
address: {
city: 'MIAMI',
country: 'US',
state: 'FL',
zip: '33172'
}
},
{
date: new Date('2014-01-13T15:42:39.000Z'),
description: 'Shipment information sent to FedEx',
Expand Down Expand Up @@ -999,16 +907,6 @@ describe('FedEx', function() {
zip: '78744'
}
},
{
date: new Date('2014-01-28T01:13:00.000Z'),
description: 'Picked up',
address: {
city: 'AUSTIN',
country: 'US',
state: 'TX',
zip: '78744'
}
},
{
date: new Date('2014-01-28T00:10:00.000Z'),
description: 'In FedEx possession',
Expand Down Expand Up @@ -1167,16 +1065,6 @@ describe('FedEx', function() {
zip: '33634'
}
},
{
date: new Date('2014-01-10T21:11:00.000Z'),
description: 'Picked up',
address: {
city: 'TAMPA',
country: 'US',
state: 'FL',
zip: '33634'
}
},
{
date: new Date('2014-01-10T20:25:00.000Z'),
description: 'Shipment information sent to FedEx',
Expand Down Expand Up @@ -1304,16 +1192,6 @@ describe('FedEx', function() {
state: 'OH',
zip: '45140'
}
},
{
date: new Date('2014-02-04T21:09:00.000Z'),
description: 'Picked up',
address: {
city: 'LOVELAND',
country: 'US',
state: 'OH',
zip: '45140'
}
}
],
shippedAt: new Date('2014-02-05T02:30:00.000Z')
Expand Down Expand Up @@ -1421,16 +1299,6 @@ describe('FedEx', function() {
zip: '99216'
}
},
{
date: new Date('2014-01-03T23:00:00.000Z'),
description: 'Picked up',
address: {
city: 'SPOKANE',
country: 'US',
state: 'WA',
zip: '99216'
}
},
{
date: new Date('2014-01-03T22:31:00.000Z'),
description: 'Shipment information sent to FedEx',
Expand Down Expand Up @@ -1633,16 +1501,6 @@ describe('FedEx', function() {
state: 'TN',
zip: '37207'
}
},
{
date: new Date('2013-12-27T02:59:00.000Z'),
description: 'Picked up',
address: {
city: 'NASHVILLE',
country: 'US',
state: 'TN',
zip: '37207'
}
}
],
shippedAt: new Date('2013-12-27T06:42:00.000Z')
Expand Down Expand Up @@ -1975,18 +1833,7 @@ describe('FedEx', function() {
assert.ifError(err);

const expected = {
events: [
{
date: new Date('2015-02-26T16:20:25.000Z'),
description: 'Picked up',
address: {
city: 'ALLENTOWN',
country: 'US',
state: 'PA',
zip: '18101'
}
}
]
events: []
};

assert.deepStrictEqual(actual, expected);
Expand Down Expand Up @@ -2019,16 +1866,6 @@ describe('FedEx', function() {
state: 'IA',
zip: '50313'
}
},
{
date: new Date('2015-03-19T17:17:38.000Z'),
description: 'Picked up',
address: {
city: 'MACKSBURG',
country: 'US',
state: 'IA',
zip: '50155'
}
}
],
shippedAt: new Date('2015-03-20T14:55:00.000Z')
Expand Down Expand Up @@ -2096,16 +1933,6 @@ describe('FedEx', function() {
state: 'OH',
zip: '45390'
}
},
{
date: new Date('2015-02-26T16:13:39.000Z'),
description: 'Picked up',
address: {
city: 'TROY',
country: 'US',
state: 'OH',
zip: '45373'
}
}
],
shippedAt: new Date('2015-02-27T13:30:00.000Z')
Expand Down Expand Up @@ -2194,16 +2021,6 @@ describe('FedEx', function() {
state: 'WI',
zip: '54301'
}
},
{
date: new Date('2015-02-26T18:02:02.000Z'),
description: 'Picked up',
address: {
city: 'MENOMINEE',
country: 'US',
state: 'MI',
zip: '49858'
}
}
],
deliveredAt: new Date('2015-03-02T17:25:25.000Z'),
Expand Down

0 comments on commit c0aa37c

Please sign in to comment.