Sha256: 754b820851da826a5d8587bf5bb5544191bc63fae3cc64e83d11b03a30c7827d

Contents?: true

Size: 1.7 KB

Versions: 62

Compression:

Stored size: 1.7 KB

Contents

require 'test_helper'

class RemoteCanadaPostTest < ActiveSupport::TestCase
  include ActiveShipping::Test::Credentials

  def setup
    @carrier        = CanadaPost.new(credentials(:canada_post))
    @french_carrier = CanadaPost.new(credentials(:canada_post).merge(french: true))

    @origin      = { address1: "61A York St", city: "Ottawa", province: "Ontario", country: "Canada", postal_code: "K1N 5T2" }
    @destination = { city: "Beverly Hills", state: "CA", country: "United States", postal_code: "90210" }
    @line_items  = [Package.new(500, [2, 3, 4], description: "a box full of stuff", value: 25)]
  rescue NoCredentialsFound => e
    skip(e.message)
  end

  def test_valid_credentials
    assert @carrier.valid_credentials?
  end

  def test_find_rates_french
    rates = @french_carrier.find_rates(@origin, @destination, @line_items)
    assert_instance_of CanadaPost::CanadaPostRateResponse, rates
  end

  def test_postal_outlets_french
    rates = @french_carrier.find_rates(@origin, @destination, @line_items)

    rates.postal_outlets.each do |outlet|
      assert_instance_of CanadaPost::PostalOutlet, outlet
    end
  end

  def test_find_rates
    rates = @carrier.find_rates(@origin, @destination, @line_items)
    assert_instance_of CanadaPost::CanadaPostRateResponse, rates
  end

  def test_postal_outlets
    rates = @carrier.find_rates(@origin, @destination, @line_items)

    rates.postal_outlets.each do |outlet|
      assert_instance_of CanadaPost::PostalOutlet, outlet
    end
  end

  def test_illegal_origin
    @origin = @destination

    assert_raises(ActiveShipping::ResponseError) do
      rates = @carrier.find_rates(@origin, @destination, @line_items)
      refute rates.success?
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.36 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.14 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.35 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.13 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.34 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.12 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.33 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.11 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.10 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.32 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.9 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.31 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.8 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.30 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.7 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.29 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.6 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.4.28 vendor/active_shipping/test/remote/canada_post_test.rb
workarea-core-3.5.5 vendor/active_shipping/test/remote/canada_post_test.rb