spree_avatax_official 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env-sample +4 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/.rubocop.yml +77 -0
- data/.travis.yml +78 -0
- data/Appraisals +49 -0
- data/Gemfile +16 -0
- data/LICENSE +26 -0
- data/README.md +173 -0
- data/Rakefile +21 -0
- data/app/controllers/spree/admin/avalara_entity_use_codes_controller.rb +61 -0
- data/app/controllers/spree/admin/avatax_pings_controller.rb +19 -0
- data/app/controllers/spree/admin/avatax_settings_controller.rb +26 -0
- data/app/controllers/spree/admin/users_controller_decorator.rb +27 -0
- data/app/helpers/spree_avatax_official/http_helper.rb +17 -0
- data/app/helpers/spree_avatax_official/tax_adjustment_label_helper.rb +30 -0
- data/app/models/avatax/request_decorator.rb +34 -0
- data/app/models/spree_avatax_official/avatax_log.rb +57 -0
- data/app/models/spree_avatax_official/calculator/avatax_transaction_calculator.rb +28 -0
- data/app/models/spree_avatax_official/configuration.rb +20 -0
- data/app/models/spree_avatax_official/entity_use_code.rb +7 -0
- data/app/models/spree_avatax_official/has_uuid.rb +22 -0
- data/app/models/spree_avatax_official/spree/address_decorator.rb +31 -0
- data/app/models/spree_avatax_official/spree/inventory_unit_decorator.rb +11 -0
- data/app/models/spree_avatax_official/spree/line_item_decorator.rb +27 -0
- data/app/models/spree_avatax_official/spree/order_decorator.rb +91 -0
- data/app/models/spree_avatax_official/spree/refund_decorator.rb +22 -0
- data/app/models/spree_avatax_official/spree/shipment_decorator.rb +25 -0
- data/app/models/spree_avatax_official/spree/tax_category_decorator.rb +14 -0
- data/app/models/spree_avatax_official/spree/user_decorator.rb +11 -0
- data/app/models/spree_avatax_official/transaction.rb +27 -0
- data/app/overrides/spree/admin/shared/sub_menu/_configuration.rb +10 -0
- data/app/overrides/spree/admin/sidebar.rb +14 -0
- data/app/presenters/spree_avatax_official/address_presenter.rb +40 -0
- data/app/presenters/spree_avatax_official/item_presenter.rb +92 -0
- data/app/presenters/spree_avatax_official/ship_to_address_presenter.rb +22 -0
- data/app/presenters/spree_avatax_official/transactions/adjust_presenter.rb +31 -0
- data/app/presenters/spree_avatax_official/transactions/create_presenter.rb +80 -0
- data/app/presenters/spree_avatax_official/transactions/full_refund_presenter.rb +32 -0
- data/app/presenters/spree_avatax_official/transactions/partial_refund_presenter.rb +46 -0
- data/app/services/spree_avatax_official/address/validate.rb +27 -0
- data/app/services/spree_avatax_official/base.rb +71 -0
- data/app/services/spree_avatax_official/create_tax_adjustments_service.rb +133 -0
- data/app/services/spree_avatax_official/generate_transaction_cache_key_service.rb +94 -0
- data/app/services/spree_avatax_official/get_tax_service.rb +20 -0
- data/app/services/spree_avatax_official/settings/update_service.rb +36 -0
- data/app/services/spree_avatax_official/transactions/adjust_service.rb +36 -0
- data/app/services/spree_avatax_official/transactions/create_service.rb +47 -0
- data/app/services/spree_avatax_official/transactions/find_order_transaction_service.rb +23 -0
- data/app/services/spree_avatax_official/transactions/full_refund_service.rb +36 -0
- data/app/services/spree_avatax_official/transactions/get_by_code_service.rb +32 -0
- data/app/services/spree_avatax_official/transactions/partial_refund_service.rb +33 -0
- data/app/services/spree_avatax_official/transactions/refund_service.rb +87 -0
- data/app/services/spree_avatax_official/transactions/void_service.rb +28 -0
- data/app/services/spree_avatax_official/utilities/ping_service.rb +9 -0
- data/app/views/spree/admin/avalara_entity_use_codes/_form.html.erb +20 -0
- data/app/views/spree/admin/avalara_entity_use_codes/edit.html.erb +12 -0
- data/app/views/spree/admin/avalara_entity_use_codes/index.html.erb +35 -0
- data/app/views/spree/admin/avalara_entity_use_codes/new.html.erb +12 -0
- data/app/views/spree/admin/avatax_settings/edit.html.erb +99 -0
- data/app/views/spree/admin/users/avalara_information.html.erb +39 -0
- data/app/views/spree/admin/zones/_form.html.erb +58 -0
- data/bin/rails +8 -0
- data/config/initializers/spree_permitted_attributes.rb +5 -0
- data/config/locales/en.yml +40 -0
- data/config/routes.rb +15 -0
- data/db/migrate/20190118155953_add_exemption_number_to_spree_users.rb +7 -0
- data/db/migrate/20190118160653_create_spree_avalara_entity_use_codes.rb +11 -0
- data/db/migrate/20190118161318_add_avalara_entity_use_code_reference_to_users.rb +7 -0
- data/db/migrate/20190118162345_add_vat_id_to_spree_users.rb +7 -0
- data/db/migrate/20190122154119_create_spree_avatax_official_transactions.rb +10 -0
- data/db/migrate/20190201123706_add_tax_code_to_spree_tax_categories.rb +7 -0
- data/db/migrate/20190208130136_add_avatax_company_code_to_spree_stores.rb +8 -0
- data/db/migrate/20190225145808_add_uuid_to_spree_line_items_and_spree_shipments.rb +13 -0
- data/db/migrate/20190329071439_add_included_in_price_to_spree_zones.rb +5 -0
- data/db/migrate/20191001085458_remove_spree_avalara_entity_use_codes_table.rb +12 -0
- data/db/migrate/20191001092353_create_spree_avatax_official_entity_use_codes_table.rb +18 -0
- data/db/seeds.rb +1 -0
- data/gemfiles/spree_3_1.gemfile +16 -0
- data/gemfiles/spree_3_7.gemfile +13 -0
- data/gemfiles/spree_4_0.gemfile +14 -0
- data/gemfiles/spree_4_1.gemfile +14 -0
- data/gemfiles/spree_4_2.gemfile +14 -0
- data/gemfiles/spree_master.gemfile +14 -0
- data/lib/generators/spree_avatax_official/install/install_generator.rb +38 -0
- data/lib/generators/spree_avatax_official/install/templates/config/initializers/spree_avatax_official.rb +9 -0
- data/lib/spree_avatax_official.rb +5 -0
- data/lib/spree_avatax_official/engine.rb +32 -0
- data/lib/spree_avatax_official/factories.rb +9 -0
- data/lib/spree_avatax_official/seeder.rb +51 -0
- data/lib/spree_avatax_official/version.rb +11 -0
- data/lib/tasks/load_seeds.rake +6 -0
- data/spec/.rubocop.yml +36 -0
- data/spec/factories/canada_address_factory.rb +23 -0
- data/spec/factories/europe_address_factory.rb +22 -0
- data/spec/factories/spree/avatax_global_zone_factory.rb +16 -0
- data/spec/factories/spree/avatax_order_factory.rb +69 -0
- data/spec/factories/spree/avatax_shipment_factory.rb +31 -0
- data/spec/factories/spree/avatax_shipping_method_factory.rb +35 -0
- data/spec/factories/spree/avatax_tax_category_factory.rb +17 -0
- data/spec/factories/spree/avatax_tax_rate_factory.rb +23 -0
- data/spec/factories/spree/line_item_factory.rb +13 -0
- data/spec/factories/spree/promotion_factory.rb +35 -0
- data/spec/factories/spree/shipping_calculator_factory.rb +10 -0
- data/spec/factories/spree_avatax_official/avalara_entity_use_code_factory.rb +7 -0
- data/spec/factories/spree_avatax_official/calculator/avatax_transaction_calculator_factory.rb +3 -0
- data/spec/factories/spree_avatax_official/transaction_factory.rb +12 -0
- data/spec/factories/usa_address_factory.rb +34 -0
- data/spec/features/admin/edit_avatax_settings_spec.rb +11 -0
- data/spec/features/admin/update_avatax_settings_spec.rb +200 -0
- data/spec/features/spree/admin/avalara_entity_use_codes_controller_spec.rb +71 -0
- data/spec/features/spree/admin/users_controller_spec.rb +34 -0
- data/spec/helpers/spree_avatax_official/tax_adjustment_label_helper_spec.rb +81 -0
- data/spec/lib/spree_avatax_official/seeder_spec.rb +23 -0
- data/spec/models/spree/line_item_spec.rb +76 -0
- data/spec/models/spree/order_spec.rb +210 -0
- data/spec/models/spree/shipment_spec.rb +11 -0
- data/spec/models/spree_avatax_official/avatax_log_spec.rb +87 -0
- data/spec/models/spree_avatax_official/entity_use_code_spec.rb +9 -0
- data/spec/models/spree_avatax_official/has_uuid_spec.rb +21 -0
- data/spec/models/spree_avatax_official/spree/refund_decorator_spec.rb +31 -0
- data/spec/models/spree_avatax_official/transaction_spec.rb +9 -0
- data/spec/presenters/spree_avatax_official/address_presenter_spec.rb +53 -0
- data/spec/presenters/spree_avatax_official/item_presenter_spec.rb +159 -0
- data/spec/presenters/spree_avatax_official/ship_to_address_presenter_spec.rb +34 -0
- data/spec/presenters/spree_avatax_official/transactions/adjust_presenter_spec.rb +39 -0
- data/spec/presenters/spree_avatax_official/transactions/create_presenter_spec.rb +110 -0
- data/spec/presenters/spree_avatax_official/transactions/full_refund_presenter_spec.rb +30 -0
- data/spec/presenters/spree_avatax_official/transactions/partial_refund_presenter_spec.rb +48 -0
- data/spec/services/spree_avatax_official/address/validate_spec.rb +47 -0
- data/spec/services/spree_avatax_official/create_tax_adjustments_service_spec.rb +444 -0
- data/spec/services/spree_avatax_official/generate_transaction_cache_key_service_spec.rb +29 -0
- data/spec/services/spree_avatax_official/get_tax_service_spec.rb +33 -0
- data/spec/services/spree_avatax_official/settings/update_service_spec.rb +131 -0
- data/spec/services/spree_avatax_official/transactions/adjust_service_spec.rb +55 -0
- data/spec/services/spree_avatax_official/transactions/create_service_spec.rb +262 -0
- data/spec/services/spree_avatax_official/transactions/find_order_transaction_service_spec.rb +38 -0
- data/spec/services/spree_avatax_official/transactions/full_refund_service_spec.rb +24 -0
- data/spec/services/spree_avatax_official/transactions/get_by_code_service_spec.rb +74 -0
- data/spec/services/spree_avatax_official/transactions/partial_refund_service_spec.rb +33 -0
- data/spec/services/spree_avatax_official/transactions/refund_service_spec.rb +65 -0
- data/spec/services/spree_avatax_official/transactions/void_service_spec.rb +33 -0
- data/spec/services/spree_avatax_official/utilities/ping_service_spec.rb +35 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/support/avatax.rb +15 -0
- data/spec/support/capybara.rb +21 -0
- data/spec/support/database_cleaner.rb +25 -0
- data/spec/support/factory_bot.rb +9 -0
- data/spec/support/vcr.rb +17 -0
- data/spec/vcr/SpreeAvataxOfficial_Transactions_FindOrderTransactionService/_call/with_Spree_Order/when_order_does_NOT_have_a_SalesInvoice_transaction/when_transaction_does_NOT_exist_in_avatax/returns_failure.yml +44 -0
- data/spec/vcr/SpreeAvataxOfficial_Transactions_FindOrderTransactionService/_call/with_Spree_Order/when_order_does_NOT_have_a_SalesInvoice_transaction/when_transaction_exists_in_avatax/returns_success_and_creates_a_new_SalesInvoice_transaction.yml +48 -0
- data/spec/vcr/spree_avatax_official/address/validate_failure.yml +46 -0
- data/spec/vcr/spree_avatax_official/address/validate_success.yml +43 -0
- data/spec/vcr/spree_avatax_official/address/zipcode_failure.yml +45 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/californian_stock_location.yml +60 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/completed_order_line_item_update.yml +62 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/order_adjustment_promotion.yml +61 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/shipment_adjustment_promotion.yml +60 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/simple_completed_order.yml +60 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_excluded/line_item_adjustment_promotion.yml +59 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_excluded/line_item_and_shipment.yml +60 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_excluded/multiple_line_items_multiple_quantity.yml +59 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_excluded/single_line_item.yml +55 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_included/line_item_adjustment_promotion.yml +59 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_included/line_item_and_shipment.yml +60 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_included/multiple_line_items_multiple_quantity.yml +59 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/tax_included/single_line_item.yml +55 -0
- data/spec/vcr/spree_avatax_official/create_tax_adjustments/with_incorrect_address.yml +97 -0
- data/spec/vcr/spree_avatax_official/get_tax/error.yml +49 -0
- data/spec/vcr/spree_avatax_official/get_tax/sucsess.yml +55 -0
- data/spec/vcr/spree_avatax_official/transactions/adjust/failure.yml +101 -0
- data/spec/vcr/spree_avatax_official/transactions/adjust/invoice_order_success.yml +117 -0
- data/spec/vcr/spree_avatax_official/transactions/create/complete_order_success.yml +60 -0
- data/spec/vcr/spree_avatax_official/transactions/create/gst/canada_to_canada.yml +55 -0
- data/spec/vcr/spree_avatax_official/transactions/create/gst/canada_to_us.yml +57 -0
- data/spec/vcr/spree_avatax_official/transactions/create/gst/us_to_canada.yml +56 -0
- data/spec/vcr/spree_avatax_official/transactions/create/invoice_order_success.yml +60 -0
- data/spec/vcr/spree_avatax_official/transactions/create/sales_order_success.yml +60 -0
- data/spec/vcr/spree_avatax_official/transactions/create/timeout.yml +54 -0
- data/spec/vcr/spree_avatax_official/transactions/create/vat/europe_to_europe.yml +57 -0
- data/spec/vcr/spree_avatax_official/transactions/create/vat/europe_to_us.yml +57 -0
- data/spec/vcr/spree_avatax_official/transactions/create/vat/us_to_europe.yml +58 -0
- data/spec/vcr/spree_avatax_official/transactions/get_by_code/error.yml +44 -0
- data/spec/vcr/spree_avatax_official/transactions/get_by_code/order_with_custom_code_success.yml +49 -0
- data/spec/vcr/spree_avatax_official/transactions/get_by_code/order_with_number_success.yml +49 -0
- data/spec/vcr/spree_avatax_official/transactions/get_by_code/order_with_type_success.yml +48 -0
- data/spec/vcr/spree_avatax_official/transactions/get_by_code/order_without_type_success.yml +48 -0
- data/spec/vcr/spree_avatax_official/transactions/refund/full_refund_success.yml +114 -0
- data/spec/vcr/spree_avatax_official/transactions/refund/partial_refund_success.yml +58 -0
- data/spec/vcr/spree_avatax_official/transactions/refund/partial_refund_with_refund_success.yml +58 -0
- data/spec/vcr/spree_avatax_official/transactions/void/success.yml +112 -0
- data/spec/vcr/spree_avatax_official/utilities/ping.yml +41 -0
- data/spec/vcr/spree_avatax_official/utilities/ping_unauthorized.yml +42 -0
- data/spec/vcr/spree_line_item/update_tax_charge/decrease_quantity.yml +55 -0
- data/spec/vcr/spree_line_item/update_tax_charge/increase_quantity.yml +55 -0
- data/spec/vcr/spree_order/california_order.yml +67 -0
- data/spec/vcr/spree_order/complete_order.yml +60 -0
- data/spec/vcr/spree_order/order_transition_to_completed.yml +112 -0
- data/spec/vcr/spree_order/order_with_line_item_adjustment.yml +57 -0
- data/spec/vcr/spree_order/order_with_order_adjustment.yml +57 -0
- data/spec/vcr/spree_order/simple_order_with_single_line_item.yml +55 -0
- data/spec/vcr/spree_order/simple_order_with_single_line_item_and_shipment.yml +57 -0
- data/spec/vcr/spree_order/update_tax_charge/create_line_item.yml +55 -0
- data/spree_avatax_official.gemspec +43 -0
- metadata +486 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SpreeAvataxOfficial::Seeder do
|
4
|
+
describe '#seed!' do
|
5
|
+
subject { described_class.new.seed! }
|
6
|
+
|
7
|
+
let!(:usa) { create(:country, name: 'United States', iso3: 'USA') }
|
8
|
+
let!(:pennslyvania) { create(:state, name: 'Pennsylvania', abbr: 'PA') }
|
9
|
+
let!(:shipping_method) { create(:shipping_method, tax_category: nil) }
|
10
|
+
let(:clothing_tax_category) { Spree::TaxCategory.find_by(name: 'Clothing') }
|
11
|
+
let(:shipping_tax_category) { Spree::TaxCategory.find_by(name: 'Shipping') }
|
12
|
+
|
13
|
+
it 'creates Clothing and Shipping tax categories and assigns Shipping tax category' do
|
14
|
+
subject
|
15
|
+
|
16
|
+
expect(clothing_tax_category).to be_present
|
17
|
+
expect(clothing_tax_category.tax_code).to eq 'P0000000'
|
18
|
+
expect(shipping_tax_category).to be_present
|
19
|
+
expect(shipping_tax_category.tax_code).to eq 'FR'
|
20
|
+
expect(shipping_method.reload.tax_category).to eq shipping_tax_category
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::LineItem do
|
4
|
+
describe '#avatax_number' do
|
5
|
+
let(:line_item) { create(:line_item) }
|
6
|
+
|
7
|
+
it 'returns line item id with avatax code' do
|
8
|
+
expect(line_item.avatax_number).to eq "LI-#{line_item.avatax_uuid}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#update_tax_charge' do
|
13
|
+
context 'with AvaTax tax calculcation', :avatax_enabled do
|
14
|
+
let(:order) { create(:avatax_order, ship_address: create(:usa_address)) }
|
15
|
+
let(:line_item) { order.line_items.first }
|
16
|
+
|
17
|
+
before do
|
18
|
+
VCR.use_cassette('spree_order/update_tax_charge/create_line_item') do
|
19
|
+
create(:line_item, price: 10.0, quantity: 2, order: order)
|
20
|
+
|
21
|
+
order.reload
|
22
|
+
order.updater.update
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when line item is created' do
|
27
|
+
it 'updates line item and order tax' do
|
28
|
+
expect(order.total).to eq 21.6
|
29
|
+
expect(order.additional_tax_total).to eq 1.6
|
30
|
+
expect(line_item.reload.additional_tax_total).to eq 1.6
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when line item quantity is increased' do
|
35
|
+
it 'updates line item and order tax' do
|
36
|
+
VCR.use_cassette('spree_line_item/update_tax_charge/increase_quantity') do
|
37
|
+
line_item.update(quantity: 3)
|
38
|
+
|
39
|
+
order.reload
|
40
|
+
order.updater.update
|
41
|
+
end
|
42
|
+
|
43
|
+
expect(order.total).to eq 32.4
|
44
|
+
expect(order.additional_tax_total).to eq 2.4
|
45
|
+
expect(line_item.reload.additional_tax_total).to eq 2.4
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when line item quantity is decreased' do
|
50
|
+
it 'updates line item and order tax' do
|
51
|
+
VCR.use_cassette('spree_line_item/update_tax_charge/decrease_quantity') do
|
52
|
+
line_item.update(quantity: 1)
|
53
|
+
|
54
|
+
order.reload
|
55
|
+
order.updater.update
|
56
|
+
end
|
57
|
+
|
58
|
+
expect(order.total).to eq 10.8
|
59
|
+
expect(order.additional_tax_total).to eq 0.8
|
60
|
+
expect(line_item.reload.additional_tax_total).to eq 0.8
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when line item is destroyed' do
|
65
|
+
it 'updates line item and order tax' do
|
66
|
+
line_item.destroy
|
67
|
+
|
68
|
+
order.reload.updater.update
|
69
|
+
|
70
|
+
expect(order.total).to eq 0
|
71
|
+
expect(Spree::Adjustment.tax.count).to eq 0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Order do
|
4
|
+
describe 'associations' do
|
5
|
+
let(:order) { create(:order) }
|
6
|
+
|
7
|
+
describe 'avatax_sales_invoice_transaction' do
|
8
|
+
let!(:return_invoice_transaction) { create(:spree_avatax_official_transaction, :return_invoice, order: order) }
|
9
|
+
let!(:sales_invoice_transaction) { create(:spree_avatax_official_transaction, order: order) }
|
10
|
+
|
11
|
+
it 'returns SpreeAvataxOfficial::Transaction object with transaction_type: SalesInvoice' do
|
12
|
+
expect(order.avatax_sales_invoice_transaction).to eq sales_invoice_transaction
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#cancel', :avatax_enabled do
|
18
|
+
let!(:avatax_tax_rate) { create(:avatax_tax_rate) }
|
19
|
+
let(:order) { create(:order, ship_address: create(:usa_address)) }
|
20
|
+
|
21
|
+
before do
|
22
|
+
VCR.use_cassette('spree_order/simple_order_with_single_line_item') do
|
23
|
+
create(:line_item, price: 10.0, quantity: 1, order: order)
|
24
|
+
order.update(state: :complete, completed_at: Time.current)
|
25
|
+
end
|
26
|
+
|
27
|
+
allow(Spree::OrderMailer).to receive_message_chain(:cancel_email, :deliver_later)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'calls void service' do
|
31
|
+
expect(SpreeAvataxOfficial::Transactions::VoidService).to receive(:call)
|
32
|
+
|
33
|
+
order.cancel
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#taxable_items' do
|
38
|
+
let(:order) { create(:shipped_order, line_items_count: 2) }
|
39
|
+
|
40
|
+
it 'returns array of shipments and line items' do
|
41
|
+
expect(order.taxable_items).to eq [order.line_items.first, order.line_items.last, order.shipments.first]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#complete', :avatax_enabled do
|
46
|
+
let(:order) do
|
47
|
+
VCR.use_cassette('spree_order/order_transition_to_completed') do
|
48
|
+
create(:avatax_order, line_items_count: 1, ship_address: create(:usa_address)).tap do |order|
|
49
|
+
order.payments << create(:payment)
|
50
|
+
|
51
|
+
order.next!
|
52
|
+
# Unfortunetly state machine does not allow me to stub create_proposed_shipments method
|
53
|
+
# Stubbing results with `Wrong number of arguments. Expected 0, got 1.` without stacktrace
|
54
|
+
create(:avatax_shipment, order: order)
|
55
|
+
order.update(state: 'delivery')
|
56
|
+
order.reload
|
57
|
+
2.times { order.next! }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
before do
|
63
|
+
allow(Spree::OrderMailer).to receive_message_chain(:confirm_email, :deliver_later)
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'commit transaction enabled' do
|
67
|
+
before { SpreeAvataxOfficial::Config.commit_transaction_enabled = true }
|
68
|
+
|
69
|
+
it 'creates a commited SalesInvoice transaction' do
|
70
|
+
expect(order.state).to eq 'confirm'
|
71
|
+
|
72
|
+
VCR.use_cassette('spree_order/complete_order') do
|
73
|
+
expect { order.next! }.to change { order.avatax_transactions.count }.by(1)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'commit transaction disabled' do
|
79
|
+
around do |example|
|
80
|
+
SpreeAvataxOfficial::Config.commit_transaction_enabled = false
|
81
|
+
example.run
|
82
|
+
SpreeAvataxOfficial::Config.commit_transaction_enabled = true
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'doesnt create a commited SalesInvoice transaction' do
|
86
|
+
expect(order.state).to eq 'confirm'
|
87
|
+
|
88
|
+
VCR.use_cassette('spree_order/complete_order_no_transaction') do
|
89
|
+
expect { order.next! }.to_not change { order.avatax_transactions.count }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'tax estimation triggering', :avatax_enabled do
|
96
|
+
let(:order) { create(:avatax_order, with_shipment: true, ship_address: create(:usa_address)) }
|
97
|
+
let(:line_item) { order.line_items.first }
|
98
|
+
let(:shipment) { order.shipments.first }
|
99
|
+
let(:tax_adjustment) { line_item.adjustments.tax.first }
|
100
|
+
|
101
|
+
before do
|
102
|
+
VCR.use_cassette('spree_order/simple_order_with_single_line_item_and_shipment') do
|
103
|
+
create(:line_item, price: 10.0, quantity: 1, order: order)
|
104
|
+
|
105
|
+
order.reload
|
106
|
+
order.updater.update
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when line item discount promotion is applied' do
|
111
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: 5, code: 'promotion_code') }
|
112
|
+
|
113
|
+
it 'triggers tax estimation' do
|
114
|
+
expect(order.total).to eq 16.2
|
115
|
+
|
116
|
+
VCR.use_cassette('spree_order/order_with_line_item_adjustment') do
|
117
|
+
order.coupon_code = promotion.code
|
118
|
+
Spree::PromotionHandler::Coupon.new(order).apply
|
119
|
+
|
120
|
+
order.updater.update
|
121
|
+
end
|
122
|
+
|
123
|
+
expect(order.total).to eq 10.8
|
124
|
+
expect(line_item.reload.additional_tax_total).to eq 0.4
|
125
|
+
expect(shipment.reload.additional_tax_total).to eq 0.4
|
126
|
+
expect(tax_adjustment.amount).to eq 0.4
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when order discount promotion is applied' do
|
131
|
+
let(:promotion) { create(:promotion, :avatax_with_order_adjustment, weighted_order_adjustment_amount: 5.0, code: 'promotion_code') }
|
132
|
+
|
133
|
+
it 'triggers tax estimation' do
|
134
|
+
expect(order.total).to eq 16.2
|
135
|
+
|
136
|
+
VCR.use_cassette('spree_order/order_with_order_adjustment') do
|
137
|
+
order.coupon_code = promotion.code
|
138
|
+
Spree::PromotionHandler::Coupon.new(order).apply
|
139
|
+
|
140
|
+
order.updater.update
|
141
|
+
end
|
142
|
+
|
143
|
+
expect(order.total).to eq 10.8
|
144
|
+
expect(shipment.reload.additional_tax_total).to eq 0.4
|
145
|
+
expect(tax_adjustment.amount).to eq 0.4
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'when shipping address is changed', if: (::Gem::Version.new(::Spree.version) >= ::Gem::Version.new('3.0.0')) do
|
150
|
+
let(:california_address) { create(:usa_address, :from_california) }
|
151
|
+
|
152
|
+
it 'triggers tax estimation' do
|
153
|
+
expect(order.total).to eq 16.2
|
154
|
+
|
155
|
+
VCR.use_cassette('spree_order/california_order') do
|
156
|
+
order.tax_address.update(
|
157
|
+
address1: california_address.address1,
|
158
|
+
address2: california_address.address2,
|
159
|
+
city: california_address.city,
|
160
|
+
zipcode: california_address.zipcode,
|
161
|
+
state_id: california_address.state_id
|
162
|
+
)
|
163
|
+
california_address.run_callbacks(:save)
|
164
|
+
end
|
165
|
+
|
166
|
+
expect(order.reload.total).to eq 15.73
|
167
|
+
expect(line_item.reload.additional_tax_total).to eq 0.73
|
168
|
+
# California does not charge shipping tax
|
169
|
+
# https://www.avalara.com/us/en/blog/2016/01/do-i-charge-tax-on-shipping-costs-in-california.html
|
170
|
+
expect(shipment.reload.additional_tax_total).to eq 0
|
171
|
+
|
172
|
+
expect(tax_adjustment.amount).to eq 0.73
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '#validate_tax_address' do
|
178
|
+
let(:order) { create(:order_with_line_items, ship_address: ship_address, state: :address) }
|
179
|
+
|
180
|
+
around do |example|
|
181
|
+
SpreeAvataxOfficial::Config.address_validation_enabled = true
|
182
|
+
|
183
|
+
example.run
|
184
|
+
|
185
|
+
SpreeAvataxOfficial::Config.address_validation_enabled = false
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'when address is invalid' do
|
189
|
+
let(:ship_address) { create(:invalid_usa_address) }
|
190
|
+
|
191
|
+
it 'does not change order state to delivery and adds an error' do
|
192
|
+
VCR.use_cassette('spree_avatax_official/address/validate_failure') do
|
193
|
+
expect { order.next! }.to raise_error StateMachines::InvalidTransition
|
194
|
+
expect(order.errors.count).to eq 1
|
195
|
+
expect(order.state).to eq 'address'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when address is valid' do
|
201
|
+
let(:ship_address) { create(:usa_address) }
|
202
|
+
|
203
|
+
it 'changes state from address to delivery' do
|
204
|
+
VCR.use_cassette('spree_avatax_official/address/validate_success') do
|
205
|
+
expect { order.next! }.to change(order, :state).to 'delivery'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Shipment do
|
4
|
+
let(:shipment) { create(:shipment) }
|
5
|
+
|
6
|
+
describe '#avatax_number' do
|
7
|
+
it 'returns shipment id with avatax code' do
|
8
|
+
expect(shipment.avatax_number).to eq "FR-#{shipment.avatax_uuid}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SpreeAvataxOfficial::AvataxLog, type: :model do
|
4
|
+
let(:file_name) { 'test_file.log' }
|
5
|
+
let(:logger) { described_class.new }
|
6
|
+
let(:example_payload) { { test: 'Test!' } }
|
7
|
+
let!(:order) { create(:order) }
|
8
|
+
let(:payload) { File.new(Rails.root.join('log', file_name)).read }
|
9
|
+
let(:log_data) { "[AVATAX] #{order.class} #{order.id} : #{order.number}" }
|
10
|
+
|
11
|
+
before do
|
12
|
+
SpreeAvataxOfficial::Config.log_file_name = file_name
|
13
|
+
SpreeAvataxOfficial::Config.log_to_stdout = false
|
14
|
+
SpreeAvataxOfficial::Config.log = true
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#enabled?' do
|
18
|
+
it 'returns a boolean value' do
|
19
|
+
SpreeAvataxOfficial::Config.log = true
|
20
|
+
|
21
|
+
expect(logger).to be_enabled
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#info' do
|
26
|
+
it 'logs info with given message' do
|
27
|
+
logger.info(example_payload)
|
28
|
+
|
29
|
+
expect(payload).to include "[AVATAX] #{example_payload.to_json}"
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns nil if logger is not enabled' do
|
33
|
+
SpreeAvataxOfficial::Config.log = false
|
34
|
+
|
35
|
+
expect(logger.info('this_wont_change')).to be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'STDOUT' do
|
39
|
+
before do
|
40
|
+
SpreeAvataxOfficial::Config.log_to_stdout = true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'writes logs to STDOUT' do
|
44
|
+
expect { logger.info('Test!') }.to output.to_stdout_from_any_process
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#debug' do
|
50
|
+
it 'receives debug with message' do
|
51
|
+
logger.debug(order, example_payload)
|
52
|
+
|
53
|
+
expect(payload).to include "#{log_data} #{example_payload.to_json}"
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns nil if logger is not enabled' do
|
57
|
+
SpreeAvataxOfficial::Config.log = false
|
58
|
+
|
59
|
+
expect(logger.debug(['Test!'])).to be_nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#error' do
|
64
|
+
it 'logs error with given message' do
|
65
|
+
logger.error(order, example_payload)
|
66
|
+
|
67
|
+
expect(payload).to include "#{log_data} #{example_payload.to_json}"
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns nil if logger is not enabled' do
|
71
|
+
SpreeAvataxOfficial::Config.log = false
|
72
|
+
|
73
|
+
expect(logger.error('this_wont_change')).to be_nil
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'message with status and body' do
|
77
|
+
it 'logs error with given message' do
|
78
|
+
message = Struct.new(:message, :status, :body)
|
79
|
+
example_payload = message.new(400, test: 'Test!')
|
80
|
+
log_data = "#{log_data} #{example_payload.status} #{example_payload.body.to_json}"
|
81
|
+
|
82
|
+
logger.error(order, example_payload)
|
83
|
+
expect(payload).to include log_data
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SpreeAvataxOfficial::HasUuid do
|
4
|
+
class Spree::LineItem
|
5
|
+
include ::SpreeAvataxOfficial::HasUuid
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:line_item) { create(:line_item) }
|
9
|
+
|
10
|
+
describe '#avatax_uuid' do
|
11
|
+
it 'generates uuid for new instance' do
|
12
|
+
expect(line_item.avatax_uuid).not_to be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#avatax_number' do
|
17
|
+
it 'return uuid with avatax code' do
|
18
|
+
expect(line_item.avatax_number).to eq "LI-#{line_item.avatax_uuid}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SpreeAvataxOfficial::Spree::RefundDecorator do
|
4
|
+
describe '#create', :avatax_enabled do
|
5
|
+
let(:refund) { create(:refund, amount: 10) }
|
6
|
+
|
7
|
+
context 'commit transaction enabled' do
|
8
|
+
before { SpreeAvataxOfficial::Config.commit_transaction_enabled = true }
|
9
|
+
|
10
|
+
it 'calls refund service' do
|
11
|
+
expect(SpreeAvataxOfficial::Transactions::RefundService).to receive(:call)
|
12
|
+
|
13
|
+
refund
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'commit transaction disabled' do
|
18
|
+
around do |example|
|
19
|
+
SpreeAvataxOfficial::Config.commit_transaction_enabled = false
|
20
|
+
example.run
|
21
|
+
SpreeAvataxOfficial::Config.commit_transaction_enabled = true
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'doesnt call refund service' do
|
25
|
+
expect(SpreeAvataxOfficial::Transactions::RefundService).to_not receive(:call)
|
26
|
+
|
27
|
+
refund
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|