Skip to content

Commit

Permalink
Fix .default_taxjar_client
Browse files Browse the repository at this point in the history
In #34, we modified `.default_taxjar_client` to include the API version,
and then the name of the plugin, but we also introduced a critical bug.
`Taxjar::Client#set_api_config` returns a hash and not the TaxJar
client, so it is not safe to chain the method call. As such, we add a
spec to cover this case and patch the class method.

Co-authored-by: Noah Silvera <[email protected]>
  • Loading branch information
nvandoorn and Noah-Silvera committed Mar 24, 2021
1 parent b8dac47 commit 84db881
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/super_good/solidus_taxjar/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ module SuperGood
module SolidusTaxjar
class Api
def self.default_taxjar_client
::Taxjar::Client.new(
client = ::Taxjar::Client.new(
api_key: ENV.fetch("TAXJAR_API_KEY"),
api_url: ENV.fetch("TAXJAR_API_URL") { "https://api.taxjar.com" } # Sandbox URL: https://api.sandbox.taxjar.com
).set_api_config('headers', {
)
client.set_api_config('headers', {
'x-api-version' => '2020-08-07',
'plugin' => 'supergoodsolidustaxjar'
})
client
end

def initialize(taxjar_client: self.class.default_taxjar_client)
Expand Down
13 changes: 13 additions & 0 deletions spec/super_good/solidus_taxjar/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
end
end

describe ".default_taxjar_client" do
subject { described_class.default_taxjar_client }

before do
ENV["TAXJAR_API_KEY"] = 'taxjar_api_token'
end

it "returns an instance of the TaxJar client" do
expect(subject).to be_an_instance_of(::Taxjar::Client)
end
end


describe "#tax_for" do
subject { api.tax_for order }

Expand Down

0 comments on commit 84db881

Please sign in to comment.