Skip to content
This repository was archived by the owner on Jun 13, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rvm:
- "2.2.2"
- "2.3.1"
- "2.4.0"
- "2.5.3"

gemfile:
- gemfiles/activesupport42.gemfile
Expand All @@ -24,4 +25,5 @@ env:
- ACTIVESHIPPING_CANADA_POST_PWS_CUSTOMER_NUMBER=2004381
- ACTIVESHIPPING_CANADA_POST_PWS_API_KEY=6e93d53968881714
- ACTIVESHIPPING_CANADA_POST_PWS_SECRET=0bfa9fcb9853d1f51ee57a
- ACTIVESHIPPING_CANADA_POST_PWS_CONTRACT=42708517
- ACTIVESHIPPING_USPS_LOGIN=677JADED7283
2 changes: 1 addition & 1 deletion active_shipping.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|


s.add_dependency("measured", ">= 2.0")
s.add_dependency("activesupport", ">= 4.2", "< 5.2.0")
s.add_dependency("activesupport", ">= 4.2", "< 6.1.0")
s.add_dependency("active_utils", "~> 3.3.1")
s.add_dependency("nokogiri", ">= 1.6")

Expand Down
2 changes: 1 addition & 1 deletion dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: active-shipping

up:
- ruby: 2.3.1
- ruby: 2.5.3
- bundler

commands:
Expand Down
6 changes: 6 additions & 0 deletions gemfiles/activesupport60.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://rubygems.org"

gemspec path: '..'

gem 'activesupport', '~> 6.0.0'
gem 'active_utils', '~> 3.3.0'
322 changes: 318 additions & 4 deletions lib/active_shipping/carriers/canada_post_pws.rb

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/active_shipping/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def to_s
prettyprint.gsub(/\n/, ' ')
end

def postal_simple
@postal_code.sub(/[^a-zA-Z0-9]/,'')
end

def prettyprint
chunks = [@name, @address1, @address2, @address3]
chunks << [@city, @province, @postal_code].reject(&:blank?).join(', ')
Expand Down
2 changes: 1 addition & 1 deletion lib/active_shipping/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveShipping
VERSION = "2.2.0"
VERSION = "2.2.2"
end
1 change: 1 addition & 0 deletions test/credentials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ canada_post_pws:
customer_number: <%= ENV['ACTIVESHIPPING_CANADA_POST_PWS_CUSTOMER_NUMBER'] %>
api_key: <%= ENV['ACTIVESHIPPING_CANADA_POST_PWS_API_KEY'] %>
secret: <%= ENV['ACTIVESHIPPING_CANADA_POST_PWS_SECRET'] %>
contract_number: <%= ENV['ACTIVESHIPPING_CANADA_POST_PWS_CONTRACT'] %>

canada_post_pws_platform:
platform_id: <%= ENV['ACTIVESHIPPING_CANADA_POST_PWS_PLATFORM_PLATFORM_ID'] %>
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/xml/canadapost_pws/group_ids_response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<groups>
<group>
<link rel="group" href="https://XX/rs/111111111/222222222/shipment?groupid=123456" media-type="application/vnd.cpc.shipment-v8+xml"></link>
<group-id>123456</group-id>
</group>
</groups>
7 changes: 7 additions & 0 deletions test/fixtures/xml/canadapost_pws/manifest_details.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest>
<po-number>D906367941</po-number>
<links>
<link rel="self" href="https://XX/rs/111111111/222222222/manifest/33333333" media-type="application/vnd.cpc.manifest-v8+xml"></link>
<link rel="details" href="https://XX/rs/111111111/222222222/manifest/666666666/details" media-type="application/vnd.cpc.manifest-v8+xml"></link>
</links>
</manifest>
4 changes: 4 additions & 0 deletions test/fixtures/xml/canadapost_pws/transmit_response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<manifests>
<link rel="manifest" href="https://XX/1111111111/222222222/manifest/444444444444" media-type="application/vnd.cpc.manifest-v8+xml"></link>
<link rel="manifest" href="https://XX/1111111111/222222222/manifest/333333333333" media-type="application/vnd.cpc.manifest-v8+xml"></link>
</manifests>
20 changes: 20 additions & 0 deletions test/fixtures/xml/canadapost_pws/transmit_set.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<transmit-set xmlns="http://www.canadapost.ca/ws/manifest-v8">
<group-ids>
<group-id>1234</group-id>
</group-ids>
<requested-shipping-point>K1K4T3</requested-shipping-point>
<cpc-pickup-indicator>true</cpc-pickup-indicator>
<detailed-manifests>true</detailed-manifests>
<method-of-payment>Account</method-of-payment>
<manifest-address>
<manifest-company>my company</manifest-company>
<manifest-name>MajorShop</manifest-name>
<phone-number>555 555 5555</phone-number>
<address-details>
<address-line-1>1230 Tako RD.</address-line-1>
<city>Ottawa</city>
<prov-state>ON</prov-state>
<postal-zip-code>K1A1A1</postal-zip-code>
</address-details>
</manifest-address>
</transmit-set>
60 changes: 51 additions & 9 deletions test/remote/canada_post_pws_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

class RemoteCanadaPostPWSTest < ActiveSupport::TestCase
# All remote tests require Canada Post development environment credentials
# When using an account with a contract number you should add it to the opts hash

include ActiveShipping::Test::Credentials
include ActiveShipping::Test::Fixtures

Expand All @@ -14,7 +16,9 @@ def setup

@line_item1 = line_item_fixture

@shipping_opts1 = { :dc => true, :cov => true, :cov_amount => 100.00, :aban => true }
@shipping_opts1 = {:cod => true, :dc => true, :cov => true, :cov_amount => 100.00, :aban => true }

@shipping_opts2 = {so: true, cov: true, cov_amount: 999.99, transmit: true, shipping_point: 'R3W1S1'}

@home_params = {
:name => "John Smith",
Expand All @@ -23,11 +27,22 @@ def setup
:address1 => "123 Elm St.",
:city => 'Ottawa',
:province => 'ON',
:country => 'CA',
:postal_code => 'K1P 1J1'
}
@home = Location.new(@home_params)

@contract_home_params = {
:name => "John Smith",
:company => "test",
:phone => "613-555-1212",
:address1 => "123 Elm St.",
:city => 'Ottawa',
:province => 'ON',
:country => 'CA',
:postal_code => 'K1P 1J1'
}
@contract_home = Location.new(@contract_home_params)

@dom_params = {
:name => "John Smith Sr.",
:company => "",
Expand Down Expand Up @@ -77,6 +92,7 @@ def setup
@cp.logger = Logger.new(StringIO.new)

@customer_number = @login[:customer_number]
@contract_number = @login[:contract_number]

@DEFAULT_RESPONSE = {
:shipping_id => "406951321983787352",
Expand Down Expand Up @@ -121,25 +137,51 @@ def test_tracking_when_no_tracking_info_raises_exception
end

def test_create_shipment
skip "Failing with 'Contract Number is a required field' after API change, skipping because no clue how to fix, might need different creds"
skip "contract number in credentials" if @contract_number
opts = {:customer_number => @customer_number, :service => "DOM.XP"}
response = @cp.create_shipment(@home_params, @dom_params, @pkg1, @line_item1, opts)
assert_kind_of CPPWSShippingResponse, response
assert_match /\A\d{17}\z/, response.shipping_id
assert_match /\A\d{18}\z/, response.shipping_id
assert_equal "123456789012", response.tracking_number
assert_match "https://ct.soa-gw.canadapost.ca/ers/artifact/", response.label_url
assert_match "https://ct.soa-gw.canadapost.ca/rs/artifact/", response.label_url
assert_match @login[:api_key], response.label_url
end

def test_create_shipment_with_options
skip "Failing with 'Contract Number is a required field' after API change, skipping because no clue how to fix, might need different creds"
skip "contract number in credentials" if @contract_number
opts = {:customer_number => @customer_number, :service => "USA.EP"}.merge(@shipping_opts1)
response = @cp.create_shipment(@home_params, @dest_params, @pkg1, @line_item1, opts)

assert_kind_of CPPWSShippingResponse, response
assert_match /\A\d{17}\z/, response.shipping_id
assert_match /\A\d{18}\z/, response.shipping_id
assert_equal "123456789012", response.tracking_number
assert_match "https://ct.soa-gw.canadapost.ca/rs/artifact/", response.label_url
assert_match @login[:api_key], response.label_url
end

def test_create_contract_shipment_with_options
skip "no contract number in credentials" unless @contract_number
opts = {:customer_number => @customer_number, :service => "DOM.XP", contract_number: @contract_number}.merge(@shipping_opts2)
response = @cp.create_contract_shipment(@contract_home_params, @dom_params, @pkg1, @line_item1, opts)
assert_kind_of CPPWSContractShippingResponse, response
assert_match /\A\d{18}\z/, response.shipping_id
assert_equal "123456789012", response.tracking_number
assert_match "https://ct.soa-gw.canadapost.ca/rs/artifact/", response.label_url
assert_match @login[:api_key], response.label_url
end

def test_create_contract_shipment_with_return_label_and_options
skip "no contract number in credentials" unless @contract_number

opts = {:customer_number => @customer_number, :service => "DOM.XP", contract_number: @contract_number}.merge(@shipping_opts2)

return_details = {service_code: 'DOM.RP', return_recipient: { address_details: @contract_home_params } }

response = @cp.create_contract_shipment(@contract_home_params, @dom_params, @pkg1, @line_item1, opts, return_details)
assert_kind_of CPPWSContractShippingResponse, response
assert_match /\A\d{18}\z/, response.shipping_id
assert_equal "123456789012", response.tracking_number
assert_match "https://ct.soa-gw.canadapost.ca/ers/artifact/", response.label_url
assert_match "https://ct.soa-gw.canadapost.ca/rs/artifact/", response.label_url
assert_match "https://ct.soa-gw.canadapost.ca/rs/artifact/", response.return_label_url
assert_match @login[:api_key], response.label_url
end

Expand Down
40 changes: 40 additions & 0 deletions test/unit/carriers/canada_post_pws_shipping_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def setup
:so => true, :pa18 => true}

@default_options = {:customer_number => '123456'}
@default_contract_options = {:customer_number => '123456', :contract_number => '42708517'}

@DEFAULT_RESPONSE = {
:shipping_id => "406951321983787352",
Expand Down Expand Up @@ -93,6 +94,30 @@ def test_build_shipment_request_for_domestic
refute request.blank?
end

def test_build_contract_shipment_request_for_domestic
options = @default_contract_options.dup
request = @cp.build_contract_shipment_request(@home_params, @dom_params, @pkg1, @line_item1, options)
refute request.blank?
end

def test_build_contract_shipment_with_return_request_for_domestic
options = @default_contract_options.dup
return_details = {service_code: 'DOM.RP', return_recipient: { address_details: @home_params } }

request = @cp.build_contract_shipment_request(@home_params, @dom_params, @pkg1, @line_item1, options, return_details)
refute request.blank?

doc = Nokogiri.XML(request)
doc.remove_namespaces!

assert root_node = doc.at('shipment')
assert delivery_spec = root_node.at('delivery-spec')
assert destination = delivery_spec.at('destination')
assert address_details = destination.at('address-details')
assert_equal 'CA', address_details.at('country-code').text
assert return_spec = root_node.at('return-spec')
end

def test_build_shipment_request_for_US
options = @default_options.dup
request = @cp.build_shipment_request(@home_params, @us_params, @pkg1, @line_item1, options)
Expand Down Expand Up @@ -255,4 +280,19 @@ def test_parse_find_shipment_receipt_doesnt_break_without_priced_options
def test_maximum_address_field_length
assert_equal 44, @cp.maximum_address_field_length
end

def test_manifest_group_ids
options = @default_options.dup
xml_response = xml_fixture('canadapost_pws/group_ids_response')
@cp.expects(:ssl_get).once.returns(xml_response)
response = @cp.list_group_ids(options)
assert_equal @cp.parse_group_ids_response(xml_response).group_ids, response.group_ids
end

def test_transmit_shipments
options = @default_options.dup
xml_response = xml_fixture('canadapost_pws/transmit_response')
response = @cp.transmit_shipments(Location.new(@home_params), options)
assert response.nil?
end
end
6 changes: 3 additions & 3 deletions test/unit/carriers/canada_post_pws_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ def setup
def test_get_sanitized_postal_code_location_nil
postal_code = @cp.send(:get_sanitized_postal_code, nil)

assert_equal nil, postal_code
assert_nil postal_code
end

def test_get_sanitized_postal_code_postal_code_nil
location = Location.new(name: 'Test test')

assert_equal nil, location.postal_code
assert_nil location.postal_code

postal_code = @cp.send(:get_sanitized_postal_code, location)

assert_equal nil, postal_code
assert_nil postal_code
end

def test_get_sanitized_postal_code_spaces
Expand Down