summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJared Norman <jared@super.gd>2019-01-30 13:14:58 -0800
committerJared Norman <jared@super.gd>2019-01-30 13:19:10 -0800
commit054a25e9da909242fef25770c31678c251621573 (patch)
tree91d4efe2b32378886af45eba0a7eda6c983d8768 /spec
parent8f3744abd7f06da848856136a7888c2b01b40ee5 (diff)
Extract address lookup params as well
Diffstat (limited to 'spec')
-rw-r--r--spec/super_good/solidus_taxjar/api_params_spec.rb16
-rw-r--r--spec/super_good/solidus_taxjar/api_spec.rb59
2 files changed, 28 insertions, 47 deletions
diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb
index d880e7f..8677153 100644
--- a/spec/super_good/solidus_taxjar/api_params_spec.rb
+++ b/spec/super_good/solidus_taxjar/api_params_spec.rb
@@ -122,4 +122,20 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do
)
end
end
+
+ describe "#address_params" do
+ subject { described_class.address_params(ship_address) }
+
+ it "returns params for fetching the tax info for that address" do
+ expect(subject).to eq([
+ "90210",
+ {
+ city: "Los Angeles",
+ country: "US",
+ state: "CA",
+ street: "475 N Beverly Dr"
+ }
+ ])
+ end
+ end
end
diff --git a/spec/super_good/solidus_taxjar/api_spec.rb b/spec/super_good/solidus_taxjar/api_spec.rb
index 2c35299..1b6defd 100644
--- a/spec/super_good/solidus_taxjar/api_spec.rb
+++ b/spec/super_good/solidus_taxjar/api_spec.rb
@@ -26,55 +26,20 @@ RSpec.describe SuperGood::SolidusTaxJar::API do
describe "#tax_rates_for" do
subject { api.tax_rates_for address }
- let(:api) do
- described_class.new(taxjar_client: dummy_client)
- end
-
- let(:dummy_client) do
- instance_double ::Taxjar::Client
- end
-
- let(:address) do
- Spree::Address.create!(
- country: country_us,
- state: state_california,
- zipcode: "90210",
- city: "Los Angeles",
- address1: "475 N Beverly Dr",
-
- first_name: "Chuck",
- last_name: "Schuldiner",
- phone: "1-250-555-4444"
- )
- end
-
- let(:country_us) do
- Spree::Country.create!(
- iso_name: "UNITED STATES",
- iso: "US",
- iso3: "USA",
- name: "United States",
- numcode: 840,
- states_required: true
- )
- end
-
- let(:state_california) do
- Spree::State.create!(
- country: country_us,
- name: "California",
- abbr: "CA"
- )
- end
+ let(:api) { described_class.new(taxjar_client: dummy_client) }
+ let(:dummy_client) { instance_double ::Taxjar::Client }
+ let(:address) { Spree::Address.new }
before do
- allow(dummy_client).to receive(:rates_for_location).with(
- "90210",
- country: "US",
- city: "Los Angeles",
- state: "CA",
- street: "475 N Beverly Dr"
- ).and_return({ some_kind_of: "response" })
+ allow(SuperGood::SolidusTaxJar::APIParams)
+ .to receive(:address_params)
+ .with(address)
+ .and_return(["zipcode", { address: "params" }])
+
+ allow(dummy_client)
+ .to receive(:rates_for_location)
+ .with("zipcode", { address: "params" })
+ .and_return({ some_kind_of: "response" })
end
it { is_expected.to eq({ some_kind_of: "response" }) }