diff options
author | Jared Norman <jared@super.gd> | 2019-01-30 17:15:37 -0800 |
---|---|---|
committer | Jared Norman <jared@super.gd> | 2019-01-30 17:15:37 -0800 |
commit | 1fdfaff9bef12831cace3f0661c2bb3209500220 (patch) | |
tree | f22b78268d69d2b0cee538a6d05dfdcd3025dc4e /spec | |
parent | 054a25e9da909242fef25770c31678c251621573 (diff) |
Add ability to create order transactions
Diffstat (limited to 'spec')
-rw-r--r-- | spec/super_good/solidus_taxjar/api_params_spec.rb | 30 | ||||
-rw-r--r-- | spec/super_good/solidus_taxjar/api_spec.rb | 22 |
2 files changed, 49 insertions, 3 deletions
diff --git a/spec/super_good/solidus_taxjar/api_params_spec.rb b/spec/super_good/solidus_taxjar/api_params_spec.rb index 8677153..cb70804 100644 --- a/spec/super_good/solidus_taxjar/api_params_spec.rb +++ b/spec/super_good/solidus_taxjar/api_params_spec.rb @@ -3,12 +3,17 @@ require 'spec_helper' RSpec.describe SuperGood::SolidusTaxJar::APIParams do let(:order) do Spree::Order.create!( - item_total: 28.00, - shipment_total: 3.01, + number: "R111222333", + total: BigDecimal("123.45"), + shipment_total: BigDecimal("3.01"), + additional_tax_total: BigDecimal("9.87"), + item_total: BigDecimal("28.00"), store: store, ship_address: ship_address, line_items: [line_item] - ) + ).tap do |order| + order.update! completed_at: DateTime.new(2018, 3, 6, 12, 10, 33) + end end let(:store) do @@ -138,4 +143,23 @@ RSpec.describe SuperGood::SolidusTaxJar::APIParams do ]) end end + + describe "#transaction_params" do + subject { described_class.transaction_params(order) } + + it "returns params for creating/updating an order transaction" do + expect(subject).to eq({ + amount: BigDecimal("113.58"), + sales_tax: BigDecimal("9.87"), + shipping: BigDecimal("3.01"), + to_city: "Los Angeles", + to_country: "US", + to_state: "CA", + to_street: "475 N Beverly Dr", + to_zip: "90210", + transaction_date: "2018-03-06T12:10:33Z", + transaction_id: "R111222333", + }) + end + end end diff --git a/spec/super_good/solidus_taxjar/api_spec.rb b/spec/super_good/solidus_taxjar/api_spec.rb index 1b6defd..0bfb67a 100644 --- a/spec/super_good/solidus_taxjar/api_spec.rb +++ b/spec/super_good/solidus_taxjar/api_spec.rb @@ -44,4 +44,26 @@ RSpec.describe SuperGood::SolidusTaxJar::API do it { is_expected.to eq({ some_kind_of: "response" }) } end + + describe "create_transaction_for" do + subject { api.create_transaction_for order } + + let(:api) { described_class.new(taxjar_client: dummy_client) } + let(:dummy_client) { instance_double ::Taxjar::Client } + let(:order) { Spree::Order.new } + + before do + allow(SuperGood::SolidusTaxJar::APIParams) + .to receive(:transaction_params) + .with(order) + .and_return({ transaction: "params" }) + + allow(dummy_client) + .to receive(:create_order) + .with({ transaction: "params" }) + .and_return({ some_kind_of: "response" }) + end + + it { is_expected.to eq({ some_kind_of: "response" }) } + end end |