reactive_shipping 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.travis.yml +33 -0
  4. data/.yardopts +13 -0
  5. data/CHANGELOG.md +225 -0
  6. data/CONTRIBUTING.md +23 -0
  7. data/Gemfile +3 -0
  8. data/MIT-LICENSE +21 -0
  9. data/README.md +158 -0
  10. data/Rakefile +35 -0
  11. data/dev.yml +17 -0
  12. data/gemfiles/activesupport42.gemfile +5 -0
  13. data/gemfiles/activesupport50.gemfile +6 -0
  14. data/gemfiles/activesupport51.gemfile +5 -0
  15. data/gemfiles/activesupport52.gemfile +5 -0
  16. data/gemfiles/activesupport_master.gemfile +5 -0
  17. data/lib/certs/eParcel.dtd +111 -0
  18. data/lib/reactive_shipping.rb +26 -0
  19. data/lib/reactive_shipping/address_validation_response.rb +30 -0
  20. data/lib/reactive_shipping/carrier.rb +184 -0
  21. data/lib/reactive_shipping/carriers.rb +35 -0
  22. data/lib/reactive_shipping/carriers/australia_post.rb +248 -0
  23. data/lib/reactive_shipping/carriers/benchmark_carrier.rb +31 -0
  24. data/lib/reactive_shipping/carriers/bogus_carrier.rb +12 -0
  25. data/lib/reactive_shipping/carriers/canada_post.rb +263 -0
  26. data/lib/reactive_shipping/carriers/canada_post_pws.rb +908 -0
  27. data/lib/reactive_shipping/carriers/fedex.rb +797 -0
  28. data/lib/reactive_shipping/carriers/kunaki.rb +155 -0
  29. data/lib/reactive_shipping/carriers/new_zealand_post.rb +260 -0
  30. data/lib/reactive_shipping/carriers/shipwire.rb +178 -0
  31. data/lib/reactive_shipping/carriers/stamps.rb +860 -0
  32. data/lib/reactive_shipping/carriers/ups.rb +1060 -0
  33. data/lib/reactive_shipping/carriers/usps.rb +708 -0
  34. data/lib/reactive_shipping/carriers/usps_returns.rb +86 -0
  35. data/lib/reactive_shipping/delivery_date_estimate.rb +20 -0
  36. data/lib/reactive_shipping/delivery_date_estimates_response.rb +11 -0
  37. data/lib/reactive_shipping/errors.rb +35 -0
  38. data/lib/reactive_shipping/external_return_label_request.rb +417 -0
  39. data/lib/reactive_shipping/external_return_label_response.rb +26 -0
  40. data/lib/reactive_shipping/label.rb +10 -0
  41. data/lib/reactive_shipping/label_response.rb +10 -0
  42. data/lib/reactive_shipping/location.rb +166 -0
  43. data/lib/reactive_shipping/package.rb +165 -0
  44. data/lib/reactive_shipping/package_item.rb +60 -0
  45. data/lib/reactive_shipping/rate_estimate.rb +197 -0
  46. data/lib/reactive_shipping/rate_response.rb +33 -0
  47. data/lib/reactive_shipping/response.rb +44 -0
  48. data/lib/reactive_shipping/shipment_event.rb +22 -0
  49. data/lib/reactive_shipping/shipment_packer.rb +108 -0
  50. data/lib/reactive_shipping/shipping_response.rb +34 -0
  51. data/lib/reactive_shipping/tracking_response.rb +120 -0
  52. data/lib/reactive_shipping/version.rb +3 -0
  53. data/reactive_shipping.gemspec +38 -0
  54. data/shipit.rubygems.yml +1 -0
  55. data/test/console.rb +39 -0
  56. data/test/credentials.yml +76 -0
  57. data/test/fixtures/files/label1.pdf +0 -0
  58. data/test/fixtures/files/ups-shipping-label.gif +0 -0
  59. data/test/fixtures/json/australia_post/calculate_domestic.json +13 -0
  60. data/test/fixtures/json/australia_post/calculate_domestic_2.json +19 -0
  61. data/test/fixtures/json/australia_post/calculate_international.json +12 -0
  62. data/test/fixtures/json/australia_post/calculate_international_2.json +15 -0
  63. data/test/fixtures/json/australia_post/error_message.json +5 -0
  64. data/test/fixtures/json/australia_post/service_domestic.json +117 -0
  65. data/test/fixtures/json/australia_post/service_domestic_2.json +117 -0
  66. data/test/fixtures/json/australia_post/service_international.json +76 -0
  67. data/test/fixtures/json/australia_post/service_international_2.json +59 -0
  68. data/test/fixtures/json/newzealandpost/domestic_book.json +1 -0
  69. data/test/fixtures/json/newzealandpost/domestic_default.json +1 -0
  70. data/test/fixtures/json/newzealandpost/domestic_error.json +1 -0
  71. data/test/fixtures/json/newzealandpost/domestic_poster.json +1 -0
  72. data/test/fixtures/json/newzealandpost/domestic_small_half_pound.json +1 -0
  73. data/test/fixtures/json/newzealandpost/international_book.json +1 -0
  74. data/test/fixtures/json/newzealandpost/international_new_zealand_wii.json +1 -0
  75. data/test/fixtures/json/newzealandpost/international_small_half_pound.json +1 -0
  76. data/test/fixtures/json/newzealandpost/international_wii.json +1 -0
  77. data/test/fixtures/xml/canadapost/example_request.xml +25 -0
  78. data/test/fixtures/xml/canadapost/example_response.xml +130 -0
  79. data/test/fixtures/xml/canadapost/example_response_error.xml +16 -0
  80. data/test/fixtures/xml/canadapost/example_response_french.xml +122 -0
  81. data/test/fixtures/xml/canadapost/example_response_with_nil_value.xml +164 -0
  82. data/test/fixtures/xml/canadapost/example_response_with_postal_outlet.xml +155 -0
  83. data/test/fixtures/xml/canadapost/example_response_with_postal_outlet_french.xml +274 -0
  84. data/test/fixtures/xml/canadapost/example_response_with_strange_delivery_date.xml +130 -0
  85. data/test/fixtures/xml/canadapost_pws/dnc_tracking_details_en.xml +112 -0
  86. data/test/fixtures/xml/canadapost_pws/merchant_details_error.xml +7 -0
  87. data/test/fixtures/xml/canadapost_pws/merchant_details_response.xml +7 -0
  88. data/test/fixtures/xml/canadapost_pws/option_response.xml +13 -0
  89. data/test/fixtures/xml/canadapost_pws/option_response_no_conflicts.xml +7 -0
  90. data/test/fixtures/xml/canadapost_pws/rates_info.xml +190 -0
  91. data/test/fixtures/xml/canadapost_pws/rates_info_error.xml +7 -0
  92. data/test/fixtures/xml/canadapost_pws/receipt_response.xml +42 -0
  93. data/test/fixtures/xml/canadapost_pws/receipt_response_no_priced_options.xml +36 -0
  94. data/test/fixtures/xml/canadapost_pws/register_token_error.xml +7 -0
  95. data/test/fixtures/xml/canadapost_pws/register_token_response.xml +3 -0
  96. data/test/fixtures/xml/canadapost_pws/service_options_response.xml +42 -0
  97. data/test/fixtures/xml/canadapost_pws/services_error.xml +6 -0
  98. data/test/fixtures/xml/canadapost_pws/services_response.xml +32 -0
  99. data/test/fixtures/xml/canadapost_pws/shipment_domestic.xml +69 -0
  100. data/test/fixtures/xml/canadapost_pws/shipment_response.xml +20 -0
  101. data/test/fixtures/xml/canadapost_pws/shipment_us.xml +69 -0
  102. data/test/fixtures/xml/canadapost_pws/tracking_details_en.xml +152 -0
  103. data/test/fixtures/xml/canadapost_pws/tracking_details_en_error.xml +7 -0
  104. data/test/fixtures/xml/canadapost_pws/tracking_details_en_undelivered.xml +116 -0
  105. data/test/fixtures/xml/canadapost_pws/tracking_details_fr.xml +156 -0
  106. data/test/fixtures/xml/canadapost_pws/tracking_details_no_expected_delivery_date.xml +40 -0
  107. data/test/fixtures/xml/fedex/create_shipment_response.xml +2 -0
  108. data/test/fixtures/xml/fedex/freight_rate_request.xml +82 -0
  109. data/test/fixtures/xml/fedex/freight_rate_response.xml +506 -0
  110. data/test/fixtures/xml/fedex/invalid_fedex_reply.xml +27 -0
  111. data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_commercial_rate_request.xml +79 -0
  112. data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_no_saturday_rate_request.xml +79 -0
  113. data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_request.xml +80 -0
  114. data/test/fixtures/xml/fedex/ottawa_to_beverly_hills_rate_response.xml +214 -0
  115. data/test/fixtures/xml/fedex/raterequest_reply.xml +213 -0
  116. data/test/fixtures/xml/fedex/raterequest_response_with_ground_home_delivery.xml +206 -0
  117. data/test/fixtures/xml/fedex/reply_without_notifications.xml +185 -0
  118. data/test/fixtures/xml/fedex/tracking_request.xml +29 -0
  119. data/test/fixtures/xml/fedex/tracking_response_bad_tracking_number.xml +20 -0
  120. data/test/fixtures/xml/fedex/tracking_response_delivered_at_door.xml +254 -0
  121. data/test/fixtures/xml/fedex/tracking_response_delivered_at_facility.xml +403 -0
  122. data/test/fixtures/xml/fedex/tracking_response_delivered_with_signature.xml +269 -0
  123. data/test/fixtures/xml/fedex/tracking_response_empty_status_detail.xml +84 -0
  124. data/test/fixtures/xml/fedex/tracking_response_failure_code_9045.xml +52 -0
  125. data/test/fixtures/xml/fedex/tracking_response_failure_code_9080.xml +51 -0
  126. data/test/fixtures/xml/fedex/tracking_response_in_transit.xml +127 -0
  127. data/test/fixtures/xml/fedex/tracking_response_invalid_tracking_number.xml +52 -0
  128. data/test/fixtures/xml/fedex/tracking_response_missing_status_code.xml +89 -0
  129. data/test/fixtures/xml/fedex/tracking_response_multiple_results.xml +100 -0
  130. data/test/fixtures/xml/fedex/tracking_response_not_found.xml +52 -0
  131. data/test/fixtures/xml/fedex/tracking_response_shipment_exception.xml +209 -0
  132. data/test/fixtures/xml/fedex/tracking_response_unable_to_process.xml +32 -0
  133. data/test/fixtures/xml/fedex/tracking_response_with_blank_state.xml +107 -0
  134. data/test/fixtures/xml/fedex/unknown_fedex_document_reply.xml +3 -0
  135. data/test/fixtures/xml/kunaki/invalid_state_response.xml +3 -0
  136. data/test/fixtures/xml/kunaki/no_valid_items_response.xml +3 -0
  137. data/test/fixtures/xml/kunaki/successful_rates_response.xml +3 -0
  138. data/test/fixtures/xml/kunaki/unsuccessful_rates_response.xml +9 -0
  139. data/test/fixtures/xml/shipwire/international_rates_response.xml +17 -0
  140. data/test/fixtures/xml/shipwire/new_carrier_rate_response.xml +18 -0
  141. data/test/fixtures/xml/shipwire/no_rates_response.xml +7 -0
  142. data/test/fixtures/xml/shipwire/rates_response.xml +36 -0
  143. data/test/fixtures/xml/shipwire/rates_response_no_estimate.xml +14 -0
  144. data/test/fixtures/xml/stamps/authenticate_user_request.xml +15 -0
  145. data/test/fixtures/xml/stamps/authenticate_user_response.xml +10 -0
  146. data/test/fixtures/xml/stamps/cleanse_address_request.xml +19 -0
  147. data/test/fixtures/xml/stamps/cleanse_address_response.xml +27 -0
  148. data/test/fixtures/xml/stamps/create_indicium_request.xml +69 -0
  149. data/test/fixtures/xml/stamps/create_indicium_response.xml +40 -0
  150. data/test/fixtures/xml/stamps/expired_authenticator_response.xml +15 -0
  151. data/test/fixtures/xml/stamps/get_account_info_request.xml +11 -0
  152. data/test/fixtures/xml/stamps/get_account_info_response.xml +36 -0
  153. data/test/fixtures/xml/stamps/get_purchase_status_request.xml +12 -0
  154. data/test/fixtures/xml/stamps/get_purchase_status_response.xml +16 -0
  155. data/test/fixtures/xml/stamps/get_rates_request.xml +19 -0
  156. data/test/fixtures/xml/stamps/get_rates_response.xml +351 -0
  157. data/test/fixtures/xml/stamps/purchase_postage_request.xml +13 -0
  158. data/test/fixtures/xml/stamps/purchase_postage_response.xml +17 -0
  159. data/test/fixtures/xml/stamps/track_shipment_request.xml +12 -0
  160. data/test/fixtures/xml/stamps/track_shipment_response.xml +45 -0
  161. data/test/fixtures/xml/ups/access_request.xml +6 -0
  162. data/test/fixtures/xml/ups/delivered_shipment_with_refund.xml +290 -0
  163. data/test/fixtures/xml/ups/delivered_shipment_without_events_tracking_response.xml +62 -0
  164. data/test/fixtures/xml/ups/delivery_dates_response.xml +140 -0
  165. data/test/fixtures/xml/ups/example_tracking_response.xml +53 -0
  166. data/test/fixtures/xml/ups/in_transit_shipment.xml +183 -0
  167. data/test/fixtures/xml/ups/out_for_delivery_shipment.xml +165 -0
  168. data/test/fixtures/xml/ups/package_exceeds_maximum_length.xml +12 -0
  169. data/test/fixtures/xml/ups/rate_single_service.xml +54 -0
  170. data/test/fixtures/xml/ups/rescheduled_shipment.xml +204 -0
  171. data/test/fixtures/xml/ups/shipment_accept_response.xml +42 -0
  172. data/test/fixtures/xml/ups/shipment_confirm_response.xml +33 -0
  173. data/test/fixtures/xml/ups/shipment_from_tiger_direct.xml +222 -0
  174. data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response.xml +290 -0
  175. data/test/fixtures/xml/ups/test_real_home_as_residential_destination_response_with_insured.xml +289 -0
  176. data/test/fixtures/xml/ups/test_real_home_as_residential_destination_with_origin_account_response.xml +311 -0
  177. data/test/fixtures/xml/ups/tracking_request.xml +9 -0
  178. data/test/fixtures/xml/ups/triple_accept_response.xml +72 -0
  179. data/test/fixtures/xml/ups/triple_confirm_response.xml +32 -0
  180. data/test/fixtures/xml/ups/void_shipment_response.xml +11 -0
  181. data/test/fixtures/xml/usps/api_error_rate_response.xml +53 -0
  182. data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml +2 -0
  183. data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_plus_rate_response.xml +258 -0
  184. data/test/fixtures/xml/usps/beverly_hills_to_new_york_book_rate_response.xml +108 -0
  185. data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_base_rate_response.xml +84 -0
  186. data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_plus_rate_response.xml +212 -0
  187. data/test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_rate_response.xml +230 -0
  188. data/test/fixtures/xml/usps/first_class_packages_with_invalid_mail_type_response.xml +12 -0
  189. data/test/fixtures/xml/usps/first_class_packages_with_mail_type_response.xml +16 -0
  190. data/test/fixtures/xml/usps/first_class_packages_without_mail_type_response.xml +12 -0
  191. data/test/fixtures/xml/usps/invalid_xml_response.xml +10 -0
  192. data/test/fixtures/xml/usps/invalid_xml_tracking_response_error.xml +2 -0
  193. data/test/fixtures/xml/usps/tracking_request.xml +10 -0
  194. data/test/fixtures/xml/usps/tracking_request_batch.xml +12 -0
  195. data/test/fixtures/xml/usps/tracking_response.xml +162 -0
  196. data/test/fixtures/xml/usps/tracking_response_alt.xml +53 -0
  197. data/test/fixtures/xml/usps/tracking_response_batch.xml +231 -0
  198. data/test/fixtures/xml/usps/tracking_response_failure.xml +11 -0
  199. data/test/fixtures/xml/usps/tracking_response_not_available.xml +12 -0
  200. data/test/fixtures/xml/usps/tracking_response_test_error.xml +8 -0
  201. data/test/fixtures/xml/usps/us_rate_request.xml +18 -0
  202. data/test/fixtures/xml/usps/us_rate_request_large.xml +18 -0
  203. data/test/fixtures/xml/usps/world_rate_request_only_country.xml +22 -0
  204. data/test/fixtures/xml/usps/world_rate_request_with_value.xml +24 -0
  205. data/test/fixtures/xml/usps/world_rate_request_without_value.xml +24 -0
  206. data/test/fixtures/xml/usps_returns/external_return_label_response.xml +2 -0
  207. data/test/fixtures/xml/usps_returns/external_return_label_response_failure.xml +10 -0
  208. data/test/remote/australia_post_test.rb +140 -0
  209. data/test/remote/canada_post_pws_platform_test.rb +259 -0
  210. data/test/remote/canada_post_pws_test.rb +169 -0
  211. data/test/remote/canada_post_test.rb +55 -0
  212. data/test/remote/fedex_test.rb +400 -0
  213. data/test/remote/kunaki_test.rb +37 -0
  214. data/test/remote/new_zealand_post_test.rb +149 -0
  215. data/test/remote/shipwire_test.rb +84 -0
  216. data/test/remote/stamps_test.rb +396 -0
  217. data/test/remote/usps_returns_test.rb +72 -0
  218. data/test/remote/usps_test.rb +243 -0
  219. data/test/test_helper.rb +296 -0
  220. data/test/unit/carrier_test.rb +130 -0
  221. data/test/unit/carriers/australia_post_test.rb +181 -0
  222. data/test/unit/carriers/benchmark_test.rb +18 -0
  223. data/test/unit/carriers/canada_post_pws_rating_test.rb +379 -0
  224. data/test/unit/carriers/canada_post_pws_register_test.rb +76 -0
  225. data/test/unit/carriers/canada_post_pws_shipping_test.rb +258 -0
  226. data/test/unit/carriers/canada_post_pws_test.rb +59 -0
  227. data/test/unit/carriers/canada_post_pws_tracking_test.rb +154 -0
  228. data/test/unit/carriers/canada_post_test.rb +148 -0
  229. data/test/unit/carriers/fedex_test.rb +693 -0
  230. data/test/unit/carriers/kunaki_test.rb +56 -0
  231. data/test/unit/carriers/new_zealand_post_test.rb +177 -0
  232. data/test/unit/carriers/shipwire_test.rb +188 -0
  233. data/test/unit/carriers/stamps_test.rb +245 -0
  234. data/test/unit/carriers/ups_test.rb +580 -0
  235. data/test/unit/carriers/usps_returns_test.rb +45 -0
  236. data/test/unit/carriers/usps_test.rb +633 -0
  237. data/test/unit/carriers_test.rb +16 -0
  238. data/test/unit/external_return_label_request_test.rb +258 -0
  239. data/test/unit/location_test.rb +234 -0
  240. data/test/unit/package_item_test.rb +232 -0
  241. data/test/unit/package_test.rb +404 -0
  242. data/test/unit/rate_estimate_test.rb +93 -0
  243. data/test/unit/response_test.rb +38 -0
  244. data/test/unit/shipment_event_test.rb +20 -0
  245. data/test/unit/shipment_packer_test.rb +212 -0
  246. data/test/unit/tracking_response_test.rb +41 -0
  247. metadata +684 -0
@@ -0,0 +1,169 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteCanadaPostPWSTest < ActiveSupport::TestCase
4
+ # All remote tests require Canada Post development environment credentials
5
+ include ReactiveShipping::Test::Credentials
6
+ include ReactiveShipping::Test::Fixtures
7
+
8
+ def setup
9
+ @login = credentials(:canada_post_pws)
10
+ refute @login.key?(:platform_id), "The 'canada_post_pws' credentials should NOT include a platform ID"
11
+
12
+ # 1000 grams, 93 cm long, 10 cm diameter, cylinders have different volume calculations
13
+ @pkg1 = Package.new(1000, [93, 10, 10], :value => 10.00)
14
+
15
+ @line_item1 = line_item_fixture
16
+
17
+ @shipping_opts1 = { :dc => true, :cov => true, :cov_amount => 100.00, :aban => true }
18
+
19
+ @home_params = {
20
+ :name => "John Smith",
21
+ :company => "test",
22
+ :phone => "613-555-1212",
23
+ :address1 => "123 Elm St.",
24
+ :city => 'Ottawa',
25
+ :province => 'ON',
26
+ :country => 'CA',
27
+ :postal_code => 'K1P 1J1'
28
+ }
29
+ @home = Location.new(@home_params)
30
+
31
+ @dom_params = {
32
+ :name => "John Smith Sr.",
33
+ :company => "",
34
+ :phone => '123-123-1234',
35
+ :address1 => "5500 Oak Ave",
36
+ :city => 'Vancouver',
37
+ :province => 'BC',
38
+ :country => 'CA',
39
+ :postal_code => 'V5J 2T4'
40
+ }
41
+
42
+ @dest_params = {
43
+ :name => "Frank White",
44
+ :phone => '123-123-1234',
45
+ :address1 => '999 Wiltshire Blvd',
46
+ :city => 'Beverly Hills',
47
+ :state => 'CA',
48
+ :country => 'US',
49
+ :zip => '90210'
50
+ }
51
+ @dest = Location.new(@dest_params)
52
+
53
+ @dom_params = {
54
+ :name => "Mrs. Smith",
55
+ :company => "",
56
+ :phone => "604-555-1212",
57
+ :address1 => "5000 Oak St.",
58
+ :address2 => "",
59
+ :city => 'Vancouver',
60
+ :province => 'BC',
61
+ :country => 'CA',
62
+ :postal_code => 'V5J 2N2'
63
+ }
64
+
65
+ @intl_params = {
66
+ :name => "Mrs. Yamamoto",
67
+ :company => "",
68
+ :phone => "011-123-123-1234",
69
+ :address1 => "123 Yokohama Road",
70
+ :address2 => "",
71
+ :city => 'Tokyo',
72
+ :province => '',
73
+ :country => 'JP'
74
+ }
75
+
76
+ @cp = CanadaPostPWS.new(@login.merge(:endpoint => "https://ct.soa-gw.canadapost.ca/"))
77
+ @cp.logger = Logger.new(StringIO.new)
78
+
79
+ @customer_number = @login[:customer_number]
80
+
81
+ @DEFAULT_RESPONSE = {
82
+ :shipping_id => "406951321983787352",
83
+ :tracking_number => "123456789012",
84
+ :label_url => "https://ct.soa-gw.canadapost.ca/ers/artifact/#{@login[:api_key]}/20238/0"
85
+ }
86
+ rescue NoCredentialsFound => e
87
+ skip(e.message)
88
+ end
89
+
90
+ def test_rates
91
+ opts = {:customer_number => @customer_number}
92
+ rate_response = @cp.find_rates(@home_params, @dom_params, [@pkg1], opts)
93
+ assert_kind_of ReactiveShipping::RateResponse, rate_response
94
+ assert_kind_of ReactiveShipping::RateEstimate, rate_response.rates.first
95
+ end
96
+
97
+ def test_rates_with_invalid_customer_raises_exception
98
+ opts = {:customer_number => "0000000000", :service => "DOM.XP"}
99
+ assert_raises(ResponseError) do
100
+ @cp.find_rates(@home_params, @dom_params, [@pkg1], opts)
101
+ end
102
+ end
103
+
104
+ def test_tracking
105
+ pin = "1371134583769923" # valid pin
106
+ response = @cp.find_tracking_info(pin, {})
107
+ assert_equal 'Xpresspost', response.service_name
108
+ assert response.expected_date.is_a?(Date)
109
+ assert response.customer_number
110
+ assert_equal 13, response.shipment_events.count
111
+ end
112
+
113
+ def test_tracking_when_no_tracking_info_raises_exception
114
+ pin = "4442172020196022" # valid pin
115
+
116
+ error = assert_raises(ReactiveShipping::ResponseError) do
117
+ @cp.find_tracking_info(pin, {})
118
+ end
119
+
120
+ assert_match /No Tracking/, error.message
121
+ end
122
+
123
+ def test_create_shipment
124
+ skip "Failing with 'Contract Number is a required field' after API change, skipping because no clue how to fix, might need different creds"
125
+ opts = {:customer_number => @customer_number, :service => "DOM.XP"}
126
+ response = @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
127
+ assert_kind_of CPPWSShippingResponse, response
128
+ assert_match /\A\d{17}\z/, response.shipping_id
129
+ assert_equal "123456789012", response.tracking_number
130
+ assert_match "https://ct.soa-gw.canadapost.ca/ers/artifact/", response.label_url
131
+ assert_match @login[:api_key], response.label_url
132
+ end
133
+
134
+ def test_create_shipment_with_options
135
+ skip "Failing with 'Contract Number is a required field' after API change, skipping because no clue how to fix, might need different creds"
136
+ opts = {:customer_number => @customer_number, :service => "USA.EP"}.merge(@shipping_opts1)
137
+ response = @cp.create_shipment(@home_params, @dest_params, @pkg1, @line_item1, opts)
138
+
139
+ assert_kind_of CPPWSShippingResponse, response
140
+ assert_match /\A\d{17}\z/, response.shipping_id
141
+ assert_equal "123456789012", response.tracking_number
142
+ assert_match "https://ct.soa-gw.canadapost.ca/ers/artifact/", response.label_url
143
+ assert_match @login[:api_key], response.label_url
144
+ end
145
+
146
+ def test_retrieve_shipping_label
147
+ skip "Failing with 'Contract Number is a required field' after API change, skipping because no clue how to fix, might need different creds"
148
+ opts = {:customer_number => @customer_number, :service => "DOM.XP"}
149
+ shipping_response = @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
150
+
151
+ # Looks like it takes Canada Post some time to actually generate the PDF.
152
+ response = nil
153
+ 10.times do
154
+ response = @cp.retrieve_shipping_label(shipping_response)
155
+ break unless response == ""
156
+ sleep(0.5)
157
+ end
158
+
159
+ assert_equal "%PDF", response[0...4]
160
+ end
161
+
162
+ def test_create_shipment_with_invalid_customer_raises_exception
163
+ skip "Failing with 'Contract Number is a required field' after API change, skipping because no clue how to fix, might need different creds"
164
+ opts = {:customer_number => "0000000000", :service => "DOM.XP"}
165
+ assert_raises(ResponseError) do
166
+ @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
167
+ end
168
+ end
169
+ end
@@ -0,0 +1,55 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteCanadaPostTest < ActiveSupport::TestCase
4
+ include ReactiveShipping::Test::Credentials
5
+
6
+ def setup
7
+ @carrier = CanadaPost.new(credentials(:canada_post))
8
+ @french_carrier = CanadaPost.new(credentials(:canada_post).merge(:french => true))
9
+
10
+ @origin = {:address1 => "61A York St", :city => "Ottawa", :province => "Ontario", :country => "Canada", :postal_code => "K1N 5T2"}
11
+ @destination = {:city => "Beverly Hills", :state => "CA", :country => "United States", :postal_code => "90210"}
12
+ @line_items = [Package.new(500, [2, 3, 4], :description => "a box full of stuff", :value => 25)]
13
+ rescue NoCredentialsFound => e
14
+ skip(e.message)
15
+ end
16
+
17
+ def test_valid_credentials
18
+ assert @carrier.valid_credentials?
19
+ end
20
+
21
+ def test_find_rates_french
22
+ rates = @french_carrier.find_rates(@origin, @destination, @line_items)
23
+ assert_instance_of CanadaPost::CanadaPostRateResponse, rates
24
+ end
25
+
26
+ def test_postal_outlets_french
27
+ rates = @french_carrier.find_rates(@origin, @destination, @line_items)
28
+
29
+ rates.postal_outlets.each do |outlet|
30
+ assert_instance_of CanadaPost::PostalOutlet, outlet
31
+ end
32
+ end
33
+
34
+ def test_find_rates
35
+ rates = @carrier.find_rates(@origin, @destination, @line_items)
36
+ assert_instance_of CanadaPost::CanadaPostRateResponse, rates
37
+ end
38
+
39
+ def test_postal_outlets
40
+ rates = @carrier.find_rates(@origin, @destination, @line_items)
41
+
42
+ rates.postal_outlets.each do |outlet|
43
+ assert_instance_of CanadaPost::PostalOutlet, outlet
44
+ end
45
+ end
46
+
47
+ def test_illegal_origin
48
+ @origin = @destination
49
+
50
+ assert_raises(ReactiveShipping::ResponseError) do
51
+ rates = @carrier.find_rates(@origin, @destination, @line_items)
52
+ refute rates.success?
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,400 @@
1
+ require 'test_helper'
2
+
3
+ class RemoteFedExTest < ActiveSupport::TestCase
4
+ include ReactiveShipping::Test::Credentials
5
+ include ReactiveShipping::Test::Fixtures
6
+
7
+ def setup
8
+ @carrier = FedEx.new(credentials(:fedex).merge(:test => true))
9
+ rescue NoCredentialsFound => e
10
+ skip(e.message)
11
+ end
12
+
13
+ ### valid_credentials?
14
+
15
+ def test_valid_credentials
16
+ valid_carrier = FedEx.new(credentials(:fedex))
17
+ assert valid_carrier.valid_credentials?
18
+
19
+ invalid_carrier = FedEx.new(credentials(:fedex).merge(password: 'invalid'))
20
+ refute invalid_carrier.valid_credentials?
21
+ end
22
+
23
+ ### find_rates
24
+
25
+ def test_us_to_canada
26
+ response = @carrier.find_rates(
27
+ location_fixtures[:beverly_hills],
28
+ location_fixtures[:ottawa],
29
+ package_fixtures.values_at(:wii)
30
+ )
31
+
32
+ assert_instance_of Array, response.rates
33
+ assert response.rates.length > 0
34
+ response.rates.each do |rate|
35
+ assert_instance_of String, rate.service_name
36
+ assert_kind_of Integer, rate.price
37
+ end
38
+ end
39
+
40
+ def test_freight
41
+ skip 'Cannot find the fedex freight creds. Whomp, whomp.'
42
+ freight = credentials(:fedex_freight)
43
+
44
+ shipping_location = Location.new( address1: freight[:shipping_address1],
45
+ address2: freight[:shipping_address2],
46
+ city: freight[:shipping_city],
47
+ state: freight[:shipping_state],
48
+ postal_code: freight[:shipping_postal_code],
49
+ country: freight[:shipping_country])
50
+
51
+ billing_location = Location.new( address1: freight[:billing_address1],
52
+ address2: freight[:billing_address2],
53
+ city: freight[:billing_city],
54
+ state: freight[:billing_state],
55
+ postal_code: freight[:billing_postal_code],
56
+ country: freight[:billing_country])
57
+
58
+ freight_options = {
59
+ account: freight[:account],
60
+ billing_location: billing_location,
61
+ payment_type: freight[:payment_type],
62
+ freight_class: freight[:freight_class],
63
+ packaging: freight[:packaging],
64
+ role: freight[:role]
65
+ }
66
+
67
+ response = @carrier.find_rates(
68
+ shipping_location,
69
+ location_fixtures[:ottawa],
70
+ package_fixtures.values_at(:wii),
71
+ freight: freight_options
72
+ )
73
+
74
+ assert_instance_of Array, response.rates
75
+ assert response.rates.length > 0
76
+ response.rates.each do |rate|
77
+ assert_instance_of String, rate.service_name
78
+ assert_kind_of Integer, rate.price
79
+ end
80
+ end
81
+
82
+ def test_zip_to_zip_fails
83
+ @carrier.find_rates(
84
+ Location.new(:zip => 40524),
85
+ Location.new(:zip => 40515),
86
+ package_fixtures[:wii]
87
+ )
88
+ rescue ResponseError => e
89
+ assert_match /country\s?code/i, e.message
90
+ assert_match /(missing|invalid)/, e.message
91
+ end
92
+
93
+ # FedEx requires a valid origin and destination postal code
94
+ def test_rates_for_locations_with_only_zip_and_country
95
+ response = @carrier.find_rates(
96
+ location_fixtures[:bare_beverly_hills],
97
+ location_fixtures[:bare_ottawa],
98
+ package_fixtures.values_at(:wii)
99
+ )
100
+
101
+ assert response.rates.size > 0
102
+ end
103
+
104
+ def test_rates_for_location_with_only_country_code
105
+ @carrier.find_rates(
106
+ location_fixtures[:bare_beverly_hills],
107
+ Location.new(:country => 'CA'),
108
+ package_fixtures.values_at(:wii)
109
+ )
110
+ rescue ResponseError => e
111
+ assert_match /postal code/i, e.message
112
+ assert_match /(missing|invalid)/i, e.message
113
+ end
114
+
115
+ def test_invalid_recipient_country
116
+ @carrier.find_rates(
117
+ location_fixtures[:bare_beverly_hills],
118
+ Location.new(:country => 'JP', :zip => '108-8361'),
119
+ package_fixtures.values_at(:wii)
120
+ )
121
+ rescue ResponseError => e
122
+ assert_match /postal code/i, e.message
123
+ assert_match /(missing|invalid)/i, e.message
124
+ end
125
+
126
+ def test_ottawa_to_beverly_hills
127
+ response = @carrier.find_rates(
128
+ location_fixtures[:ottawa],
129
+ location_fixtures[:beverly_hills],
130
+ package_fixtures.values_at(:book, :wii)
131
+ )
132
+
133
+ assert_instance_of Array, response.rates
134
+ assert response.rates.length > 0
135
+ response.rates.each do |rate|
136
+ assert_instance_of String, rate.service_name
137
+ assert_kind_of Integer, rate.price
138
+ end
139
+ end
140
+
141
+ def test_ottawa_to_london
142
+ response = @carrier.find_rates(
143
+ location_fixtures[:ottawa],
144
+ location_fixtures[:london],
145
+ package_fixtures.values_at(:book, :wii)
146
+ )
147
+
148
+ assert_instance_of Array, response.rates
149
+ assert response.rates.length > 0
150
+ response.rates.each do |rate|
151
+ assert_instance_of String, rate.service_name
152
+ assert_kind_of Integer, rate.price
153
+ end
154
+ end
155
+
156
+ def test_beverly_hills_to_netherlands
157
+ response = @carrier.find_rates(
158
+ location_fixtures[:beverly_hills],
159
+ location_fixtures[:netherlands],
160
+ package_fixtures.values_at(:book, :wii)
161
+ )
162
+
163
+ assert_instance_of Array, response.rates
164
+ assert response.rates.length > 0
165
+ response.rates.each do |rate|
166
+ assert_instance_of String, rate.service_name
167
+ assert_kind_of Integer, rate.price
168
+ end
169
+ end
170
+
171
+ def test_beverly_hills_to_new_york
172
+ response = @carrier.find_rates(
173
+ location_fixtures[:beverly_hills],
174
+ location_fixtures[:new_york],
175
+ package_fixtures.values_at(:book, :wii)
176
+ )
177
+
178
+ assert_instance_of Array, response.rates
179
+ assert response.rates.length > 0
180
+ response.rates.each do |rate|
181
+ assert_instance_of String, rate.service_name
182
+ assert_kind_of Integer, rate.price
183
+ end
184
+ end
185
+
186
+ def test_beverly_hills_to_london
187
+ response = @carrier.find_rates(
188
+ location_fixtures[:beverly_hills],
189
+ location_fixtures[:london],
190
+ package_fixtures.values_at(:book, :wii)
191
+ )
192
+
193
+ assert_instance_of Array, response.rates
194
+ assert response.rates.length > 0
195
+ response.rates.each do |rate|
196
+ assert_instance_of String, rate.service_name
197
+ assert_kind_of Integer, rate.price
198
+ end
199
+ end
200
+
201
+ def test_different_rates_for_commercial
202
+ residential_response = @carrier.find_rates(
203
+ location_fixtures[:beverly_hills],
204
+ location_fixtures[:ottawa],
205
+ package_fixtures.values_at(:chocolate_stuff)
206
+ )
207
+ commercial_response = @carrier.find_rates(
208
+ location_fixtures[:beverly_hills],
209
+ Location.from(location_fixtures[:ottawa].to_hash, :address_type => :commercial),
210
+ package_fixtures.values_at(:chocolate_stuff)
211
+ )
212
+
213
+ refute_equal residential_response.rates.map(&:price), commercial_response.rates.map(&:price)
214
+ end
215
+
216
+ ### find_tracking_info
217
+
218
+ def test_find_tracking_info_for_delivered_shipment
219
+ response = @carrier.find_tracking_info('122816215025810')
220
+ assert response.success?
221
+ assert response.delivered?
222
+ assert_equal '122816215025810', response.tracking_number
223
+ assert_equal :delivered, response.status
224
+ assert_equal 'DL', response.status_code
225
+ assert_equal "Delivered", response.status_description
226
+
227
+ assert_equal Time.parse('Fri, 03 Jan 2014'), response.ship_time
228
+ assert_nil response.scheduled_delivery_date
229
+ assert_equal Time.parse('2014-01-09 18:31:00 +0000'), response.actual_delivery_date
230
+
231
+ origin_address = ReactiveShipping::Location.new(
232
+ city: 'SPOKANE',
233
+ country: 'US',
234
+ state: 'WA'
235
+ )
236
+ assert_equal origin_address.to_hash, response.origin.to_hash
237
+
238
+ destination_address = ReactiveShipping::Location.new(
239
+ city: 'NORTON',
240
+ country: 'US',
241
+ state: 'VA'
242
+ )
243
+ assert_equal destination_address.to_hash, response.destination.to_hash
244
+ assert_equal 11, response.shipment_events.length
245
+ assert_equal 'OC', response.shipment_events.first.type_code
246
+ assert_equal 'PU', response.shipment_events.second.type_code
247
+ assert_equal 'AR', response.shipment_events.third.type_code
248
+ end
249
+
250
+ def test_find_tracking_info_for_in_transit_shipment_1
251
+ # unfortunately, we have to use Fedex unique identifiers, because the test tracking numbers are overloaded.
252
+ response = @carrier.find_tracking_info('920241085725456')
253
+ assert response.success?
254
+ refute response.delivered?
255
+ assert_equal '920241085725456', response.tracking_number
256
+ assert_equal :at_fedex_destination, response.status
257
+ assert_equal 'FD', response.status_code
258
+ assert_equal "At FedEx destination facility", response.status_description
259
+ assert_equal 7, response.shipment_events.length
260
+ assert_equal 'PU', response.shipment_events.first.type_code
261
+ assert_equal 'OC', response.shipment_events.second.type_code
262
+ assert_equal 'AR', response.shipment_events.third.type_code
263
+ assert_nil response.actual_delivery_date
264
+ assert_nil response.scheduled_delivery_date
265
+ end
266
+
267
+ def test_find_tracking_info_for_in_transit_shipment_2
268
+ # unfortunately, we have to use Fedex unique identifiers, because the test tracking numbers are overloaded.
269
+ response = @carrier.find_tracking_info('403934084723025')
270
+ assert response.success?
271
+ refute response.delivered?
272
+ assert_equal '403934084723025', response.tracking_number
273
+ assert_equal :at_fedex_facility, response.status
274
+ assert_equal 'AR', response.status_code
275
+ assert_equal "Arrived at FedEx location", response.status_description
276
+
277
+ assert_equal Time.parse('Fri, 03 Jan 2014'), response.ship_time
278
+ assert_nil response.scheduled_delivery_date
279
+ assert_nil response.actual_delivery_date
280
+
281
+ origin_address = ReactiveShipping::Location.new(
282
+ city: 'CAMBRIDGE',
283
+ country: 'US',
284
+ state: 'OH'
285
+ )
286
+ assert_equal origin_address.to_hash, response.origin.to_hash
287
+
288
+ destination_address = ReactiveShipping::Location.new(
289
+ city: 'Spokane Valley',
290
+ country: 'US',
291
+ state: 'WA'
292
+ )
293
+ assert_equal destination_address.to_hash, response.destination.to_hash
294
+ assert_equal 3, response.shipment_events.length
295
+ assert_equal 'PU', response.shipment_events.first.type_code
296
+ assert_equal 'OC', response.shipment_events.second.type_code
297
+ assert_equal 'AR', response.shipment_events.third.type_code
298
+ end
299
+
300
+ def test_find_tracking_info_with_multiple_matches
301
+ exception = assert_raises(ReactiveShipping::Error) do
302
+ response = @carrier.find_tracking_info('123456789012')
303
+ end
304
+ assert_match 'Multiple matches were found.', exception.message
305
+ end
306
+
307
+ def test_find_tracking_info_not_found
308
+ assert_raises(ReactiveShipping::ShipmentNotFound) do
309
+ @carrier.find_tracking_info('199997777713')
310
+ end
311
+ end
312
+
313
+ def test_find_tracking_info_with_invalid_tracking_number
314
+ assert_raises(ReactiveShipping::ResponseError) do
315
+ @carrier.find_tracking_info('abc')
316
+ end
317
+ end
318
+
319
+ ### create_shipment
320
+
321
+ def test_cant_obtain_multiple_shipping_labels
322
+ assert_raises(ReactiveShipping::Error,"Multiple packages are not supported yet.") do
323
+ @carrier.create_shipment(
324
+ location_fixtures[:beverly_hills_with_name],
325
+ location_fixtures[:new_york_with_name],
326
+ [package_fixtures[:wii],package_fixtures[:wii]],
327
+ :test => true,
328
+ :reference_number => {
329
+ :value => "FOO-123",
330
+ :code => "PO"
331
+ }
332
+ )
333
+ end
334
+ end
335
+
336
+ def test_obtain_shipping_label_with_single_element_array
337
+ response = @carrier.create_shipment(
338
+ location_fixtures[:beverly_hills_with_name],
339
+ location_fixtures[:new_york_with_name],
340
+ [package_fixtures[:wii]],
341
+ :test => true,
342
+ :reference_number => {
343
+ :value => "FOO-123",
344
+ :code => "PO"
345
+ }
346
+ )
347
+
348
+ assert response.success?
349
+ refute_empty response.labels
350
+ refute_empty response.labels.first.img_data
351
+ end
352
+
353
+ def test_obtain_shipping_label
354
+ response = @carrier.create_shipment(
355
+ location_fixtures[:beverly_hills_with_name],
356
+ location_fixtures[:new_york_with_name],
357
+ package_fixtures[:wii],
358
+ :test => true,
359
+ :reference_number => {
360
+ :value => "FOO-123",
361
+ :code => "PO"
362
+ }
363
+ )
364
+
365
+ assert response.success?
366
+ refute_empty response.labels
367
+ refute_empty response.labels.first.img_data
368
+ end
369
+
370
+ def test_obtain_shipping_label_with_signature_option
371
+ packages = package_fixtures.values_at(:wii)
372
+ packages.each {|p| p.options[:signature_option] = :adult }
373
+
374
+ response = @carrier.create_shipment(
375
+ location_fixtures[:beverly_hills_with_name],
376
+ location_fixtures[:new_york_with_name],
377
+ packages,
378
+ {:test => true}
379
+ )
380
+
381
+ signature_option = response.params["ProcessShipmentReply"]["CompletedShipmentDetail"]["CompletedPackageDetails"]["SignatureOption"]
382
+ assert_equal FedEx::SIGNATURE_OPTION_CODES[:adult], signature_option
383
+ end
384
+
385
+ def test_obtain_shipping_label_with_label_format_option
386
+ response = @carrier.create_shipment(
387
+ location_fixtures[:beverly_hills_with_name],
388
+ location_fixtures[:new_york_with_name],
389
+ package_fixtures[:wii],
390
+ :test => true,
391
+ :label_format => 'PDF'
392
+ )
393
+
394
+ assert response.success?
395
+ refute_empty response.labels
396
+ data = response.labels.first.img_data
397
+ refute_empty data
398
+ assert data[0...4] == '%PDF'
399
+ end
400
+ end