Skip to content

Commit

Permalink
Test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmwhitehead committed Jul 3, 2019
1 parent 566178f commit e7a184f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
14 changes: 7 additions & 7 deletions carriers/usps.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ function USPS(options) {
}

parser.parseString(res.body, function(err, data) {
const results = {
events: []
};

if (err) {
return callback(err);
} else if (data.Error) {
// Invalid credentials
// Invalid credentials or Invalid Tracking Number
return callback(new Error(data.Error.Description[0]));
} else if (data.TrackResponse.TrackInfo[0].Error) {
// Invalid tracking number
return callback(new Error(data.TrackResponse.TrackInfo[0].Error[0].Description[0]));
// No Tracking Information
return callback(null, results);
}

const results = {
events: []
};

const scanDetailsList = [];

// TrackSummary[0] exists for every item (with valid tracking number)
Expand Down
24 changes: 21 additions & 3 deletions test/carriers/usps.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,24 @@ describe('USPS', function () {
done();
});
});

it('should return an error for a tracking number that contains invalid characters', function (done) {
bloodhound.track('12c &^trackf0', 'usps', function (err) {
assert(err);
done();
})
})
});

describe('USPS Tracking', function () {
it('should return an error for an invalid tracking number', function (done) {
bloodhound.track('An Invalid Tracking Number', 'usps', function (err) {
assert(err);
it.only('should return an empty result if there is no tracking information available ', function (done) {
bloodhound.track('0987654321234567890', 'usps', function (err, actual) {
const expected = {
events: []
}

assert.ifError(err);
assert.deepStrictEqual(actual, expected);
done();
});
});
Expand Down Expand Up @@ -196,5 +208,11 @@ describe('USPS', function () {
done();
});
});
it('should skip Track Details that do no have time stamps', function (done) {
bloodhound.track('9400110200830244685403', 'usps', function (err) {
assert.ifError(err);
done();
});
})
});
});

0 comments on commit e7a184f

Please sign in to comment.