diff --git a/backend/spec/features/admin/orders/adjustments_spec.rb b/backend/spec/features/admin/orders/adjustments_spec.rb index 4650a27de6c..3cae2732ac9 100644 --- a/backend/spec/features/admin/orders/adjustments_spec.rb +++ b/backend/spec/features/admin/orders/adjustments_spec.rb @@ -3,29 +3,26 @@ describe "Adjustments", type: :feature do stub_authorization! - let!(:order) { create(:completed_order_with_totals, line_items_count: 5) } - let!(:line_item) do - line_item = order.line_items.first - # so we can be sure of a determinate price in our assertions - line_item.update_column(:price, 10) - line_item + let!(:ship_address) { create(:address) } + let!(:tax_zone) { create(:global_zone) } # will include the above address + let!(:tax_rate) { create(:tax_rate, amount: 0.20, zone: tax_zone, tax_category: tax_category) } + + let!(:order) do + create( + :completed_order_with_totals, + line_items_attributes: [{ price: 10, variant: variant }] * 5, + ship_address: ship_address, + ) end + let!(:line_item) { order.line_items[0] } - let!(:tax_adjustment) do - create(:tax_adjustment, - adjustable: line_item, - finalized: true, - order: order, - label: "VAT 5%", - amount: 10) - end + let(:tax_category) { create(:tax_category) } + let(:variant) { create(:variant, tax_category: tax_category) } let!(:adjustment) { order.adjustments.create!(order: order, label: 'Rebate', amount: 10) } before(:each) do - # To ensure the order totals are correct - order.update_totals - order.persist_totals + order.update! visit spree.admin_path click_link "Orders" @@ -35,9 +32,9 @@ context "admin managing adjustments" do it "should display the correct values for existing order adjustments" do - within_row(1) do - expect(column_text(2)).to eq("VAT 5%") - expect(column_text(3)).to eq("$10.00") + within first('table tr', text: 'Tax') do + expect(column_text(2)).to match(/TaxCategory - \d+ 20\.000%/) + expect(column_text(3)).to eq("$2.00") end end @@ -76,7 +73,9 @@ context "admin editing an adjustment" do before(:each) do - within_row(2) { click_icon :edit } + within('table tr', text: 'Rebate') do + click_icon :edit + end end context "successfully" do @@ -106,15 +105,19 @@ end context "deleting an adjustment" do - it "should not be possible if adjustment is closed" do - within_row(1) do - expect(page).not_to have_css('.fa-trash') + context 'when the adjustment is finalized' do + let!(:adjustment) { super().tap(&:finalize!) } + + it 'should not be possible' do + within('table tr', text: 'Rebate') do + expect(page).not_to have_css('.fa-trash') + end end end it "should update the total", js: true do accept_alert do - within_row(2) do + within('table tr', text: 'Rebate') do click_icon(:trash) end end diff --git a/core/spec/models/spree/order/updating_spec.rb b/core/spec/models/spree/order/updating_spec.rb index 9a13be434ae..0772d4c35d3 100644 --- a/core/spec/models/spree/order/updating_spec.rb +++ b/core/spec/models/spree/order/updating_spec.rb @@ -1,11 +1,9 @@ require 'spec_helper' describe Spree::Order, type: :model do - let(:order) { stub_model(Spree::Order) } + let(:order) { create(:order) } context "#update!" do - let(:line_items) { [mock_model(Spree::LineItem, amount: 5)] } - context "when there are update hooks" do before { Spree::Order.register_update_hook :foo } after { Spree::Order.update_hooks.clear } diff --git a/core/spec/models/spree/order_cancellations_spec.rb b/core/spec/models/spree/order_cancellations_spec.rb index 4222631e094..b46961b53f7 100644 --- a/core/spec/models/spree/order_cancellations_spec.rb +++ b/core/spec/models/spree/order_cancellations_spec.rb @@ -134,17 +134,19 @@ let(:line_item) { order.line_items.to_a.first } let(:inventory_unit_1) { line_item.inventory_units[0] } let(:inventory_unit_2) { line_item.inventory_units[1] } + let(:promotion) { create(:promotion, :with_line_item_adjustment) } + let(:promotion_action) { promotion.actions[0] } before do order.contents.add(line_item.variant) # make the total $1.67 so it divides unevenly line_item.adjustments.create!( - source_type: 'Spree::TaxRate', order: order, amount: 0.01, - label: 'some fake tax', - finalized: true + label: 'some promo', + source: promotion_action, + finalized: true, ) order.update! end @@ -154,7 +156,7 @@ order.cancellations.short_ship([inventory_unit_2]) expect(line_item.adjustments.map(&:amount)).to match_array( [ - 0.01, # tax adjustment + 0.01, # promo adjustment -0.84, # short ship 1 -0.83, # short ship 2 ] diff --git a/core/spec/models/spree/order_updater_spec.rb b/core/spec/models/spree/order_updater_spec.rb index f6dc1dff4dd..887d9e3def0 100644 --- a/core/spec/models/spree/order_updater_spec.rb +++ b/core/spec/models/spree/order_updater_spec.rb @@ -276,7 +276,6 @@ def create_adjustment(label, amount) let(:order) do create( :order_with_line_items, - line_items_count: 1, line_items_attributes: [{ price: 10, variant: variant }], ship_address: ship_address, ) diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb index 62df39207ae..70788cf5832 100644 --- a/core/spec/models/spree/shipment_spec.rb +++ b/core/spec/models/spree/shipment_spec.rb @@ -118,10 +118,23 @@ end context "#item_cost" do + let(:shipment) { order.shipments[0] } + + let(:order) do + create( + :order_ready_to_ship, + line_items_attributes: [{ price: 10, variant: variant }], + ship_address: ship_address, + ) + end + + let!(:ship_address) { create(:address) } + let!(:tax_zone) { create(:global_zone) } # will include the above address + let!(:tax_rate) { create(:tax_rate, amount: 0.1, zone: tax_zone, tax_category: tax_category) } + let(:tax_category) { create(:tax_category) } + let(:variant) { create(:variant, tax_category: tax_category) } + it 'should equal line items final amount with tax' do - shipment = create(:shipment, order: create(:order_with_totals)) - create :tax_adjustment, adjustable: shipment.order.line_items.first, order: shipment.order - shipment.order.update! expect(shipment.item_cost).to eql(11.0) end end