Permalink
Browse files

Added more tests for when response is minimal

  • Loading branch information...
1 parent 9c8429c commit 93219faae9fcdf141ee8a20eefa3bd1d6c1bb6fc @jkeen committed Mar 20, 2013
@@ -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"]
@@ -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
)
@@ -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>
@@ -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

0 comments on commit 93219fa

Please sign in to comment.