Skip to content

Commit

Permalink
Added more tests for when response is minimal
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeen committed Mar 20, 2013
1 parent 9c8429c commit 93219fa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
18 changes: 16 additions & 2 deletions lib/trackerific/services/fedex.rb
Expand Up @@ -48,6 +48,7 @@ def track_package(package_id)
details = track_reply["Package"]
# convert them into Trackerific::Events
events = []

[details["Event"]].flatten.each do |e|
date = Time.parse("#{e["Date"]} #{e["Time"]}")
desc = e["Description"]
Expand All @@ -58,11 +59,24 @@ def track_package(package_id)
:location => Trackerific::Location.new(:city => addr["City"], :state => addr["StateOrProvinceCode"], :country => addr["CountryCode"], :postal_code => addr["PostalCode"])
)
end

# this isn't always provided
origin = Trackerific::Location.new(
:city => details["OriginLocationAddress"]["City"],
:state => details["OriginLocationAddress"]["StateOrProvinceCode"],
:country => details["OriginLocationAddress"]["CountryCode"]) if details["OriginLocationAddress"]

destination = Trackerific::Location.new(
:city => details["DestinationAddress"]["City"],
:state => details["DestinationAddress"]["StateOrProvinceCode"],
:country => details["DestinationAddress"]["CountryCode"]) if details["DestinationAddress"]


# Return a Trackerific::Details containing all the events
Trackerific::Details.new(
:package_id => details["TrackingNumber"],
:origin => Trackerific::Location.new(:city => details["OriginLocationAddress"]["City"], :state => details["OriginLocationAddress"]["StateOrProvinceCode"], :country => details["OriginLocationAddress"]["CountryCode"]),
:destination => Trackerific::Location.new(:city => details["DestinationAddress"]["City"], :state => details["DestinationAddress"]["StateOrProvinceCode"], :country => details["DestinationAddress"]["CountryCode"]),
:origin => origin,
:destination => destination,
:summary => details["StatusDescription"],
:events => events
)
Expand Down
Expand Up @@ -18,11 +18,6 @@
<PackagingDescription>Package</PackagingDescription>
<PackageSequenceNumber>1</PackageSequenceNumber>
<PackageCount>1</PackageCount>
<OriginLocationAddress>
<City>ANAHEIM</City>
<StateOrProvinceCode>CA</StateOrProvinceCode>
<CountryCode>US</CountryCode>
</OriginLocationAddress>
<ShipDate>2010-06-25</ShipDate>
<DestinationAddress>
<City>Gainesville</City>
Expand Down
23 changes: 20 additions & 3 deletions spec/lib/trackerific/services/fedex_spec.rb
Expand Up @@ -70,17 +70,34 @@
end
end

context "with a successful response with only one event" do
context "with a successful response with minimal data" do
before(:all) do
FakeWeb.register_uri(:post, FEDEX_TRACK_URL, :body => load_fixture(:fedex_success_response_single_event))
FakeWeb.register_uri(:post, FEDEX_TRACK_URL, :body => load_fixture(:fedex_success_response_minimal))
end

before(:each) do
@tracking = @fedex.track_package(@package_id)
end

subject { @tracking }
subject { @tracking }
# this response only has one event
it("should return a Trackerific::Details") { should be_a Trackerific::Details }

describe "events.length" do
subject { @tracking.events.length }
it { should == 1}
end

describe "origin" do
subject { @tracking.origin }
it("should return nil") { should be_nil }
end

describe "destination" do
subject { @tracking.destination }
it("should return a Trackerific::Location") { should be_a Trackerific::Location }
end

end


Expand Down

0 comments on commit 93219fa

Please sign in to comment.