super_good-solidus_taxjar 0.15.2 → 0.18.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +16 -0
  3. data/.gitignore +19 -13
  4. data/.travis.yml +12 -5
  5. data/CHANGELOG.md +71 -0
  6. data/Gemfile +23 -5
  7. data/LICENSE +26 -0
  8. data/PULL_REQUEST_TEMPLATE.md +20 -0
  9. data/README.md +34 -9
  10. data/Rakefile +4 -17
  11. data/app/controllers/spree/admin/taxjar_settings_controller.rb +8 -0
  12. data/app/decorators/super_good/solidus_taxjar/spree/order_updater/fire_recalculated_event.rb +18 -0
  13. data/app/overrides/spree/admin/shared/_configuration_menu.rb +11 -0
  14. data/app/views/spree/admin/taxjar_settings/show.html.erb +13 -0
  15. data/bin/rails +7 -0
  16. data/bin/rails-engine +13 -0
  17. data/bin/rails-sandbox +16 -0
  18. data/bin/rake +7 -0
  19. data/bin/sandbox +84 -0
  20. data/config/routes.rb +7 -0
  21. data/lib/super_good-solidus_taxjar.rb +4 -0
  22. data/lib/super_good/engine.rb +10 -0
  23. data/lib/super_good/solidus_taxjar.rb +19 -7
  24. data/lib/super_good/solidus_taxjar/addresses.rb +63 -0
  25. data/lib/super_good/solidus_taxjar/api.rb +27 -10
  26. data/lib/super_good/solidus_taxjar/api_params.rb +26 -8
  27. data/lib/super_good/solidus_taxjar/calculator_helper.rb +38 -0
  28. data/lib/super_good/solidus_taxjar/discount_calculator.rb +1 -1
  29. data/lib/super_good/solidus_taxjar/tax_calculator.rb +17 -50
  30. data/lib/super_good/solidus_taxjar/tax_rate_calculator.rb +35 -0
  31. data/lib/super_good/solidus_taxjar/version.rb +2 -2
  32. data/spec/features/spree/admin/taxjar_settings_spec.rb +48 -0
  33. data/spec/models/spree/order_updater_spec.rb +12 -0
  34. data/spec/spec_helper.rb +20 -0
  35. data/spec/super_good/solidus_taxjar/addresses_spec.rb +288 -0
  36. data/spec/super_good/solidus_taxjar/api_params_spec.rb +434 -0
  37. data/spec/super_good/solidus_taxjar/api_spec.rb +222 -0
  38. data/spec/super_good/solidus_taxjar/discount_calculator_spec.rb +13 -0
  39. data/spec/super_good/solidus_taxjar/tax_calculator_spec.rb +332 -0
  40. data/spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb +116 -0
  41. data/spec/super_good/solidus_taxjar_spec.rb +92 -0
  42. data/super_good-solidus_taxjar.gemspec +17 -14
  43. metadata +46 -9
  44. 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,92 @@
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
+
77
+ describe ".shipping_calculator" do
78
+ subject { described_class.shipping_calculator.call(order) }
79
+
80
+ let(:order) { create :order }
81
+ let(:shipment) { create :shipment, order: order, cost: 20 }
82
+
83
+ before do
84
+ create :adjustment, order: order, adjustable: shipment, amount: -10, eligible: true, source: create(:shipping_rate, shipment: shipment)
85
+ end
86
+
87
+ it "returns the shipment total including promotions" do
88
+ expect(subject).to eq(10)
89
+ end
90
+ end
91
+ end
92
+ 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 = "super_good-solidus_taxjar"
7
- spec.version = SuperGood::SolidusTaxJar::VERSION
8
- spec.authors = ["Jared Norman"]
9
- spec.email = ["jared@super.gd"]
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 = "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 = "MIT"
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 = ">= 2.5.0"
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
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
- end
21
- spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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.15.2
4
+ version: 0.18.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Norman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-26 00:00:00.000000000 Z
11
+ date: 2021-07-08 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: bundler
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: database_cleaner
70
+ name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -157,27 +157,54 @@ executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
+ - ".circleci/config.yml"
160
161
  - ".gitignore"
161
162
  - ".rspec"
162
163
  - ".travis.yml"
163
164
  - CHANGELOG.md
164
165
  - CODE_OF_CONDUCT.md
165
166
  - Gemfile
166
- - LICENSE.txt
167
+ - LICENSE
168
+ - PULL_REQUEST_TEMPLATE.md
167
169
  - README.md
168
170
  - Rakefile
171
+ - app/controllers/spree/admin/taxjar_settings_controller.rb
172
+ - app/decorators/super_good/solidus_taxjar/spree/order_updater/fire_recalculated_event.rb
173
+ - app/overrides/spree/admin/shared/_configuration_menu.rb
174
+ - app/views/spree/admin/taxjar_settings/show.html.erb
169
175
  - bin/console
176
+ - bin/rails
177
+ - bin/rails-engine
178
+ - bin/rails-sandbox
179
+ - bin/rake
180
+ - bin/sandbox
170
181
  - bin/setup
182
+ - config/routes.rb
183
+ - lib/super_good-solidus_taxjar.rb
184
+ - lib/super_good/engine.rb
171
185
  - lib/super_good/solidus_taxjar.rb
186
+ - lib/super_good/solidus_taxjar/addresses.rb
172
187
  - lib/super_good/solidus_taxjar/api.rb
173
188
  - lib/super_good/solidus_taxjar/api_params.rb
189
+ - lib/super_good/solidus_taxjar/calculator_helper.rb
174
190
  - lib/super_good/solidus_taxjar/discount_calculator.rb
175
191
  - lib/super_good/solidus_taxjar/tax_calculator.rb
192
+ - lib/super_good/solidus_taxjar/tax_rate_calculator.rb
176
193
  - lib/super_good/solidus_taxjar/version.rb
194
+ - spec/features/spree/admin/taxjar_settings_spec.rb
195
+ - spec/models/spree/order_updater_spec.rb
196
+ - spec/spec_helper.rb
197
+ - spec/super_good/solidus_taxjar/addresses_spec.rb
198
+ - spec/super_good/solidus_taxjar/api_params_spec.rb
199
+ - spec/super_good/solidus_taxjar/api_spec.rb
200
+ - spec/super_good/solidus_taxjar/discount_calculator_spec.rb
201
+ - spec/super_good/solidus_taxjar/tax_calculator_spec.rb
202
+ - spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb
203
+ - spec/super_good/solidus_taxjar_spec.rb
177
204
  - super_good-solidus_taxjar.gemspec
178
205
  homepage: https://github.com/SuperGoodSoft/solidus_taxjar
179
206
  licenses:
180
- - MIT
207
+ - BSD-3-Clause
181
208
  metadata: {}
182
209
  post_install_message:
183
210
  rdoc_options: []
@@ -187,15 +214,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
214
  requirements:
188
215
  - - ">="
189
216
  - !ruby/object:Gem::Version
190
- version: '0'
217
+ version: 2.5.0
191
218
  required_rubygems_version: !ruby/object:Gem::Requirement
192
219
  requirements:
193
220
  - - ">="
194
221
  - !ruby/object:Gem::Version
195
222
  version: '0'
196
223
  requirements: []
197
- rubygems_version: 3.0.3
224
+ rubygems_version: 3.1.6
198
225
  signing_key:
199
226
  specification_version: 4
200
227
  summary: Support for using TaxJar to handle tax calculations in Solidus
201
- test_files: []
228
+ test_files:
229
+ - spec/features/spree/admin/taxjar_settings_spec.rb
230
+ - spec/models/spree/order_updater_spec.rb
231
+ - spec/spec_helper.rb
232
+ - spec/super_good/solidus_taxjar/addresses_spec.rb
233
+ - spec/super_good/solidus_taxjar/api_params_spec.rb
234
+ - spec/super_good/solidus_taxjar/api_spec.rb
235
+ - spec/super_good/solidus_taxjar/discount_calculator_spec.rb
236
+ - spec/super_good/solidus_taxjar/tax_calculator_spec.rb
237
+ - spec/super_good/solidus_taxjar/tax_rate_calculator_spec.rb
238
+ - 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.