active_shipping 1.0.0.pre2 → 1.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gitignore +12 -0
  5. data/.travis.yml +14 -0
  6. data/.yardopts +14 -0
  7. data/Gemfile +3 -0
  8. data/Gemfile.activesupport32 +4 -0
  9. data/Gemfile.activesupport40 +4 -0
  10. data/Gemfile.activesupport41 +4 -0
  11. data/Gemfile.activesupport42 +4 -0
  12. data/Rakefile +23 -0
  13. data/active_shipping.gemspec +32 -0
  14. data/lib/active_shipping.rb +1 -1
  15. data/lib/active_shipping/carrier.rb +1 -1
  16. data/lib/active_shipping/carriers/shipwire.rb +32 -35
  17. data/lib/active_shipping/carriers/ups.rb +2 -2
  18. data/lib/active_shipping/carriers/usps.rb +103 -101
  19. data/lib/active_shipping/label_response.rb +1 -1
  20. data/lib/active_shipping/rate_estimate.rb +76 -15
  21. data/lib/active_shipping/rate_response.rb +20 -0
  22. data/lib/active_shipping/response.rb +17 -0
  23. data/lib/active_shipping/shipment_packer.rb +2 -2
  24. data/lib/active_shipping/shipping_response.rb +24 -2
  25. data/lib/active_shipping/tracking_response.rb +65 -17
  26. data/lib/active_shipping/version.rb +1 -1
  27. data/shipit.rubygems.yml +1 -0
  28. data/test/credentials.yml +47 -0
  29. data/test/fixtures/files/label1.pdf +0 -0
  30. data/test/fixtures/files/ups-shipping-label.gif +0 -0
  31. data/test/fixtures/json/newzealandpost/domestic_book.json +1 -0
  32. data/test/fixtures/json/newzealandpost/domestic_default.json +1 -0
  33. data/test/fixtures/json/newzealandpost/domestic_error.json +1 -0
  34. data/test/fixtures/json/newzealandpost/domestic_poster.json +1 -0
  35. data/test/fixtures/json/newzealandpost/domestic_small_half_pound.json +1 -0
  36. data/test/fixtures/json/newzealandpost/international_book.json +1 -0
  37. data/test/fixtures/json/newzealandpost/international_new_zealand_wii.json +1 -0
  38. data/test/fixtures/json/newzealandpost/international_small_half_pound.json +1 -0
  39. data/test/fixtures/json/newzealandpost/international_wii.json +1 -0
  40. data/test/fixtures/xml/canadapost/example_request.xml +25 -0
  41. data/test/fixtures/xml/canadapost/example_response.xml +130 -0
  42. data/test/fixtures/xml/canadapost/example_response_error.xml +16 -0
  43. data/test/fixtures/xml/canadapost/example_response_french.xml +122 -0
  44. data/test/fixtures/xml/canadapost/example_response_with_nil_value.xml +164 -0
  45. data/test/fixtures/xml/canadapost/example_response_with_postal_outlet.xml +155 -0
  46. data/test/fixtures/xml/canadapost/example_response_with_postal_outlet_french.xml +274 -0
  47. data/test/fixtures/xml/canadapost/example_response_with_strange_delivery_date.xml +130 -0
  48. data/test/fixtures/xml/canadapost_pws/dnc_tracking_details_en.xml +112 -0
  49. data/test/fixtures/xml/canadapost_pws/merchant_details_error.xml +7 -0
  50. data/test/fixtures/xml/canadapost_pws/merchant_details_response.xml +7 -0
  51. data/test/fixtures/xml/canadapost_pws/option_response.xml +13 -0
  52. data/test/fixtures/xml/canadapost_pws/option_response_no_conflicts.xml +7 -0
  53. data/test/fixtures/xml/canadapost_pws/rates_info.xml +190 -0
  54. data/test/fixtures/xml/canadapost_pws/rates_info_error.xml +7 -0
  55. data/test/fixtures/xml/canadapost_pws/receipt_response.xml +42 -0
  56. data/test/fixtures/xml/canadapost_pws/receipt_response_no_priced_options.xml +36 -0
  57. data/test/fixtures/xml/canadapost_pws/register_token_error.xml +7 -0
  58. data/test/fixtures/xml/canadapost_pws/register_token_response.xml +3 -0
  59. data/test/fixtures/xml/canadapost_pws/service_options_response.xml +42 -0
  60. data/test/fixtures/xml/canadapost_pws/services_error.xml +6 -0
  61. data/test/fixtures/xml/canadapost_pws/services_response.xml +32 -0
  62. data/test/fixtures/xml/canadapost_pws/shipment_domestic.xml +69 -0
  63. data/test/fixtures/xml/canadapost_pws/shipment_response.xml +20 -0
  64. data/test/fixtures/xml/canadapost_pws/shipment_us.xml +69 -0
  65. data/test/fixtures/xml/canadapost_pws/tracking_details_en.xml +152 -0
  66. data/test/fixtures/xml/canadapost_pws/tracking_details_en_error.xml +7 -0
  67. data/test/fixtures/xml/canadapost_pws/tracking_details_en_undelivered.xml +116 -0
  68. data/test/fixtures/xml/canadapost_pws/tracking_details_fr.xml +156 -0
  69. data/test/fixtures/xml/canadapost_pws/tracking_details_no_expected_delivery_date.xml +40 -0
  70. data/test/fixtures/xml/fedex/freight_rate_request.xml +82 -0
  71. data/test/fixtures/xml/fedex/freight_rate_response.xml +506 -0
  72. data/test/fixtures/xml/fedex/invalid_fedex_reply.xml +27 -0
  73. data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_commercial_rate_request.xml +79 -0
  74. data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_request.xml +80 -0
  75. data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_response.xml +214 -0
  76. data/test/fixtures/xml/fedex/raterequest_reply.xml +213 -0
  77. data/test/fixtures/xml/fedex/reply_without_notifications.xml +185 -0
  78. data/test/fixtures/xml/fedex/tracking_request.xml +27 -0
  79. data/test/fixtures/xml/fedex/tracking_response.xml +151 -0
  80. data/test/fixtures/xml/fedex/tracking_response_empty_destination.xml +76 -0
  81. data/test/fixtures/xml/fedex/tracking_response_no_destination.xml +139 -0
  82. data/test/fixtures/xml/fedex/tracking_response_no_ship_time.xml +150 -0
  83. data/test/fixtures/xml/fedex/tracking_response_with_estimated_delivery_date.xml +95 -0
  84. data/test/fixtures/xml/fedex/tracking_response_with_shipper_address.xml +71 -0
  85. data/test/fixtures/xml/fedex/unknown_fedex_document_reply.xml +3 -0
  86. data/test/fixtures/xml/kunaki/invalid_state_response.xml +3 -0
  87. data/test/fixtures/xml/kunaki/no_valid_items_response.xml +3 -0
  88. data/test/fixtures/xml/kunaki/successful_rates_response.xml +3 -0
  89. data/test/fixtures/xml/kunaki/unsuccessful_rates_response.xml +9 -0
  90. data/test/fixtures/xml/shipwire/international_rates_response.xml +17 -0
  91. data/test/fixtures/xml/shipwire/new_carrier_rate_response.xml +18 -0
  92. data/test/fixtures/xml/shipwire/no_rates_response.xml +7 -0
  93. data/test/fixtures/xml/shipwire/rates_response.xml +36 -0
  94. data/test/fixtures/xml/shipwire/rates_response_no_estimate.xml +14 -0
  95. data/test/fixtures/xml/stamps/authenticate_user_request.xml +15 -0
  96. data/test/fixtures/xml/stamps/authenticate_user_response.xml +10 -0
  97. data/test/fixtures/xml/stamps/cleanse_address_request.xml +19 -0
  98. data/test/fixtures/xml/stamps/cleanse_address_response.xml +27 -0
  99. data/test/fixtures/xml/stamps/create_indicium_request.xml +69 -0
  100. data/test/fixtures/xml/stamps/create_indicium_response.xml +40 -0
  101. data/test/fixtures/xml/stamps/expired_authenticator_response.xml +15 -0
  102. data/test/fixtures/xml/stamps/get_account_info_request.xml +11 -0
  103. data/test/fixtures/xml/stamps/get_account_info_response.xml +36 -0
  104. data/test/fixtures/xml/stamps/get_purchase_status_request.xml +12 -0
  105. data/test/fixtures/xml/stamps/get_purchase_status_response.xml +16 -0
  106. data/test/fixtures/xml/stamps/get_rates_request.xml +19 -0
  107. data/test/fixtures/xml/stamps/get_rates_response.xml +351 -0
  108. data/test/fixtures/xml/stamps/purchase_postage_request.xml +13 -0
  109. data/test/fixtures/xml/stamps/purchase_postage_response.xml +17 -0
  110. data/test/fixtures/xml/stamps/track_shipment_request.xml +12 -0
  111. data/test/fixtures/xml/stamps/track_shipment_response.xml +45 -0
  112. data/test/fixtures/xml/ups/delivered_shipment_with_refund.xml +290 -0
  113. data/test/fixtures/xml/ups/delivered_shipment_without_events_tracking_response.xml +62 -0
  114. data/test/fixtures/xml/ups/example_tracking_response.xml +53 -0
  115. data/test/fixtures/xml/ups/in_transit_shipment.xml +183 -0
  116. data/test/fixtures/xml/ups/out_for_delivery_shipment.xml +165 -0
  117. data/test/fixtures/xml/ups/shipment_accept_response.xml +42 -0
  118. data/test/fixtures/xml/ups/shipment_confirm_response.xml +33 -0
  119. data/test/fixtures/xml/ups/shipment_from_tiger_direct.xml +222 -0
  120. data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response.xml +1 -0
  121. data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response_with_insured.xml +289 -0
  122. data/test/fixtures/xml/ups/test_real_home_as_residential_destination_with_origin_account_response.xml +311 -0
  123. data/test/fixtures/xml/ups/triple_accept_response.xml +72 -0
  124. data/test/fixtures/xml/ups/triple_confirm_response.xml +32 -0
  125. data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml +2 -0
  126. data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_plus_rate_response.xml +258 -0
  127. data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_rate_response.xml +108 -0
  128. data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_base_rate_response.xml +84 -0
  129. data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_plus_rate_response.xml +212 -0
  130. data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_rate_response.xml +230 -0
  131. data/test/fixtures/xml/usps/delivered_tracking_response.xml +11 -0
  132. data/test/fixtures/xml/usps/first_class_packages_with_invalid_mail_type_response.xml +12 -0
  133. data/test/fixtures/xml/usps/first_class_packages_with_mail_type_response.xml +16 -0
  134. data/test/fixtures/xml/usps/first_class_packages_without_mail_type_response.xml +12 -0
  135. data/test/fixtures/xml/usps/invalid_xml_tracking_response_error.xml +2 -0
  136. data/test/fixtures/xml/usps/tracking_request.xml +3 -0
  137. data/test/fixtures/xml/usps/tracking_response.xml +13 -0
  138. data/test/fixtures/xml/usps/tracking_response_failure.xml +3 -0
  139. data/test/fixtures/xml/usps/tracking_response_not_available.xml +12 -0
  140. data/test/fixtures/xml/usps/tracking_response_test_error.xml +8 -0
  141. data/test/fixtures/xml/usps/us_rate_request.xml +18 -0
  142. data/test/fixtures/xml/usps/world_rate_request_with_value.xml +20 -0
  143. data/test/fixtures/xml/usps/world_rate_request_without_value.xml +20 -0
  144. data/test/remote/canada_post_pws_platform_test.rb +246 -0
  145. data/test/remote/canada_post_pws_test.rb +171 -0
  146. data/test/remote/canada_post_test.rb +53 -0
  147. data/test/remote/fedex_test.rb +216 -0
  148. data/test/remote/kunaki_test.rb +36 -0
  149. data/test/remote/new_zealand_post_test.rb +147 -0
  150. data/test/remote/shipwire_test.rb +82 -0
  151. data/test/remote/stamps_test.rb +394 -0
  152. data/test/remote/ups_test.rb +257 -0
  153. data/test/remote/usps_test.rb +235 -0
  154. data/test/test_helper.rb +220 -0
  155. data/test/unit/carriers/benchmark_test.rb +18 -0
  156. data/test/unit/carriers/canada_post_pws_rating_test.rb +349 -0
  157. data/test/unit/carriers/canada_post_pws_register_test.rb +75 -0
  158. data/test/unit/carriers/canada_post_pws_shipping_test.rb +244 -0
  159. data/test/unit/carriers/canada_post_pws_tracking_test.rb +154 -0
  160. data/test/unit/carriers/canada_post_test.rb +145 -0
  161. data/test/unit/carriers/fedex_test.rb +408 -0
  162. data/test/unit/carriers/kunaki_test.rb +52 -0
  163. data/test/unit/carriers/new_zealand_post_test.rb +174 -0
  164. data/test/unit/carriers/shipwire_test.rb +187 -0
  165. data/test/unit/carriers/stamps_test.rb +241 -0
  166. data/test/unit/carriers/ups_test.rb +311 -0
  167. data/test/unit/carriers/usps_test.rb +484 -0
  168. data/test/unit/carriers_test.rb +17 -0
  169. data/test/unit/label_response_test.rb +15 -0
  170. data/test/unit/location_test.rb +138 -0
  171. data/test/unit/package_test.rb +68 -0
  172. data/test/unit/rate_estimate_test.rb +34 -0
  173. data/test/unit/response_test.rb +14 -0
  174. data/test/unit/shipment_packer_test.rb +174 -0
  175. metadata +331 -35
  176. metadata.gz.sig +0 -0
  177. data/lib/vendor/quantified/MIT-LICENSE +0 -22
  178. data/lib/vendor/quantified/README.markdown +0 -49
  179. data/lib/vendor/quantified/Rakefile +0 -13
  180. data/lib/vendor/quantified/init.rb +0 -0
  181. data/lib/vendor/quantified/lib/quantified.rb +0 -6
  182. data/lib/vendor/quantified/lib/quantified/attribute.rb +0 -211
  183. data/lib/vendor/quantified/lib/quantified/length.rb +0 -20
  184. data/lib/vendor/quantified/lib/quantified/mass.rb +0 -19
  185. data/lib/vendor/quantified/test/length_test.rb +0 -94
  186. data/lib/vendor/quantified/test/mass_test.rb +0 -96
  187. data/lib/vendor/quantified/test/test_helper.rb +0 -19
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0"?>
2
+ <TrackResponse>
3
+ <TrackInfo ID="9361289949034102283511">
4
+ <TrackSummary>Your item was delivered at 2:16 pm on October 12, 2013 in BROOKLYN, NY 11201.</TrackSummary>
5
+ <TrackDetail>Out for Delivery, October 12, 2013, 10:16 am, BROOKLYN, NY 11201</TrackDetail>
6
+ <TrackDetail>Sorting Complete, October 12, 2013, 10:06 am, BROOKLYN, NY 11201</TrackDetail>
7
+ <TrackDetail>Arrival at Post Office, October 12, 2013, 6:32 am, BROOKLYN, NY 11201</TrackDetail>
8
+ <TrackDetail>Acceptance, October 12, 2013, 6:26 am, BROOKLYN, NY 11201</TrackDetail>
9
+ <TrackDetail>Electronic Shipping Info Received, October 12, 2013</TrackDetail>
10
+ </TrackInfo>
11
+ </TrackResponse>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" ?>
2
+ <RateV4Response>
3
+ <Package ID="0">
4
+ <Error>
5
+ <Number>-2147219428</Number>
6
+ <Source>DomesticRatesV4;clsRateV4.ValidateFirstClassMailType;RateEngineV4.ProcessRequest</Source>
7
+ <Description>Invalid First Class Mail Type.</Description>
8
+ <HelpFile/>
9
+ <HelpContext>1000440</HelpContext>
10
+ </Error>
11
+ </Package>
12
+ </RateV4Response>
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" ?>
2
+ <RateV4Response>
3
+ <Package ID="0">
4
+ <ZipOrigination>90210</ZipOrigination>
5
+ <ZipDestination>10017</ZipDestination>
6
+ <Pounds>0</Pounds>
7
+ <Ounces>1.0</Ounces>
8
+ <Size>REGULAR</Size>
9
+ <Machinable>FALSE</Machinable>
10
+ <Zone>8</Zone>
11
+ <Postage CLASSID="0">
12
+ <MailService>First-Class Mail</MailService>
13
+ <Rate>2.07</Rate>
14
+ </Postage>
15
+ </Package>
16
+ </RateV4Response>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" ?>
2
+ <RateV4Response>
3
+ <Package ID="0">
4
+ <Error>
5
+ <Number>-2147219428</Number>
6
+ <Source>DomesticRatesV4;clsRateV4.ValidateFirstClassMailType;RateEngineV4.ProcessRequest</Source>
7
+ <Description>Invalid First Class Mail Type.</Description>
8
+ <HelpFile/>
9
+ <HelpContext>1000440</HelpContext>
10
+ </Error>
11
+ </Package>
12
+ </RateV4Response>
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0"?><Error><Number>-2147219067</Number><Source>;SOLServer.Track2_Respond</Source><Description>Invalid XML A name contained an invalid character.
2
+ </Description><HelpFile></HelpFile><HelpContext></HelpContext></Error>
@@ -0,0 +1,3 @@
1
+ <TrackRequest USERID="xxxxxxxx">
2
+ <TrackID ID="EJ958083578US"></TrackID>
3
+ </TrackRequest>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0"?>
2
+ <TrackResponse>
3
+ <TrackInfo ID="9102901000462189604217">
4
+ <TrackSummary>Your item is out for delivery at 8:13 am on January 27, 2012 in DES MOINES, IA 50311.</TrackSummary>
5
+ <TrackDetail>Sorting Complete, January 27, 2012, 8:03 am, DES MOINES, IA 50311</TrackDetail>
6
+ <TrackDetail>Electronic Shipping Info Received, January 27, 2012</TrackDetail>
7
+ <TrackDetail>Arrival at Post Office, January 26, 2012, 11:21 am, DES MOINES, IA 50311</TrackDetail>
8
+ <TrackDetail>Departed Shipping Partner Facility, January 24, 2012, 7:45 am, GRAND PRAIRIE, TX 75050</TrackDetail>
9
+ <TrackDetail>Departed Shipping Partner Facility, January 23, 2012, 2:49 am, PHOENIX, AZ 85043</TrackDetail>
10
+ <TrackDetail>Arrived Shipping Partner Facility, January 22, 2012, 5:00 pm, PHOENIX, AZ 85043</TrackDetail>
11
+ <TrackDetail>Picked Up by Shipping Partner, January 22, 2012, 4:30 pm, PHOENIX, AZ 85043</TrackDetail>
12
+ </TrackInfo>
13
+ </TrackResponse>
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0"?>
2
+ <TrackResponse><TrackInfo ID="ABC123XYZ"><TrackSummary>There is no record of that mail item. If it was mailed recently, it may not yet be tracked. Please try again later.</TrackSummary></TrackInfo>
3
+ </TrackResponse>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0"?>
2
+ <TrackResponse>
3
+ <TrackInfo ID="9574211957289221353248">
4
+ <Error>
5
+ <Number>-2147219301</Number>
6
+ <Description>Delivery status information is not available for your item via this web site.</Description>
7
+ <HelpFile/>
8
+ <HelpContext/>
9
+ </Error>
10
+ </TrackInfo>
11
+ </TrackResponse>
12
+
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0"?>
2
+ <Error>
3
+ <Number>-2147219040</Number>
4
+ <Source>SOLServerTest;SOLServerTest.Track_Respond</Source>
5
+ <Description>This Information has not been included in this Test Server.</Description>
6
+ <HelpFile></HelpFile>
7
+ <HelpContext></HelpContext>
8
+ </Error>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0"?>
2
+ <RateV4Request USERID="login">
3
+ <Package ID="0">
4
+ <Service>ALL</Service>
5
+ <FirstClassMailType/>
6
+ <ZipOrigination>90210</ZipOrigination>
7
+ <ZipDestination>10017</ZipDestination>
8
+ <Pounds>0</Pounds>
9
+ <Ounces>8.8</Ounces>
10
+ <Container>RECTANGULAR</Container>
11
+ <Size>REGULAR</Size>
12
+ <Width>5.51</Width>
13
+ <Length>7.48</Length>
14
+ <Height>0.79</Height>
15
+ <Girth>12.60</Girth>
16
+ <Machinable>TRUE</Machinable>
17
+ </Package>
18
+ </RateV4Request>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0"?>
2
+ <IntlRateV2Request USERID="login">
3
+ <Package ID="0">
4
+ <Pounds>0</Pounds>
5
+ <Ounces>120</Ounces>
6
+ <MailType>Package</MailType>
7
+ <GXG>
8
+ <POBoxFlag>N</POBoxFlag>
9
+ <GiftFlag>N</GiftFlag>
10
+ </GXG>
11
+ <ValueOfContents>269.99</ValueOfContents>
12
+ <Country>Canada</Country>
13
+ <Container>RECTANGULAR</Container>
14
+ <Size>LARGE</Size>
15
+ <Width>10.00</Width>
16
+ <Length>15.00</Length>
17
+ <Height>4.50</Height>
18
+ <Girth>29.00</Girth>
19
+ </Package>
20
+ </IntlRateV2Request>
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0"?>
2
+ <IntlRateV2Request USERID="login">
3
+ <Package ID="0">
4
+ <Pounds>0</Pounds>
5
+ <Ounces>9</Ounces>
6
+ <MailType>Package</MailType>
7
+ <GXG>
8
+ <POBoxFlag>N</POBoxFlag>
9
+ <GiftFlag>N</GiftFlag>
10
+ </GXG>
11
+ <ValueOfContents>0.0</ValueOfContents>
12
+ <Country>Canada</Country>
13
+ <Container>RECTANGULAR</Container>
14
+ <Size>REGULAR</Size>
15
+ <Width>5.51</Width>
16
+ <Length>7.48</Length>
17
+ <Height>0.79</Height>
18
+ <Girth>12.60</Girth>
19
+ </Package>
20
+ </IntlRateV2Request>
@@ -0,0 +1,246 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+
5
+ # All remote tests require Canada Post development environment credentials
6
+ class CanadaPostPWSPlatformTest < Minitest::Test
7
+ include ActiveShipping::Test::Credentials
8
+ include ActiveShipping::Test::Fixtures
9
+
10
+ def setup
11
+ @login = credentials(:canada_post_pws)
12
+
13
+ # 100 grams, 93 cm long, 10 cm diameter, cylinders have different volume calculations
14
+ # @pkg1 = Package.new(1000, [93,10], :value => 10.00)
15
+ @pkg1 = Package.new(10, nil, :value => 10.00)
16
+ @pkg2 = Package.new(10, [20.0, 10.0, 1.0], :value => 10.00)
17
+
18
+ @line_item1 = line_item_fixture
19
+
20
+ @shipping_opts1 = {:dc => true, :cod => true, :cod_amount => 500.00, :cov => true, :cov_amount => 100.00,
21
+ :so => true, :pa18 => true}
22
+
23
+ @home_params = {
24
+ :name => "John Smith",
25
+ :company => "test",
26
+ :phone => "613-555-1212",
27
+ :address1 => "123 Elm St.",
28
+ :city => 'Ottawa',
29
+ :province => 'ON',
30
+ :country => 'CA',
31
+ :postal_code => 'K1P 1J1'
32
+ }
33
+ @home = Location.new(@home_params)
34
+
35
+ @dom_params = {
36
+ :name => "John Smith Sr.",
37
+ :company => "",
38
+ :phone => '123-123-1234',
39
+ :address1 => "5500 Oak Ave",
40
+ :city => 'Vancouver',
41
+ :province => 'BC',
42
+ :country => 'CA',
43
+ :postal_code => 'V5J 2T4'
44
+ }
45
+
46
+ @dest_params = {
47
+ :name => "Frank White",
48
+ :phone => '123-123-1234',
49
+ :address1 => '999 Wiltshire Blvd',
50
+ :city => 'Beverly Hills',
51
+ :state => 'CA',
52
+ :country => 'US',
53
+ :zip => '90210'
54
+ }
55
+ @dest = Location.new(@dest_params)
56
+
57
+ @dom_params = {
58
+ :name => "Mrs. Smith",
59
+ :company => "",
60
+ :phone => "604-555-1212",
61
+ :address1 => "5000 Oak St.",
62
+ :address2 => "",
63
+ :city => 'Vancouver',
64
+ :province => 'BC',
65
+ :country => 'CA',
66
+ :postal_code => 'V5J 2N2'
67
+ }
68
+
69
+ @intl_params = {
70
+ :name => "Mrs. Yamamoto",
71
+ :company => "",
72
+ :phone => "011-123-123-1234",
73
+ :address1 => "123 Yokohama Road",
74
+ :address2 => "",
75
+ :city => 'Tokyo',
76
+ :province => '',
77
+ :country => 'JP'
78
+ }
79
+
80
+ @usa_params = {
81
+ :name => "John Smith",
82
+ :company => "",
83
+ :phone => "555-555-5555",
84
+ :address1 => "123 Fake Street",
85
+ :address2 => "",
86
+ :city => 'New York',
87
+ :province => 'NY',
88
+ :country => 'US',
89
+ :zip => '12345'
90
+ }
91
+
92
+ @cp = CanadaPostPWS.new(@login)
93
+ @cp.logger = Logger.new(StringIO.new)
94
+
95
+ @customer_number = @login[:customer_number]
96
+ @customer_api_key = @login[:customer_api_key]
97
+ @customer_secret = @login[:customer_secret]
98
+ end
99
+
100
+ def build_options
101
+ {
102
+ :customer_number => @customer_number,
103
+ :customer_api_key => @customer_api_key,
104
+ :customer_secret => @customer_secret
105
+ }
106
+ end
107
+
108
+ def test_rates
109
+ rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], build_options)
110
+ assert_equal RateResponse, rates.class
111
+ assert_equal RateEstimate, rates.rates.first.class
112
+ end
113
+
114
+ def test_rates_with_insurance_changes_price
115
+ rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], build_options)
116
+ insured_rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], build_options.merge(@shipping_opts1))
117
+ assert_not_equal rates.rates.first.price, insured_rates.rates.first.price
118
+ end
119
+
120
+ def test_rates_with_invalid_customer_raises_exception
121
+ opts = {:customer_number => "0000000000", :service => "DOM.XP"}
122
+ assert_raises(ResponseError) do
123
+ @cp.find_rates(@home_params, @dom_params, [@pkg1], opts)
124
+ end
125
+ end
126
+
127
+ def test_rates_USA_returns_small_packet_rates
128
+ rates = @cp.find_rates(@home_params, @usa_params, [@pkg1], build_options, @pkg2, ['USA.SP.AIR'])
129
+ assert_equal CPPWSRateResponse, rates.class
130
+ assert_equal RateEstimate, rates.rates.first.class
131
+ assert rates.rates.map(&:service_code).include? "USA.SP.AIR"
132
+ end
133
+
134
+ def test_tracking
135
+ pin = "1371134583769923" # valid pin
136
+ response = @cp.find_tracking_info(pin, build_options)
137
+ assert_equal 'Xpresspost', response.service_name
138
+ assert response.expected_date.is_a?(Date)
139
+ assert response.customer_number
140
+ assert_equal 10, response.shipment_events.count
141
+ end
142
+
143
+ def test_tracking_invalid_pin_raises_exception
144
+ pin = "000000000000000"
145
+ exception = assert_raises(ResponseError) do
146
+ @cp.find_tracking_info(pin, build_options)
147
+ end
148
+ assert_equal "No Pin History", exception.message
149
+ end
150
+
151
+ def test_create_shipment_with_invalid_customer_raises_exception
152
+ opts = {:customer_number => "0000000000", :service => "DOM.XP"}
153
+ assert_raises(ResponseError) do
154
+ @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
155
+ end
156
+ end
157
+
158
+ def test_register_merchant
159
+ response = @cp.register_merchant
160
+ assert response.is_a?(CPPWSRegisterResponse)
161
+ assert_match /^(\d|[a-f]){22}$/, response.token_id
162
+ end
163
+
164
+ def test_merchant_details_empty_details
165
+ response = @cp.register_merchant
166
+ exception = assert_raises(ResponseError) do
167
+ response = @cp.retrieve_merchant_details(:token_id => response.token_id)
168
+ end
169
+ assert_equal "No Merchant Info", exception.message
170
+ end
171
+
172
+ def test_find_services_no_country
173
+ response = @cp.find_services(nil, build_options)
174
+ assert response
175
+ end
176
+
177
+ def test_find_services_country_JP
178
+ response = @cp.find_services('JP', build_options)
179
+ assert response
180
+ end
181
+
182
+ def test_find_services_invalid_country
183
+ exception = assert_raises(ResponseError) do
184
+ @cp.find_services('XX', build_options)
185
+ end
186
+ assert_equal "A valid destination country must be supplied.", exception.message
187
+ end
188
+
189
+ def test_find_service_options_no_country
190
+ assert response = @cp.find_service_options("INT.XP", nil, build_options)
191
+ assert_equal "INT.XP", response[:service_code]
192
+ assert_equal "Xpresspost International", response[:service_name]
193
+ assert_equal 4, response[:options].size
194
+ assert_equal "COV", response[:options][0][:code]
195
+ assert_equal false, response[:options][0][:required]
196
+ assert_equal true, response[:options][0][:qualifier_required]
197
+ assert_equal 5000, response[:options][0][:qualifier_max]
198
+ assert_equal 0, response[:restrictions][:min_weight]
199
+ assert_equal 30000, response[:restrictions][:max_weight]
200
+ assert_equal 0.1, response[:restrictions][:min_length]
201
+ assert_equal 150, response[:restrictions][:max_length]
202
+ assert_equal 0.1, response[:restrictions][:min_height]
203
+ assert_equal 150, response[:restrictions][:max_height]
204
+ assert_equal 0.1, response[:restrictions][:min_width]
205
+ assert_equal 150, response[:restrictions][:max_width]
206
+ end
207
+
208
+ def test_find_service_options
209
+ assert response = @cp.find_service_options("INT.XP", "JP", build_options)
210
+ assert_equal "INT.XP", response[:service_code]
211
+ assert_equal "Xpresspost International", response[:service_name]
212
+ assert_equal 3, response[:options].size
213
+ assert_equal "COV", response[:options][0][:code]
214
+ assert_equal false, response[:options][0][:required]
215
+ assert_equal true, response[:options][0][:qualifier_required]
216
+ assert_equal 1000, response[:options][0][:qualifier_max]
217
+ assert_equal 0, response[:restrictions][:min_weight]
218
+ assert_equal 30000, response[:restrictions][:max_weight]
219
+ assert_equal 0.1, response[:restrictions][:min_length]
220
+ assert_equal 150, response[:restrictions][:max_length]
221
+ assert_equal 0.1, response[:restrictions][:min_height]
222
+ assert_equal 150, response[:restrictions][:max_height]
223
+ assert_equal 0.1, response[:restrictions][:min_width]
224
+ assert_equal 150, response[:restrictions][:max_width]
225
+ end
226
+
227
+ def test_find_option_details
228
+ assert response = @cp.find_option_details("SO", build_options)
229
+ assert_equal "SO", response[:code]
230
+ assert_equal "Signature option", response[:name]
231
+ assert_equal "FEAT", response[:class]
232
+ assert_equal true, response[:prints_on_label]
233
+ assert_equal false, response[:qualifier_required]
234
+ assert_equal 1, response[:conflicting_options].size
235
+ assert_equal "LAD", response[:conflicting_options][0]
236
+ assert_equal 1, response[:prerequisite_options].size
237
+ assert_equal "DC", response[:prerequisite_options][0]
238
+ end
239
+
240
+ def test_find_option_details_french
241
+ cp = CanadaPostPWS.new(@login.merge(:language => 'fr'))
242
+ assert response = cp.find_option_details("LAD", build_options)
243
+ assert_equal "LAD", response[:code]
244
+ assert_equal "Laisser à la porte (pas d'avis)", response[:name]
245
+ end
246
+ end
@@ -0,0 +1,171 @@
1
+ require 'test_helper'
2
+
3
+ class CanadaPostPWSTest < Minitest::Test
4
+ # All remote tests require Canada Post development environment credentials
5
+ include ActiveShipping::Test::Credentials
6
+ include ActiveShipping::Test::Fixtures
7
+
8
+ def setup
9
+ @login = credentials(:canada_post_pws)
10
+
11
+ # 100 grams, 93 cm long, 10 cm diameter, cylinders have different volume calculations
12
+ # @pkg1 = Package.new(1000, [93,10], :value => 10.00)
13
+ @pkg1 = Package.new(1000, nil, :value => 10.00)
14
+
15
+ @line_item1 = line_item_fixture
16
+
17
+ @shipping_opts1 = {:dc => true, :cod => true, :cod_amount => 500.00, :cov => true, :cov_amount => 100.00,
18
+ :so => true, :pa18 => true}
19
+
20
+ @home_params = {
21
+ :name => "John Smith",
22
+ :company => "test",
23
+ :phone => "613-555-1212",
24
+ :address1 => "123 Elm St.",
25
+ :city => 'Ottawa',
26
+ :province => 'ON',
27
+ :country => 'CA',
28
+ :postal_code => 'K1P 1J1'
29
+ }
30
+ @home = Location.new(@home_params)
31
+
32
+ @dom_params = {
33
+ :name => "John Smith Sr.",
34
+ :company => "",
35
+ :phone => '123-123-1234',
36
+ :address1 => "5500 Oak Ave",
37
+ :city => 'Vancouver',
38
+ :province => 'BC',
39
+ :country => 'CA',
40
+ :postal_code => 'V5J 2T4'
41
+ }
42
+
43
+ @dest_params = {
44
+ :name => "Frank White",
45
+ :phone => '123-123-1234',
46
+ :address1 => '999 Wiltshire Blvd',
47
+ :city => 'Beverly Hills',
48
+ :state => 'CA',
49
+ :country => 'US',
50
+ :zip => '90210'
51
+ }
52
+ @dest = Location.new(@dest_params)
53
+
54
+ @dom_params = {
55
+ :name => "Mrs. Smith",
56
+ :company => "",
57
+ :phone => "604-555-1212",
58
+ :address1 => "5000 Oak St.",
59
+ :address2 => "",
60
+ :city => 'Vancouver',
61
+ :province => 'BC',
62
+ :country => 'CA',
63
+ :postal_code => 'V5J 2N2'
64
+ }
65
+
66
+ @intl_params = {
67
+ :name => "Mrs. Yamamoto",
68
+ :company => "",
69
+ :phone => "011-123-123-1234",
70
+ :address1 => "123 Yokohama Road",
71
+ :address2 => "",
72
+ :city => 'Tokyo',
73
+ :province => '',
74
+ :country => 'JP'
75
+ }
76
+
77
+ @cp = CanadaPostPWS.new(@login.merge(:endpoint => "https://ct.soa-gw.canadapost.ca/"))
78
+ @cp.logger = Logger.new(StringIO.new)
79
+
80
+ @customer_number = @login[:customer_number]
81
+
82
+ @DEFAULT_RESPONSE = {
83
+ :shipping_id => "406951321983787352",
84
+ :tracking_number => "11111118901234",
85
+ :label_url => "https://ct.soa-gw.canadapost.ca/ers/artifact/#{@login[:api_key]}/20238/0"
86
+ }
87
+ end
88
+
89
+ def test_rates
90
+ opts = {:customer_number => @customer_number}
91
+ rates = @cp.find_rates(@home_params, @dom_params, [@pkg1], opts)
92
+ assert_equal RateResponse, rates.class
93
+ assert_equal RateEstimate, rates.rates.first.class
94
+ end
95
+
96
+ def test_rates_with_invalid_customer_raises_exception
97
+ opts = {:customer_number => "0000000000", :service => "DOM.XP"}
98
+ assert_raises(ResponseError) do
99
+ @cp.find_rates(@home_params, @dom_params, [@pkg1], opts)
100
+ end
101
+ end
102
+
103
+ def test_tracking
104
+ pin = "1371134583769923" # valid pin
105
+ response = @cp.find_tracking_info(pin, {})
106
+ assert_equal 'Xpresspost', response.service_name
107
+ assert response.expected_date.is_a?(Date)
108
+ assert response.customer_number
109
+ assert_equal 10, response.shipment_events.count
110
+ end
111
+
112
+ def test_tracking_when_no_tracking_info_raises_exception
113
+ pin = "4442172020196022" # valid pin
114
+
115
+ error = assert_raises(ActiveShipping::ResponseError) do
116
+ @cp.find_tracking_info(pin, {})
117
+ end
118
+
119
+ assert_match /No Tracking/, error.message
120
+ end
121
+
122
+ def test_create_shipment
123
+ opts = {:customer_number => @customer_number, :service => "DOM.XP"}
124
+ response = @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
125
+ assert response.is_a?(CPPWSShippingResponse)
126
+ assert_equal @DEFAULT_RESPONSE[:shipping_id], response.shipping_id
127
+ assert_equal @DEFAULT_RESPONSE[:tracking_number], response.tracking_number
128
+ assert_equal @DEFAULT_RESPONSE[:label_url], response.label_url
129
+ end
130
+
131
+ def test_create_shipment_with_options
132
+ opts = {:customer_number => @customer_number, :service => "USA.EP"}
133
+ opts.merge! @shipping_opts1
134
+ response = @cp.create_shipment(@home_params, @dest_params, @pkg1, @line_item1, opts)
135
+ assert response.is_a?(CPPWSShippingResponse)
136
+ assert_equal @DEFAULT_RESPONSE[:shipping_id], response.shipping_id
137
+ assert_equal @DEFAULT_RESPONSE[:tracking_number], response.tracking_number
138
+ assert_equal @DEFAULT_RESPONSE[:label_url], response.label_url
139
+ end
140
+
141
+ def test_retrieve_shipping_label
142
+ shipping_response = CPPWSShippingResponse.new(true, '', {}, @DEFAULT_RESPONSE)
143
+ response = @cp.retrieve_shipping_label(shipping_response)
144
+ assert_not_nil response
145
+ assert_equal "%PDF", response[0...4]
146
+ end
147
+
148
+ def test_create_shipment_with_invalid_customer_raises_exception
149
+ opts = {:customer_number => "0000000000", :service => "DOM.XP"}
150
+ assert_raises(ResponseError) do
151
+ @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
152
+ end
153
+ end
154
+
155
+ def test_register_merchant
156
+ response = @cp.register_merchant
157
+ assert response.is_a?(CPPWSRegisterResponse)
158
+ assert_equal "1111111111111111111111", response.token_id
159
+ end
160
+
161
+ def test_merchant_details
162
+ token_id = "1111111111111111111111"
163
+ response = @cp.retrieve_merchant_details(:token_id => token_id)
164
+ assert response.is_a?(CPPWSMerchantDetailsResponse)
165
+ assert_equal "0000000000", response.customer_number
166
+ assert_equal "1234567890", response.contract_number
167
+ assert_equal "0000000000000000", response.username
168
+ assert_equal "1a2b3c4d5e6f7a8b9c0d12", response.password
169
+ assert_equal true, response.has_default_credit_card
170
+ end
171
+ end