Skip to content

Commit

Permalink
Add more tests for get_rates method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsears committed Apr 22, 2011
1 parent 6873bb2 commit 641088b
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 12 deletions.
17 changes: 17 additions & 0 deletions lib/stamps/client/rate.rb
@@ -1,7 +1,24 @@
module Stamps
class Client

# Produces a list of rates for all available USPS services based
# on the ZIP Code or the foreign country being shipped to for
# a given package weight and size.
#
# == Examples:
#
# Stamps.get_rates(
# :from_zip_code => '45440',
# :to_zip_code => '45458',
# :weight_oz => '8.0',
# :ship_date => '2011-06-01'
# )
#
module Rate

# Produces a list of rates matching the criteria provided in
# the parameters
#
def get_rates(params = {})
rates = Stamps::Mapping::Rates.new({
:authenticator => authenticator_token,
Expand Down
22 changes: 16 additions & 6 deletions test/client/rate_test.rb
Expand Up @@ -8,23 +8,33 @@ class StampsTest < Test::Unit::TestCase
end

context ".get_rates" do

setup do
stub_post("GetRates")
@rates = Stamps.get_rates(
:from_zip_code => '45440',
:to_zip_code => '45458',
:weight_lb => '0.5',
:ship_date => '2011-06-01'
)
@rates = Stamps.get_rates
end

should 'return an array of rates' do
assert_equal Array, @rates.class
end

should 'assign the amount for a given rate' do
assert_equal "2.41", @rates.first.amount
end

end

context '.get_rates with package and service types' do

setup do
stub_post("GetRate", 'GetRates')
@rate = Stamps.get_rate
end

should 'return an Hashie::Mash for the single rate' do
assert_equal Hashie::Mash, @rate.class
end

end
end
end
163 changes: 163 additions & 0 deletions test/fixtures/GetRate.xml
@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetRatesResponse xmlns="http://stamps.com/xml/namespace/2010/11/swsim/swsimv12">
<Authenticator>X9EFGtLfk2QZ8EQ8tMIQ/x/J0i4=</Authenticator>
<Rates>
<Rate>
<FromZIPCode>45440</FromZIPCode>
<ToZIPCode>45458</ToZIPCode>
<ToCountry>US</ToCountry>
<Amount>4.8</Amount>
<ServiceType>US-PM</ServiceType>
<DeliverDays>1</DeliverDays>
<WeightOz>7.8</WeightOz>
<PackageType>Package</PackageType>
<ShipDate>2011-04-21</ShipDate>
<DimWeighting>N</DimWeighting>
<AddOns>
<AddOnV2>
<AddOnType>US-A-INS</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>SC-A-HP</AddOnTypeV2>
<AddOnTypeV2>US-A-REG</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
<AddOnTypeV2>US-A-COD</AddOnTypeV2>
<AddOnTypeV2>SC-A-INS</AddOnTypeV2>
</ProhibitedWithAnyOf>
<MissingData>InsuredValue</MissingData>
</AddOnV2>
<AddOnV2>
<AddOnType>US-A-COD</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>SC-A-HP</AddOnTypeV2>
<AddOnTypeV2>US-A-RRM</AddOnTypeV2>
<AddOnTypeV2>US-A-INS</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
</ProhibitedWithAnyOf>
<MissingData>CODValue</MissingData>
</AddOnV2>
<AddOnV2>
<AddOnType>US-A-DC</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>US-A-SC</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
<AddOnV2>
<Amount>2.05</Amount>
<AddOnType>US-A-SC</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>US-A-DC</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
<AddOnTypeV2>US-A-RRM</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
<AddOnV2>
<Amount>2.85</Amount>
<AddOnType>US-A-CM</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>SC-A-HP</AddOnTypeV2>
<AddOnTypeV2>US-A-RRM</AddOnTypeV2>
<AddOnTypeV2>US-A-REG</AddOnTypeV2>
<AddOnTypeV2>US-A-DC</AddOnTypeV2>
<AddOnTypeV2>US-A-COD</AddOnTypeV2>
<AddOnTypeV2>US-A-SC</AddOnTypeV2>
<AddOnTypeV2>US-A-INS</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
<AddOnV2>
<Amount>2.3</Amount>
<AddOnType>US-A-RR</AddOnType>
<RequiresAllOf>
<RequiresOneOf>
<AddOnTypeV2>US-A-COD</AddOnTypeV2>
<AddOnTypeV2>US-A-REG</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
<AddOnTypeV2>US-A-INS</AddOnTypeV2>
</RequiresOneOf>
</RequiresAllOf>
<ProhibitedWithAnyOf>
<AddOnTypeV2>SC-A-HP</AddOnTypeV2>
<AddOnTypeV2>US-A-RRM</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
<AddOnV2>
<Amount>10.75</Amount>
<AddOnType>US-A-REG</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>SC-A-HP</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
<AddOnTypeV2>US-A-INS</AddOnTypeV2>
<AddOnTypeV2>US-A-RRM</AddOnTypeV2>
<AddOnTypeV2>SC-A-INS</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
<AddOnV2>
<Amount>4.5</Amount>
<AddOnType>US-A-RD</AddOnType>
<RequiresAllOf>
<RequiresOneOf>
<AddOnTypeV2>US-A-COD</AddOnTypeV2>
<AddOnTypeV2>US-A-REG</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
<AddOnTypeV2>US-A-INS</AddOnTypeV2>
</RequiresOneOf>
</RequiresAllOf>
<ProhibitedWithAnyOf>
<AddOnTypeV2>SC-A-HP</AddOnTypeV2>
<AddOnTypeV2>US-A-RRM</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
<AddOnV2>
<AddOnType>SC-A-INS</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>US-A-REG</AddOnTypeV2>
<AddOnTypeV2>US-A-INS</AddOnTypeV2>
</ProhibitedWithAnyOf>
<MissingData>InsuredValue</MissingData>
</AddOnV2>
<AddOnV2>
<AddOnType>SC-A-HP</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>US-A-RRM</AddOnTypeV2>
<AddOnTypeV2>US-A-INS</AddOnTypeV2>
<AddOnTypeV2>US-A-REG</AddOnTypeV2>
<AddOnTypeV2>US-A-RD</AddOnTypeV2>
<AddOnTypeV2>US-A-COD</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
<AddOnTypeV2>US-A-RR</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
<AddOnV2>
<Amount>3.9</Amount>
<AddOnType>US-A-NND</AddOnType>
<RequiresAllOf>
<RequiresOneOf>
<AddOnTypeV2>US-A-COD</AddOnTypeV2>
</RequiresOneOf>
</RequiresAllOf>
</AddOnV2>
<AddOnV2>
<Amount>3.85</Amount>
<AddOnType>US-A-RRM</AddOnType>
<ProhibitedWithAnyOf>
<AddOnTypeV2>SC-A-HP</AddOnTypeV2>
<AddOnTypeV2>US-A-REG</AddOnTypeV2>
<AddOnTypeV2>US-A-RD</AddOnTypeV2>
<AddOnTypeV2>US-A-COD</AddOnTypeV2>
<AddOnTypeV2>US-A-SC</AddOnTypeV2>
<AddOnTypeV2>US-A-CM</AddOnTypeV2>
<AddOnTypeV2>US-A-RR</AddOnTypeV2>
</ProhibitedWithAnyOf>
</AddOnV2>
</AddOns>
<EffectiveWeightInOunces>8</EffectiveWeightInOunces>
<IsIntraBMC>true</IsIntraBMC>
<Zone>1</Zone>
<RateCategory>805310512</RateCategory>
</Rate>
</Rates>
</GetRatesResponse>
</soap:Body>
</soap:Envelope>
9 changes: 3 additions & 6 deletions test/helper.rb
Expand Up @@ -3,10 +3,6 @@

require 'simplecov'
SimpleCov.merge_timeout 3600
SimpleCov.start do
add_group 'Stamps', 'lib/stamps'
add_group 'Faraday Middleware', 'lib/faraday'
end

require 'mocha'
require 'test/unit'
Expand All @@ -33,9 +29,10 @@
end

# Stub requests
def stub_post(web_method)
def stub_post(web_method, soap_action = nil)
soap_action = web_method if soap_action.nil?
stub_request(:post, Stamps.endpoint).
with(:headers => {"SoapAction" => "#{Stamps.namespace}/#{web_method}"}).
with(:headers => {"SoapAction" => "#{Stamps.namespace}/#{soap_action}"}).
to_return(:body => fixture("#{web_method}.xml"))
end

Expand Down

0 comments on commit 641088b

Please sign in to comment.