Skip to content

Commit

Permalink
added additional regular expressions to the fedex service; fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
travishaynes committed Aug 21, 2014
1 parent 1c8fd4c commit 1f07d67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 8 additions & 2 deletions lib/trackerific/services/fedex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ class Trackerific::Services::FedEx < Trackerific::Services::Base
config.track_operation = :track
config.builder = Trackerific::Builders::FedEx
config.parser = Trackerific::Parsers::FedEx
config.wsdl = 'fedex/TrackService_v8'
config.package_id_matchers = [ /^[0-9]{15}$/ ]
config.wsdl = 'fedex/TrackService_v9'
config.package_id_matchers = [
/\b96\d{20}\b/ ,
/\b\d{15}\b/ ,
/\b\d{12}\b/ ,
/\b((98\d{5}?\d{3}|98\d{2}) ?\d{4} ?\d{4}( ?\d{2})?)\b/ ,
]
end
end

20 changes: 16 additions & 4 deletions spec/lib/trackerific/services/fedex_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
describe Trackerific::Services::FedEx do
include Savon::SpecHelper

let(:valid_ids) { ["183689015000001", "999999999999999"] }
let(:invalid_ids) { %w[these are not valid tracking ids] }
let(:valid_ids) {
[ "123456789012", "123456789012345", "9612345678901234567890",
"98123456 1234 1234", "9812 1234 1234", "98123456 1234 1234 123",
"9812 1234 1234 123" ]
}

it "should match valid tracking ids" do
let(:invalid_ids) {
[ "1234567890123456", "1234567890", "96123456789012345678901",
"961234567890123456789", "9812345 1234 1234", "981234567 1234 1234",
"981 1234 1234", "98123 1234 1234", "981234567 1234 1234 123",
"9812345 1234 1234 123", "981 1234 1234 123", "98123 1234 1234 123",
"1Z12345E0291980793", "EJ958083578US", "XXXXXXXXXX" ]
}

it "should match valid tracking ids", :wip do
valid_ids.all? {|id| described_class.can_track?(id) }.should be_true
end

it "should not match invalid tracking ids" do
it "should not match invalid tracking ids", :wip do
invalid_ids.all? {|id| described_class.can_track?(id) }.should be_false
end

Expand Down Expand Up @@ -69,3 +80,4 @@
end
end
end

0 comments on commit 1f07d67

Please sign in to comment.