super_good-solidus_taxjar 0.17.1 → 0.18.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +19 -13
- data/.travis.yml +11 -5
- data/CHANGELOG.md +30 -0
- data/Gemfile +21 -5
- data/LICENSE +26 -0
- data/PULL_REQUEST_TEMPLATE.md +19 -0
- data/README.md +20 -11
- data/Rakefile +4 -17
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +84 -0
- data/lib/super_good-solidus_taxjar.rb +4 -0
- data/lib/super_good/engine.rb +8 -0
- data/lib/super_good/solidus_taxjar.rb +11 -6
- data/lib/super_good/solidus_taxjar/addresses.rb +63 -0
- data/lib/super_good/solidus_taxjar/api.rb +20 -11
- data/lib/super_good/solidus_taxjar/api_params.rb +19 -9
- data/lib/super_good/solidus_taxjar/calculator_helper.rb +4 -10
- data/lib/super_good/solidus_taxjar/discount_calculator.rb +1 -1
- data/lib/super_good/solidus_taxjar/tax_calculator.rb +12 -12
- data/lib/super_good/solidus_taxjar/tax_rate_calculator.rb +6 -7
- data/lib/super_good/solidus_taxjar/version.rb +2 -2
- data/spec/spec_helper.rb +20 -0
- data/spec/super_good/solidus_taxjar/addresses_spec.rb +288 -0
- data/spec/super_good/solidus_taxjar/api_params_spec.rb +402 -0
- data/spec/super_good/solidus_taxjar/api_spec.rb +205 -0
- data/spec/super_good/solidus_taxjar/discount_calculator_spec.rb +13 -0
- data/spec/super_good/solidus_taxjar/tax_calculator_spec.rb +332 -0
- data/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb +116 -0
- data/spec/super_good/solidus_taxjar_spec.rb +77 -0
- data/super_good-solidus_taxjar.gemspec +17 -14
- metadata +35 -10
- data/LICENSE.txt +0 -21
@@ -0,0 +1,116 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ::SuperGood::SolidusTaxjar::TaxRateCalculator do
|
4
|
+
describe "#calculate" do
|
5
|
+
subject { calculator.calculate }
|
6
|
+
|
7
|
+
let(:calculator) { described_class.new(address, api: dummy_api) }
|
8
|
+
|
9
|
+
let(:dummy_api) do
|
10
|
+
instance_double ::SuperGood::SolidusTaxjar::Api
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:dummy_tax_rate) { BigDecimal(0) }
|
14
|
+
|
15
|
+
let(:empty_address) do
|
16
|
+
::Spree::Address.new
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:incomplete_address) do
|
20
|
+
::Spree::Address.new(
|
21
|
+
first_name: "Ronnie James",
|
22
|
+
zipcode: nil,
|
23
|
+
address1: nil,
|
24
|
+
city: "Beverly Hills",
|
25
|
+
state_name: "California",
|
26
|
+
country: ::Spree::Country.new(iso: "US")
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:complete_address) do
|
31
|
+
incomplete_address.tap do |address|
|
32
|
+
address.zipcode = "90210"
|
33
|
+
address.address1 = "9900 Wilshire Blvd"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
shared_examples "returns the dummy tax rate" do
|
38
|
+
it { expect(subject).to eq dummy_tax_rate }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the address is an empty address" do
|
42
|
+
let(:address) { empty_address }
|
43
|
+
|
44
|
+
context "when we're not rescuing from errors" do
|
45
|
+
around do |example|
|
46
|
+
handler = SuperGood::SolidusTaxjar.exception_handler
|
47
|
+
SuperGood::SolidusTaxjar.exception_handler = ->(error) { raise error }
|
48
|
+
example.run
|
49
|
+
SuperGood::SolidusTaxjar.exception_handler = handler
|
50
|
+
end
|
51
|
+
|
52
|
+
it_behaves_like "returns the dummy tax rate"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when the address is not complete" do
|
57
|
+
let(:address) { incomplete_address }
|
58
|
+
|
59
|
+
it_behaves_like "returns the dummy tax rate"
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when the address is complete" do
|
63
|
+
let(:address) { complete_address }
|
64
|
+
|
65
|
+
context "when the address is not taxable" do
|
66
|
+
before do
|
67
|
+
allow(SuperGood::SolidusTaxjar.taxable_address_check)
|
68
|
+
.to receive(:call).with(address)
|
69
|
+
.and_return(false)
|
70
|
+
end
|
71
|
+
|
72
|
+
it_behaves_like "returns the dummy tax rate"
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when the address is taxable" do
|
76
|
+
let(:tax_rate) { 0.03 }
|
77
|
+
|
78
|
+
before do
|
79
|
+
allow(dummy_api).to receive(:tax_rate_for) { tax_rate }
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns the expected tax rate" do
|
83
|
+
expect(subject).to eq tax_rate
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when the API encounters an error" do
|
89
|
+
let(:address) { complete_address }
|
90
|
+
|
91
|
+
before do
|
92
|
+
allow(dummy_api).to receive(:tax_rate_for).and_raise("A bad thing happened.")
|
93
|
+
end
|
94
|
+
|
95
|
+
it "calls the configured error handler" do
|
96
|
+
expect(SuperGood::SolidusTaxjar.exception_handler).to receive(:call) do |e|
|
97
|
+
expect(e).to be_a StandardError
|
98
|
+
expect(e.message).to eq "A bad thing happened."
|
99
|
+
end
|
100
|
+
|
101
|
+
subject
|
102
|
+
end
|
103
|
+
|
104
|
+
it_behaves_like "returns the dummy tax rate"
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when test_mode is set" do
|
108
|
+
let(:address) { complete_address }
|
109
|
+
|
110
|
+
before { SuperGood::SolidusTaxjar.test_mode = true }
|
111
|
+
after { SuperGood::SolidusTaxjar.test_mode = false }
|
112
|
+
|
113
|
+
it_behaves_like "returns the dummy tax rate"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe SuperGood::SolidusTaxjar do
|
4
|
+
it "has a version number" do
|
5
|
+
expect(SuperGood::SolidusTaxjar::VERSION).not_to be nil
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "configuration" do
|
9
|
+
describe ".cache_key" do
|
10
|
+
subject { described_class.cache_key.call(order) }
|
11
|
+
|
12
|
+
let(:order) { Spree::Order.new }
|
13
|
+
|
14
|
+
it "returns the API params converted to JSON" do
|
15
|
+
allow(SuperGood::SolidusTaxjar::ApiParams)
|
16
|
+
.to receive(:order_params)
|
17
|
+
.with(order)
|
18
|
+
.and_return({some: "hash", with: "stuff", in: "it"})
|
19
|
+
|
20
|
+
expect(subject).to eq '{"some":"hash","with":"stuff","in":"it"}'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".discount_calculator" do
|
25
|
+
subject { described_class.discount_calculator }
|
26
|
+
it { is_expected.to eq SuperGood::SolidusTaxjar::DiscountCalculator }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe ".test_mode" do
|
30
|
+
subject { described_class.test_mode }
|
31
|
+
it { is_expected.to eq false }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".exception_handler" do
|
35
|
+
subject { described_class.exception_handler.call(exception) }
|
36
|
+
|
37
|
+
let(:exception) { StandardError.new("Something happened") }
|
38
|
+
|
39
|
+
it "reports the exception using the Rails logger" do
|
40
|
+
expect(Rails.logger).to receive(:error).with(
|
41
|
+
"An error occurred while fetching TaxJar tax rates - Something happened: Something happened"
|
42
|
+
)
|
43
|
+
subject
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe ".taxable_address_check" do
|
48
|
+
subject { described_class.taxable_address_check.call(address) }
|
49
|
+
|
50
|
+
let(:address) { Spree::Address.new }
|
51
|
+
|
52
|
+
it { is_expected.to eq true }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe ".taxable_order_check" do
|
56
|
+
subject { described_class.taxable_order_check.call(order) }
|
57
|
+
|
58
|
+
let(:order) { Spree::Order.new }
|
59
|
+
|
60
|
+
it { is_expected.to eq true }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".shipping_tax_label_maker" do
|
64
|
+
subject { described_class.shipping_tax_label_maker.call(shipment, shipping_tax) }
|
65
|
+
let(:shipment) { Spree::Shipment.new }
|
66
|
+
let(:shipping_tax) { BigDecimal("3.25") }
|
67
|
+
it { is_expected.to eq "Sales Tax" }
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ".line_item_tax_label_maker" do
|
71
|
+
subject { described_class.line_item_tax_label_maker.call(taxjar_line_item, spree_line_item) }
|
72
|
+
let(:taxjar_line_item) { instance_double Taxjar::BreakdownLineItem }
|
73
|
+
let(:spree_line_item) { Spree::LineItem.new }
|
74
|
+
it { is_expected.to eq "Sales Tax" }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -3,31 +3,34 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
require "super_good/solidus_taxjar/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "super_good-solidus_taxjar"
|
7
|
+
spec.version = SuperGood::SolidusTaxjar::VERSION
|
8
|
+
spec.authors = ["Jared Norman"]
|
9
|
+
spec.email = ["jared@super.gd"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
11
|
+
spec.summary = "Support for using TaxJar to handle tax calculations in Solidus"
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/SuperGoodSoft/solidus_taxjar"
|
14
|
+
spec.license = 'BSD-3-Clause'
|
15
|
+
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
|
15
17
|
|
16
18
|
# Specify which files should be added to the gem when it is released.
|
17
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
spec.
|
22
|
-
spec.
|
20
|
+
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
|
21
|
+
|
22
|
+
spec.files = files.grep_v(%r{^(test|spec|features)/})
|
23
|
+
spec.test_files = files.grep(%r{^(test|spec|features)/})
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
26
|
spec.require_paths = ["lib"]
|
24
27
|
|
25
28
|
spec.add_dependency "solidus_core", ">= 2.4.0"
|
26
29
|
spec.add_dependency "solidus_support"
|
27
30
|
spec.add_dependency "taxjar-ruby"
|
28
31
|
|
32
|
+
spec.add_development_dependency "solidus_dev_support"
|
29
33
|
spec.add_development_dependency "bundler"
|
30
|
-
spec.add_development_dependency "database_cleaner"
|
31
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
36
|
spec.add_development_dependency "rspec-rails"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_good-solidus_taxjar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Norman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: solidus_dev_support
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -163,12 +163,21 @@ files:
|
|
163
163
|
- CHANGELOG.md
|
164
164
|
- CODE_OF_CONDUCT.md
|
165
165
|
- Gemfile
|
166
|
-
- LICENSE
|
166
|
+
- LICENSE
|
167
|
+
- PULL_REQUEST_TEMPLATE.md
|
167
168
|
- README.md
|
168
169
|
- Rakefile
|
169
170
|
- bin/console
|
171
|
+
- bin/rails
|
172
|
+
- bin/rails-engine
|
173
|
+
- bin/rails-sandbox
|
174
|
+
- bin/rake
|
175
|
+
- bin/sandbox
|
170
176
|
- bin/setup
|
177
|
+
- lib/super_good-solidus_taxjar.rb
|
178
|
+
- lib/super_good/engine.rb
|
171
179
|
- lib/super_good/solidus_taxjar.rb
|
180
|
+
- lib/super_good/solidus_taxjar/addresses.rb
|
172
181
|
- lib/super_good/solidus_taxjar/api.rb
|
173
182
|
- lib/super_good/solidus_taxjar/api_params.rb
|
174
183
|
- lib/super_good/solidus_taxjar/calculator_helper.rb
|
@@ -176,10 +185,18 @@ files:
|
|
176
185
|
- lib/super_good/solidus_taxjar/tax_calculator.rb
|
177
186
|
- lib/super_good/solidus_taxjar/tax_rate_calculator.rb
|
178
187
|
- lib/super_good/solidus_taxjar/version.rb
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
- spec/super_good/solidus_taxjar/addresses_spec.rb
|
190
|
+
- spec/super_good/solidus_taxjar/api_params_spec.rb
|
191
|
+
- spec/super_good/solidus_taxjar/api_spec.rb
|
192
|
+
- spec/super_good/solidus_taxjar/discount_calculator_spec.rb
|
193
|
+
- spec/super_good/solidus_taxjar/tax_calculator_spec.rb
|
194
|
+
- spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb
|
195
|
+
- spec/super_good/solidus_taxjar_spec.rb
|
179
196
|
- super_good-solidus_taxjar.gemspec
|
180
197
|
homepage: https://github.com/SuperGoodSoft/solidus_taxjar
|
181
198
|
licenses:
|
182
|
-
-
|
199
|
+
- BSD-3-Clause
|
183
200
|
metadata: {}
|
184
201
|
post_install_message:
|
185
202
|
rdoc_options: []
|
@@ -187,17 +204,25 @@ require_paths:
|
|
187
204
|
- lib
|
188
205
|
required_ruby_version: !ruby/object:Gem::Requirement
|
189
206
|
requirements:
|
190
|
-
- - "
|
207
|
+
- - "~>"
|
191
208
|
- !ruby/object:Gem::Version
|
192
|
-
version: '
|
209
|
+
version: '2.5'
|
193
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
211
|
requirements:
|
195
212
|
- - ">="
|
196
213
|
- !ruby/object:Gem::Version
|
197
214
|
version: '0'
|
198
215
|
requirements: []
|
199
|
-
rubygems_version: 3.
|
216
|
+
rubygems_version: 3.1.4
|
200
217
|
signing_key:
|
201
218
|
specification_version: 4
|
202
219
|
summary: Support for using TaxJar to handle tax calculations in Solidus
|
203
|
-
test_files:
|
220
|
+
test_files:
|
221
|
+
- spec/spec_helper.rb
|
222
|
+
- spec/super_good/solidus_taxjar/addresses_spec.rb
|
223
|
+
- spec/super_good/solidus_taxjar/api_params_spec.rb
|
224
|
+
- spec/super_good/solidus_taxjar/api_spec.rb
|
225
|
+
- spec/super_good/solidus_taxjar/discount_calculator_spec.rb
|
226
|
+
- spec/super_good/solidus_taxjar/tax_calculator_spec.rb
|
227
|
+
- spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb
|
228
|
+
- spec/super_good/solidus_taxjar_spec.rb
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2018 Jared Norman
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|