Sha256: 839d48c8cc1e23b54d6d8fd5bb6ee1c36536aa7bb0fc2442dee9f3b3b0e6fd52

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

require 'test_helper'

class CanadaPostTest < Minitest::Test
  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)]
  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

1 entries across 1 versions & 1 rubygems

Version Path
active_shipping-1.0.0.pre3 test/remote/canada_post_test.rb