diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index 851e102a7c..c5e6e49977 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -379,6 +379,7 @@ describe Admin::BulkLineItemsController, type: :controller do order.shipments.map(&:refresh_rates) order.select_shipping_method(shipping_method.id) + OrderWorkflow.new(order).advance_to_payment order.finalize! order.recreate_all_fees! order.create_tax_charge! diff --git a/spec/controllers/payment_gateways/stripe_controller_spec.rb b/spec/controllers/payment_gateways/stripe_controller_spec.rb index 36095c9f74..3c611df908 100644 --- a/spec/controllers/payment_gateways/stripe_controller_spec.rb +++ b/spec/controllers/payment_gateways/stripe_controller_spec.rb @@ -74,8 +74,6 @@ Please try again!" context "using split checkout" do before do - Flipper.enable(:split_checkout) - order.update_attribute :state, "confirmation" end diff --git a/spec/controllers/split_checkout_controller_spec.rb b/spec/controllers/split_checkout_controller_spec.rb index c57710a2bb..114a947c39 100644 --- a/spec/controllers/split_checkout_controller_spec.rb +++ b/spec/controllers/split_checkout_controller_spec.rb @@ -16,8 +16,6 @@ describe SplitCheckoutController, type: :controller do let(:shipping_method) { distributor.shipping_methods.first } before do - Flipper.enable(:split_checkout) - exchange.variants << order.line_items.first.variant allow(controller).to receive(:current_order) { order } allow(controller).to receive(:spree_current_user) { user } diff --git a/spec/helpers/injection_helper_spec.rb b/spec/helpers/injection_helper_spec.rb index c4abbdbf17..06319fa87b 100644 --- a/spec/helpers/injection_helper_spec.rb +++ b/spec/helpers/injection_helper_spec.rb @@ -37,8 +37,6 @@ describe InjectionHelper, type: :helper do order = create(:order, distributor: current_distributor) allow(helper).to receive(:current_order) { order } allow(helper).to receive(:spree_current_user) { nil } - expect(helper.inject_available_shipping_methods).to match sm.id.to_s - expect(helper.inject_available_shipping_methods).to match sm.compute_amount(order).to_s end it "injects payment methods" do @@ -47,8 +45,6 @@ describe InjectionHelper, type: :helper do order = create(:order, distributor: current_distributor) allow(helper).to receive(:current_order) { order } allow(helper).to receive(:spree_current_user) { nil } - expect(helper.inject_available_payment_methods).to match pm.id.to_s - expect(helper.inject_available_payment_methods).to match pm.name end it "injects current order" do diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee deleted file mode 100644 index 3858f2a922..0000000000 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee +++ /dev/null @@ -1,24 +0,0 @@ -describe "AccordionCtrl", -> - ctrl = null - scope = null - CurrentHubMock = - hub: - id: 1 - - beforeEach -> - module "Darkswarm" - module ($provide)-> - $provide.value "CurrentHub", CurrentHubMock - null - inject ($controller, $rootScope) -> - scope = $rootScope.$new() - scope.order = - id: 129 - ctrl = $controller 'AccordionCtrl', {$scope: scope} - - it "defaults the details accordion to visible", -> - expect(scope.accordion.details).toEqual true - - it "changes accordion", -> - scope.show "shipping" - expect(scope.accordion["shipping"]).toEqual true diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee deleted file mode 100644 index 75d6fd8d36..0000000000 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee +++ /dev/null @@ -1,100 +0,0 @@ -describe "CheckoutCtrl", -> - ctrl = null - scope = null - Checkout = null - CurrentUser = null - CurrentHubMock = - hub: - id: 1 - localStorageService = null - - beforeEach -> - module("Darkswarm") - angular.module('Darkswarm').value('user', {}) - angular.module('Darkswarm').value('currentHub', {id: 1}) - module ($provide)-> - $provide.value "CurrentHub", CurrentHubMock - null - Checkout = - purchase: -> - submit: -> - navigate: -> - bindFieldsToLocalStorage: -> - order: - id: 1 - email: "public" - user_id: 1 - bill_address: 'bill_address' - ship_address: 'ship address' - secrets: - card_number: "this is a secret" - - describe "with user", -> - beforeEach -> - inject ($controller, $rootScope, _localStorageService_) -> - localStorageService = _localStorageService_ - spyOn(localStorageService, "bind").and.callThrough() - scope = $rootScope.$new() - CurrentUser = { id: 1 } - ctrl = $controller 'CheckoutCtrl', {$scope: scope, Checkout: Checkout, CurrentUser: CurrentUser } - - describe "submitting", -> - event = - preventDefault: -> - - beforeEach -> - spyOn(Checkout, "purchase") - scope.submitted = false - - it "delegates to the service when valid", -> - scope.purchase(event, {$valid: true}) - expect(Checkout.purchase).toHaveBeenCalled() - expect(scope.submitted).toBe(true) - - it "does nothing when invalid", -> - scope.purchase(event, {$valid: false}) - expect(Checkout.purchase).not.toHaveBeenCalled() - expect(scope.submitted).toBe(true) - - it "is enabled", -> - expect(scope.enabled).toEqual true - - describe "Local storage", -> - it "binds to localStorage when given a scope", inject ($timeout) -> - prefix = "order_#{scope.order.id}#{CurrentUser.id or ""}#{CurrentHubMock.hub.id}" - - field = scope.fieldsToBind[0] - expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.order.#{field}", Checkout.order[field], "#{prefix}_#{field}") - expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", true, "#{prefix}_sameasbilling") - expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.default_bill_address", false, "#{prefix}_defaultasbilladdress") - expect(localStorageService.bind).toHaveBeenCalledWith(scope, "Checkout.default_ship_address", false, "#{prefix}_defaultasshipaddress") - - it "it can retrieve data from localstorage", -> - prefix = "order_#{scope.order.id}#{CurrentUser.id or ""}#{CurrentHubMock.hub.id}" - scope.$digest() - expect(localStorage.getItem("ls.#{prefix}_email")).toMatch "public" - - it "does not store secrets in local storage", -> - Checkout.secrets = - card_number: "superfuckingsecret" - scope.$digest() - keys = (localStorage.key(i) for i in [0..localStorage.length]) - for key in keys - expect(localStorage.getItem(key)).not.toMatch Checkout.secrets.card_number - - describe "without user", -> - beforeEach -> - inject ($controller, $rootScope) -> - scope = $rootScope.$new() - ctrl = $controller 'CheckoutCtrl', {$scope: scope, Checkout: Checkout, CurrentUser: {}} - - it "is disabled", -> - expect(scope.enabled).toEqual false - - it "does not store secrets in local storage", -> - Checkout.secrets = - card_number: "superfuckingsecret" - scope.$digest() - keys = (localStorage.key(i) for i in [0..localStorage.length]) - for key in keys - expect(localStorage.getItem(key)).not.toMatch Checkout.secrets.card_number diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee deleted file mode 100644 index 163a6c0f0b..0000000000 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee +++ /dev/null @@ -1,37 +0,0 @@ -describe "DetailsCtrl", -> - ctrl = null - scope = null - order = null - CurrentUser = null - - beforeEach -> - module("Darkswarm") - inject ($controller, $rootScope) -> - scope = $rootScope.$new() - CurrentUser = { id: 1 } - ctrl = $controller 'DetailsCtrl', { $scope: scope, CurrentUser: CurrentUser } - - - it "finds a field by path", -> - scope.details = - path: "test" - expect(scope.field('path')).toEqual "test" - - it "tests validity", -> - scope.details = - path: - $dirty: true - $invalid: true - expect(scope.fieldValid('path')).toEqual false - - it "returns errors by path", -> - scope.Order = - errors: -> - scope.details = - path: - $error: - email: true - required: true - expect(scope.fieldErrors('path')).toEqual ["must be email address", "can't be blank"].join ", " - - diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/payment_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/payment_controller_spec.js.coffee deleted file mode 100644 index 46b152b00a..0000000000 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/payment_controller_spec.js.coffee +++ /dev/null @@ -1,17 +0,0 @@ -describe "PaymentCtrl", -> - ctrl = null - scope = null - card1 = { id: 1, is_default: false } - card2 = { id: 3, is_default: true } - cards = [card1, card2] - - beforeEach -> - module("Darkswarm") - angular.module('Darkswarm').value('savedCreditCards', cards) - inject ($controller, $rootScope) -> - scope = $rootScope.$new() - scope.secrets = {} - ctrl = $controller 'PaymentCtrl', {$scope: scope} - - it "sets the default card id as the selected_card", -> - expect(scope.secrets.selected_card).toEqual card2.id diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee deleted file mode 100644 index c1e780e783..0000000000 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee +++ /dev/null @@ -1,164 +0,0 @@ -describe "ShopVariantCtrl", -> - ctrl = null - scope = null - CartMock = null - - beforeEach -> - module 'Darkswarm' - - inject ($rootScope, $controller, $modal)-> - scope = $rootScope.$new() - scope.$watchGroup = -> - scope.variant = { - on_demand: true - product: {group_buy: true} - line_item: { - quantity: undefined - max_quantity: undefined - } - } - CartMock = - adjust: -> - true - ctrl = $controller 'ShopVariantCtrl', {$scope: scope, $modal: $modal, Cart: CartMock, Shopfront: {}} - - it "initializes the quantity for shop display", -> - expect(scope.variant.line_item.quantity).toEqual 0 - - it "adds an item to the cart", -> - scope.add 1 - expect(scope.variant.line_item.quantity).toEqual 1 - - it "adds to the existing quantity", -> - scope.add 1 - scope.add 5 - expect(scope.variant.line_item.quantity).toEqual 6 - - it "adds to an invalid quantity", -> - scope.$apply -> - scope.variant.line_item.quantity = -5 - scope.add 1 - expect(scope.variant.line_item.quantity).toEqual 1 - - it "adds to an undefined quantity", -> - scope.$apply -> - scope.variant.line_item.quantity = undefined - scope.add 1 - expect(scope.variant.line_item.quantity).toEqual 1 - - it "adds to the max quantity", -> - scope.addMax 5 - expect(scope.variant.line_item.quantity).toEqual 0 - expect(scope.variant.line_item.max_quantity).toEqual 5 - - it "adds to an undefined max quantity", -> - scope.variant.line_item.quantity = 3 - scope.variant.line_item.max_quantity = undefined - scope.addMax 1 - expect(scope.variant.line_item.max_quantity).toEqual 4 - - it "adds to the max quantity to be at least min quantity", -> - scope.$apply -> - scope.variant.line_item.max_quantity = 2 - - scope.$apply -> - scope.add 3 - - expect(scope.variant.line_item.quantity).toEqual 3 - expect(scope.variant.line_item.max_quantity).toEqual 3 - - it "decreases the min quantity to not exceed max quantity", -> - scope.$apply -> - scope.variant.line_item.quantity = 3 - scope.variant.line_item.max_quantity = 5 - - scope.$apply -> - scope.addMax -3 - - expect(scope.variant.line_item.quantity).toEqual 2 - expect(scope.variant.line_item.max_quantity).toEqual 2 - - it "caps at the available quantity", -> - scope.$apply -> - scope.variant.on_demand = false - scope.variant.on_hand = 3 - scope.variant.line_item.quantity = 5 - scope.variant.line_item.max_quantity = 7 - - expect(scope.variant.line_item.quantity).toEqual 3 - expect(scope.variant.line_item.max_quantity).toEqual 3 - - it "allows adding when variant is on demand", -> - expect(scope.canAdd(5000)).toEqual true - - it "denies adding if variant is out of stock", -> - scope.variant.on_demand = false - scope.variant.on_hand = 0 - - expect(scope.canAdd(1)).toEqual false - - it "denies adding if stock is limitted", -> - scope.variant.on_demand = false - scope.variant.on_hand = 5 - - expect(scope.canAdd(4)).toEqual true - expect(scope.canAdd(5)).toEqual true - expect(scope.canAdd(6)).toEqual false - - scope.add 3 - expect(scope.canAdd(2)).toEqual true - expect(scope.canAdd(3)).toEqual false - - it "denies adding if quantity is too high", -> - scope.variant.on_demand = false - scope.variant.on_hand = 5 - scope.variant.line_item.quantity = 7 - scope.variant.line_item.max_quantity = 7 - - expect(scope.canAdd(1)).toEqual false - expect(scope.canAddMax(1)).toEqual false - - it "allows decrease when quantity is too high", -> - scope.variant.on_demand = false - scope.variant.on_hand = 5 - scope.variant.line_item.quantity = 7 - scope.variant.line_item.max_quantity = 7 - expect(scope.canAdd(-1)).toEqual true - expect(scope.canAddMax(-1)).toEqual true - - it "allows increase when quantity is negative", -> - scope.variant.on_demand = false - scope.variant.on_hand = 5 - scope.variant.line_item.quantity = -3 - scope.variant.line_item.max_quantity = -3 - expect(scope.canAdd(1)).toEqual true - expect(scope.canAddMax(1)).toEqual false - - scope.variant.line_item.quantity = 1 - expect(scope.canAddMax(1)).toEqual true - - it "denies decrease when quantity is negative", -> - scope.variant.on_demand = false - scope.variant.on_hand = 5 - scope.variant.line_item.quantity = -3 - scope.variant.line_item.max_quantity = -3 - expect(scope.canAdd(-1)).toEqual false - expect(scope.canAddMax(-1)).toEqual false - - it "denies declaring max quantity before item is in cart", -> - expect(scope.canAddMax(1)).toEqual false - - it "allows declaring max quantity when item is in cart", -> - scope.add 1 - expect(scope.canAddMax(1)).toEqual true - - it "denies adding if stock is limitted", -> - scope.variant.on_demand = false - scope.variant.on_hand = 5 - scope.variant.line_item.quantity = 1 - scope.variant.line_item.max_quantity = 1 - - expect(scope.canAddMax(3)).toEqual true - expect(scope.canAddMax(4)).toEqual true - expect(scope.canAddMax(5)).toEqual false - expect(scope.canAddMax(6)).toEqual false diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 9bb4baa06c..35a6ba5779 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -224,7 +224,7 @@ module Spree } let(:tax_category) { create(:tax_category, name: "Shipping", tax_rates: [tax_rate] ) } let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) } - let(:order) { create(:order, distributor: hub) } + let(:order) { create(:order, distributor: hub, state: 'payment') } let(:line_item) { create(:line_item, order: order) } let(:shipping_method) { @@ -348,7 +348,7 @@ module Spree let(:line_item) { create(:line_item, variant: variant) } let(:order) { create(:order, line_items: [line_item], order_cycle: order_cycle, - distributor: coordinator) + distributor: coordinator, state: 'payment') } let(:fee) { order.all_adjustments.reload.enterprise_fee.first } let(:fee_tax) { fee.adjustments.tax.first } @@ -508,7 +508,7 @@ module Spree let!(:zone) { create(:zone_with_member) } let!(:tax_category) { create(:tax_category, name: "Tax Test") } let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true) } - let(:order) { create(:order, distributor: distributor) } + let(:order) { create(:order, distributor: distributor, state: "payment") } let(:included_in_price) { true } let(:tax_rate) { create(:tax_rate, included_in_price: included_in_price, zone: zone, diff --git a/spec/models/spree/order/checkout_spec.rb b/spec/models/spree/order/checkout_spec.rb index 76912a62e5..69d46c1e4e 100644 --- a/spec/models/spree/order/checkout_spec.rb +++ b/spec/models/spree/order/checkout_spec.rb @@ -10,8 +10,9 @@ describe Spree::Order::Checkout do [ { address: :delivery }, { delivery: :payment }, - { payment: :complete }, - { delivery: :complete } + { delivery: :confirmation }, + { payment: :confirmation }, + { confirmation: :complete } ] end @@ -36,14 +37,14 @@ describe Spree::Order::Checkout do context "when payment not required" do before { allow(order).to receive_messages payment_required?: false } specify do - expect(order.checkout_steps).to eq %w(address delivery complete) + expect(order.checkout_steps).to eq %w(address delivery confirmation complete) end end context "when payment required" do before { allow(order).to receive_messages payment_required?: true } specify do - expect(order.checkout_steps).to eq %w(address delivery payment complete) + expect(order.checkout_steps).to eq %w(address delivery payment confirmation complete) end end end @@ -112,9 +113,9 @@ describe Spree::Order::Checkout do allow(order).to receive_messages payment_required?: false end - it "transitions to complete" do + it "transitions to confirmation" do order.next! - expect(order.state).to eq "complete" + expect(order.state).to eq 'confirmation' end end end diff --git a/spec/models/spree/order/state_machine_spec.rb b/spec/models/spree/order/state_machine_spec.rb index dc4b767ce7..3426532cb1 100644 --- a/spec/models/spree/order/state_machine_spec.rb +++ b/spec/models/spree/order/state_machine_spec.rb @@ -24,6 +24,8 @@ describe Spree::Order do before { allow(order).to receive_messages process_payments!: true } it "should finalize order when transitioning to complete state" do + order.next + expect(order.state).to eq "confirmation" expect(order).to receive(:finalize!) order.next! end @@ -32,6 +34,8 @@ describe Spree::Order do before { allow(order).to receive_messages process_payments!: false } it "should still complete the order" do + order.next + expect(order.state).to eq "confirmation" order.next expect(order.state).to eq "complete" end @@ -42,6 +46,8 @@ describe Spree::Order do before { allow(order).to receive_messages process_payments!: false } it "can transition to complete" do + order.next + expect(order.state).to eq "confirmation" order.next expect(order.state).to eq "complete" end diff --git a/spec/models/spree/order/tax_spec.rb b/spec/models/spree/order/tax_spec.rb index 072e8999cd..900720aa8c 100644 --- a/spec/models/spree/order/tax_spec.rb +++ b/spec/models/spree/order/tax_spec.rb @@ -152,6 +152,10 @@ module Spree label: "legacy", originator_type: "Spree::TaxRate") } + before do + order.update(state: "payment") + end + it "removes any legacy tax adjustments on order" do order.create_tax_charge! diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 97204b6db9..adaaf97f4e 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -690,6 +690,7 @@ describe Spree::Order do before do allow(order).to receive(:tax_zone) { shipping_tax_rate.zone } + order.update_attribute(:state, 'payment') order.reload order.create_tax_charge! end @@ -1269,7 +1270,8 @@ describe Spree::Order do order.next! order.payments << create(:payment, order: order) - expect { order.next! }.to change { order.state }.from("payment").to("complete") + expect { order.next! }.to change { order.state }.from("payment").to("confirmation") + expect { order.next! }.to change { order.state }.from("confirmation").to("complete") end end @@ -1303,7 +1305,8 @@ describe Spree::Order do it "skips the payment state" do advance_to_delivery_state(order) - expect { order.next! }.to change { order.state }.from("delivery").to("complete") + expect { order.next! }.to change { order.state }.from("delivery").to("confirmation") + expect { order.next! }.to change { order.state }.from("confirmation").to("complete") end end end diff --git a/spec/requests/checkout/routes_spec.rb b/spec/requests/checkout/routes_spec.rb index d0f37c5b6a..d328542ae2 100644 --- a/spec/requests/checkout/routes_spec.rb +++ b/spec/requests/checkout/routes_spec.rb @@ -37,28 +37,13 @@ describe 'checkout endpoints', type: :request do context "when getting the cart `/checkout/cart`" do let(:path) { "/checkout/cart" } - context "using the legacy checkout" do - it "do not redirect" do - get path - puts response.redirect_url - expect(response.status).to eq(200) - end - end + it "redirect to the split checkout" do + get path + expect(response.status).to redirect_to("/checkout") - context "using the split checkout" do - before do - # feature toggle is enabled - Flipper.enable(:split_checkout) - end - - it "redirect to the split checkout" do - get path - expect(response.status).to redirect_to("/checkout") - - # follow the redirect - get response.redirect_url - expect(response.status).to redirect_to("/checkout/details") - end + # follow the redirect + get response.redirect_url + expect(response.status).to redirect_to("/checkout/details") end end end diff --git a/spec/requests/voucher_adjustments_spec.rb b/spec/requests/voucher_adjustments_spec.rb index e663c1a6a9..9154f7ea32 100644 --- a/spec/requests/voucher_adjustments_spec.rb +++ b/spec/requests/voucher_adjustments_spec.rb @@ -10,8 +10,6 @@ describe VoucherAdjustmentsController, type: :request do let!(:adjustment) { voucher.create_adjustment(voucher.code, order) } before do - Flipper.enable(:split_checkout) - # Make sure the order is created by the order user, the factory doesn't set ip properly order.created_by = user order.save! diff --git a/spec/services/checkout/form_data_adapter_spec.rb b/spec/services/checkout/form_data_adapter_spec.rb deleted file mode 100644 index 30aaab2138..0000000000 --- a/spec/services/checkout/form_data_adapter_spec.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Checkout::FormDataAdapter do - describe '#params' do - let(:params) { { "order" => { "order_id" => "123" } } } - let(:order) { create(:order) } - let(:user) { create(:user) } - - let(:adapter) { Checkout::FormDataAdapter.new(params, order, user) } - - it "returns the :order item in the params provided" do - expect(adapter.params[:order]).to eq params["order"] - end - - describe "when payment_attributes are provided" do - before { params["order"]["payments_attributes"] = [{ "payment_method_id" => "123" }] } - - describe "and source attributes are provided" do - let(:source_attributes) { { "payment_method_name" => "Pay at the farm" } } - - before { params["payment_source"] = { "123" => source_attributes } } - - it "moves payment source attributes to the order payment attributes" do - expect(adapter.params[:order][:payments_attributes]. - first[:source_attributes]).to eq source_attributes - end - end - - describe "and order total is not zero" do - before { order.total = "50.0" } - - it "sets the payment attributes amount to the order total" do - expect(adapter.params[:order][:payments_attributes].first[:amount]).to eq order.total - end - end - - describe "and a credit card is provided" do - before do - params["order"]["payments_attributes"].first["source_attributes"] = - { "number" => "4444333322221111" } - end - - it "fills in missing credit card brand" do - expect(adapter.params[:order][:payments_attributes].first[:source_attributes][:cc_type]).to eq "visa" - end - - it "leaves an existing credit card brand" do - params["order"]["payments_attributes"].first["source_attributes"]["cc_type"] = "test" - expect(adapter.params[:order][:payments_attributes].first[:source_attributes][:cc_type]).to eq "test" - end - - it "doesn't touch the credit card brand without a number" do - params["order"]["payments_attributes"].first["source_attributes"]["number"] = "" - expect(adapter.params[:order][:payments_attributes].first[:source_attributes].key?(:cc_type)).to eq false - end - end - - describe "and existing credit card is provided" do - before { params["order"]["existing_card_id"] = credit_card.id } - - describe "and credit card is owned by current user" do - let(:credit_card) { create(:credit_card, user_id: user.id) } - - before { params["order"]["existing_card_id"] = credit_card.id } - - it "adds card details to payment attributes" do - expect(adapter.params[:order][:payments_attributes].first[:source][:id]).to eq credit_card.id - expect(adapter.params[:order][:payments_attributes]. - first[:source][:last_digits]).to eq credit_card.last_digits - end - end - - describe "and credit card is not owned by current user" do - let(:credit_card) { create(:credit_card) } - - it "raises exception if credit card provided doesnt belong to the current user" do - expect { adapter.params[:order] }.to raise_error Spree::Core::GatewayError - end - end - end - end - end -end diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index edde70b1e1..93e1eb4273 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -578,7 +578,7 @@ describe ' } let(:order1) { create(:order, order_cycle: order_cycle, distributor: user1.enterprises.first, - shipments: [shipment], bill_address: bill_address) + shipments: [shipment], bill_address: bill_address, state: 'payment') } let(:product1) { create(:taxed_product, zone: zone, price: 12.54, tax_rate_amount: 0, sku: 'sku1') diff --git a/spec/system/consumer/shopping/cart_spec.rb b/spec/system/consumer/shopping/cart_spec.rb index 116041fe18..270b84d728 100644 --- a/spec/system/consumer/shopping/cart_spec.rb +++ b/spec/system/consumer/shopping/cart_spec.rb @@ -174,18 +174,6 @@ describe "full-page cart" do end end - describe "tax" do - before do - add_enterprise_fee enterprise_fee - add_product_to_cart order, product_with_tax - visit main_app.cart_path - end - - it "shows the total tax for the order, including product tax and tax on fees" do - expect(page).to have_selector '.tax-total', text: '11.00' # 10 + 1 - end - end - describe "updating quantities" do let(:li) { order.line_items.reload.last } let(:variant) { product_with_tax.variants.first } diff --git a/spec/system/consumer/shopping/checkout_auth_spec.rb b/spec/system/consumer/shopping/checkout_auth_spec.rb index 2808bb0098..b44deee481 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -29,66 +29,42 @@ describe "As a consumer I want to check out my cart" do add_product_to_cart order, product end - shared_examples "with different checkout types" do |checkout_type| - context "on #{checkout_type}" do - it "does not render the login form when logged in" do - login_as user - visit checkout_path - within "section[role='main']" do - expect(page).to have_no_content "Login" - expect(page).to have_checkout_details - end - end - - it "renders the login buttons when logged out" do - visit checkout_path - within "section[role='main']" do - expect(page).to have_content "Login" - click_button "Login" - end - expect(page).to have_login_modal - end - - describe "logging in" do - before do - visit checkout_path - within("section[role='main']") { click_button "Login" } - expect(page).to have_login_modal - fill_in "Email", with: user.email - fill_in "Password", with: user.password - within(".login-modal") { click_button 'Login' } - end - - context "and populating user details on (#{checkout_type})", - if: checkout_type.eql?("legacy_checkout") do - it "toggles the Details section" do - expect(page).to have_content "Your details" - page.find(:css, "i.ofn-i_052-point-down").click - end - end - - context "and populating user details on (#{checkout_type})", - if: checkout_type.eql?("split_checkout") do - it "should allow proceeding to the next step" do - expect(page).to have_content("Logged in successfully") - click_button "Next - Payment method" - expect(page).to have_button("Next - Order summary") - end - end + context "on split_checkout" do + it "does not render the login form when logged in" do + login_as user + visit checkout_path + within "section[role='main']" do + expect(page).to have_no_content "Login" + expect(page).to have_checkout_details end end - end - describe "shared examples" do - context "legacy checkout" do - it_behaves_like "with different checkout types", "legacy_checkout" + it "renders the login buttons when logged out" do + visit checkout_path + within "section[role='main']" do + expect(page).to have_content "Login" + click_button "Login" + end + expect(page).to have_login_modal end - context "split checkout" do + describe "logging in" do before do - Flipper.enable(:split_checkout) + visit checkout_path + within("section[role='main']") { click_button "Login" } + expect(page).to have_login_modal + fill_in "Email", with: user.email + fill_in "Password", with: user.password + within(".login-modal") { click_button 'Login' } + end + + context "and populating user details on (split_checkout)" do + it "should allow proceeding to the next step" do + expect(page).to have_content("Logged in successfully") + click_button "Next - Payment method" + expect(page).to have_button("Next - Order summary") + end end - include_examples "with different checkout types", "split_checkout" end end @@ -98,24 +74,6 @@ describe "As a consumer I want to check out my cart" do checkout_as_guest expect(page).to have_checkout_details end - - it "asks the user to log in if they are using a registered email" do - visit checkout_path - checkout_as_guest - - fill_in 'First Name', with: 'Not' - fill_in 'Last Name', with: 'Guest' - fill_in 'Email', with: user.email - fill_in 'Phone', with: '098712736' - - within '#details' do - click_button 'Next' - end - - expect(page).to have_selector 'div.login-modal' - expect(page).to have_content 'This email address is already registered. Please log in '\ - 'to continue, or go back and use another email address.' - end end end end diff --git a/spec/system/consumer/split_checkout_spec.rb b/spec/system/consumer/split_checkout_spec.rb index 59e428f2de..f2939bb53e 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -70,8 +70,6 @@ describe "As a consumer, I want to checkout my order" do } before do - Flipper.enable(:split_checkout) - add_enterprise_fee enterprise_fee set_order order diff --git a/spec/system/consumer/split_checkout_tax_incl_spec.rb b/spec/system/consumer/split_checkout_tax_incl_spec.rb index b4935aca7c..66edeff008 100644 --- a/spec/system/consumer/split_checkout_tax_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_incl_spec.rb @@ -82,158 +82,95 @@ describe "As a consumer, I want to see adjustment breakdown" do end describe "for a customer with shipping address within the tax zone" do - context "on legacy checkout" do - before do - set_order order_within_zone - login_as(user_within_zone) - end - - it "will be charged tax on the order" do - visit checkout_path - - find(:xpath, '//*[@id="shipping"]/ng-form/dd').click - choose free_shipping.name.to_s - - within "#payment" do - choose free_payment.name.to_s - end - - click_on "Place order now" - - # UI checks - expect(page).to have_selector('#order_total', text: with_currency(10.00)) - expect(page).to have_selector('#tax-row', text: with_currency(1.15)) - - # DB checks - assert_db_tax_incl - end + before do + set_order order_within_zone + login_as(user_within_zone) end - context "on split-checkout" do - before do - Flipper.enable(:split_checkout) + it "will be charged tax on the order" do + visit checkout_step_path(:details) - set_order order_within_zone - login_as(user_within_zone) + choose "Delivery" + + click_button "Next - Payment method" + click_on "Next - Order summary" + click_on "Complete order" + + # UI checks + expect(page).to have_content("Confirmed") + expect(page).to have_selector('#order_total', text: with_currency(10.00)) + expect(page).to have_selector('#tax-row', text: with_currency(1.15)) + + # DB checks + assert_db_tax_incl + end + + context "when using a voucher" do + let!(:voucher) do + create(:voucher, code: 'some_code', enterprise: distributor, amount: 10) end - it "will be charged tax on the order" do + it "will include a tax included amount on the voucher adjustment" do visit checkout_step_path(:details) choose "Delivery" click_button "Next - Payment method" + + # add Voucher + fill_in "Enter voucher code", with: voucher.code + click_button("Apply") + + # Choose payment click_on "Next - Order summary" click_on "Complete order" # UI checks expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(10.00)) + expect(page).to have_selector('#order_total', text: with_currency(0.00)) expect(page).to have_selector('#tax-row', text: with_currency(1.15)) - # DB checks - assert_db_tax_incl - end - - context "when using a voucher" do - let!(:voucher) do - create(:voucher, code: 'some_code', enterprise: distributor, amount: 10) + # Voucher + within "#line-items" do + expect(page).to have_content(voucher.code) + expect(page).to have_content(with_currency(-10.00)) end - it "will include a tax included amount on the voucher adjustment" do - visit checkout_step_path(:details) + # DB check + order_within_zone.reload + voucher_adjustment = order_within_zone.voucher_adjustments.first - choose "Delivery" - - click_button "Next - Payment method" - - # add Voucher - fill_in "Enter voucher code", with: voucher.code - click_button("Apply") - - # Choose payment - click_on "Next - Order summary" - click_on "Complete order" - - # UI checks - expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(0.00)) - expect(page).to have_selector('#tax-row', text: with_currency(1.15)) - - # Voucher - within "#line-items" do - expect(page).to have_content(voucher.code) - expect(page).to have_content(with_currency(-10.00)) - end - - # DB check - order_within_zone.reload - voucher_adjustment = order_within_zone.voucher_adjustments.first - - expect(voucher_adjustment.amount.to_f).to eq(-10) - expect(voucher_adjustment.included_tax.to_f).to eq(-1.15) - end + expect(voucher_adjustment.amount.to_f).to eq(-10) + expect(voucher_adjustment.included_tax.to_f).to eq(-1.15) end end end describe "for a customer with shipping address outside the tax zone" do - context "on legacy checkout" do - before do - set_order order_outside_zone - login_as(user_outside_zone) - end - - it "will not be charged tax on the order" do - pending("#7540") - visit checkout_path - - find(:xpath, '//*[@id="shipping"]/ng-form/dd').click - choose free_shipping.name.to_s - - within "#payment" do - choose free_payment.name.to_s - end - - click_on "Place order now" - - # UI checks - expect(page).to have_selector('#order_total', text: with_currency(10.00)) - expect(page).not_to have_content("includes tax") - - # DB checks - assert_db_no_tax_incl - end + before do + set_order order_outside_zone + login_as(user_outside_zone) end - context "on split-checkout" do - before do - Flipper.enable(:split_checkout) + it "will not be charged tax on the order" do + pending("#7540") + visit checkout_step_path(:details) - set_order order_outside_zone - login_as(user_outside_zone) - end + choose "Delivery" + check "order_save_bill_address" + check "ship_address_same_as_billing" - it "will not be charged tax on the order" do - pending("#7540") - visit checkout_step_path(:details) + click_button "Next - Payment method" + click_on "Next - Order summary" + click_on "Complete order" - choose "Delivery" - check "order_save_bill_address" - check "ship_address_same_as_billing" + # UI checks + expect(page).to have_content("Confirmed") + expect(page).to have_selector('#order_total', text: with_currency(10.00)) + expect(page).not_to have_content("includes tax") - click_button "Next - Payment method" - click_on "Next - Order summary" - click_on "Complete order" - - # UI checks - expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(10.00)) - expect(page).not_to have_content("includes tax") - - # DB checks - assert_db_no_tax_incl - end + # DB checks + assert_db_no_tax_incl end end end diff --git a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb index 2b734adfe4..c7b0de4b61 100644 --- a/spec/system/consumer/split_checkout_tax_not_incl_spec.rb +++ b/spec/system/consumer/split_checkout_tax_not_incl_spec.rb @@ -88,207 +88,141 @@ describe "As a consumer, I want to see adjustment breakdown" do end describe "for a customer with shipping address within the tax zone" do - context "on legacy checkout" do - before do - set_order order_within_zone - login_as(user_within_zone) - end - - it "will be charged tax on the order" do - visit checkout_path - - find(:xpath, '//*[@id="shipping"]/ng-form/dd').click - choose free_shipping.name.to_s - - within "#payment" do - choose free_payment.name.to_s - end - - click_on "Place order now" - - # DB checks - order_within_zone.reload - expect(order_within_zone.additional_tax_total).to eq(1.3) - - # UI checks - expect(page).to have_selector('#order_total', text: with_currency(11.30)) - expect(page).to have_selector('#tax-row', text: with_currency(1.30)) - end + before do + set_order order_within_zone + login_as(user_within_zone) end - context "on split-checkout" do - before do - Flipper.enable(:split_checkout) + it "will be charged tax on the order" do + visit checkout_step_path(:details) - set_order order_within_zone - login_as(user_within_zone) + choose "Delivery" + + click_button "Next - Payment method" + click_on "Next - Order summary" + click_on "Complete order" + + # DB checks + order_within_zone.reload + expect(order_within_zone.additional_tax_total).to eq(1.3) + + # UI checks + expect(page).to have_content("Confirmed") + expect(page).to have_selector('#order_total', text: with_currency(11.30)) + expect(page).to have_selector('#tax-row', text: with_currency(1.30)) + end + + context "when using a voucher" do + let!(:voucher) do + create(:voucher, code: 'some_code', enterprise: distributor, amount: 10) end - it "will be charged tax on the order" do + it "will include a tax included amount on the voucher adjustment" do visit checkout_step_path(:details) choose "Delivery" click_button "Next - Payment method" + # add Voucher + fill_in "Enter voucher code", with: voucher.code + click_button("Apply") + click_on "Next - Order summary" click_on "Complete order" - # DB checks - order_within_zone.reload - expect(order_within_zone.additional_tax_total).to eq(1.3) - # UI checks expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(11.30)) + expect(page).to have_selector('#order_total', text: with_currency(1.30)) expect(page).to have_selector('#tax-row', text: with_currency(1.30)) - end - context "when using a voucher" do - let!(:voucher) do - create(:voucher, code: 'some_code', enterprise: distributor, amount: 10) + # Voucher + within "#line-items" do + expect(page).to have_content(voucher.code) + expect(page).to have_content(with_currency(-8.85)) + + expect(page).to have_content("Tax #{voucher.code}") + expect(page).to have_content(with_currency(-1.15)) end - it "will include a tax included amount on the voucher adjustment" do - visit checkout_step_path(:details) + # DB check + order_within_zone.reload + voucher_adjustment = order_within_zone.voucher_adjustments.first + voucher_tax_adjustment = order_within_zone.voucher_adjustments.second - choose "Delivery" - - click_button "Next - Payment method" - # add Voucher - fill_in "Enter voucher code", with: voucher.code - click_button("Apply") - - click_on "Next - Order summary" - click_on "Complete order" - - # UI checks - expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(1.30)) - expect(page).to have_selector('#tax-row', text: with_currency(1.30)) - - # Voucher - within "#line-items" do - expect(page).to have_content(voucher.code) - expect(page).to have_content(with_currency(-8.85)) - - expect(page).to have_content("Tax #{voucher.code}") - expect(page).to have_content(with_currency(-1.15)) - end - - # DB check - order_within_zone.reload - voucher_adjustment = order_within_zone.voucher_adjustments.first - voucher_tax_adjustment = order_within_zone.voucher_adjustments.second - - expect(voucher_adjustment.amount.to_f).to eq(-8.85) - expect(voucher_tax_adjustment.amount.to_f).to eq(-1.15) - end + expect(voucher_adjustment.amount.to_f).to eq(-8.85) + expect(voucher_tax_adjustment.amount.to_f).to eq(-1.15) end end end describe "for a customer with shipping address outside the tax zone" do - context "on legacy checkout" do - before do - set_order order_outside_zone - login_as(user_outside_zone) - end - - it "will not be charged tax on the order" do - visit checkout_path - - find(:xpath, '//*[@id="shipping"]/ng-form/dd').click - choose free_shipping.name.to_s - - within "#payment" do - choose free_payment.name.to_s - end - - click_on "Place order now" - - # DB checks - order_outside_zone.reload - expect(order_outside_zone.included_tax_total).to eq(0.0) - expect(order_outside_zone.additional_tax_total).to eq(0.0) - - # UI checks - expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(10.00)) - expect(page).not_to have_content("includes tax") - end + before do + set_order order_outside_zone + login_as(user_outside_zone) end - context "on split-checkout" do + it "will not be charged tax on the order" do + visit checkout_step_path(:details) + + choose "Delivery" + + click_button "Next - Payment method" + click_on "Next - Order summary" + click_on "Complete order" + + # DB checks + order_outside_zone.reload + expect(order_outside_zone.included_tax_total).to eq(0.0) + expect(order_outside_zone.additional_tax_total).to eq(0.0) + + # UI checks + expect(page).to have_content("Confirmed") + expect(page).to have_selector('#order_total', text: with_currency(10.00)) + expect(page).not_to have_content("includes tax") + end + + # reproducing bug #9153 + context "changing the address on the /details step" do before do - Flipper.enable(:split_checkout) - - set_order order_outside_zone - login_as(user_outside_zone) - end - - it "will not be charged tax on the order" do visit checkout_step_path(:details) - choose "Delivery" click_button "Next - Payment method" click_on "Next - Order summary" + + expect(page).to have_selector('#order_total', text: with_currency(10.00)) + + # customer goes back from Summary to Details step, to change Delivery + click_on "Your details" + end + + it "should re-calculate the tax accordingly" do + select "Victoria", from: "order_bill_address_attributes_state_id" + + # it should not be necessary to save as new default bill address + check "order_save_bill_address" + check "ship_address_same_as_billing" + + choose "Delivery" + click_button "Next - Payment method" + + click_on "Next - Order summary" + + # Summary step should reflect changes + expect(page).to have_selector('#order_total', text: with_currency(11.30)) + expect(page).to have_selector('#tax-row', text: with_currency(1.30)) + click_on "Complete order" # DB checks order_outside_zone.reload expect(order_outside_zone.included_tax_total).to eq(0.0) - expect(order_outside_zone.additional_tax_total).to eq(0.0) + expect(order_outside_zone.additional_tax_total).to eq(1.3) - # UI checks + # UI checks - Order confirmation page should reflect changes expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(10.00)) - expect(page).not_to have_content("includes tax") - end - - # reproducing bug #9153 - context "changing the address on the /details step" do - before do - visit checkout_step_path(:details) - choose "Delivery" - - click_button "Next - Payment method" - click_on "Next - Order summary" - - expect(page).to have_selector('#order_total', text: with_currency(10.00)) - - # customer goes back from Summary to Details step, to change Delivery - click_on "Your details" - end - - it "should re-calculate the tax accordingly" do - select "Victoria", from: "order_bill_address_attributes_state_id" - - # it should not be necessary to save as new default bill address - check "order_save_bill_address" - check "ship_address_same_as_billing" - - choose "Delivery" - click_button "Next - Payment method" - - click_on "Next - Order summary" - - # Summary step should reflect changes - expect(page).to have_selector('#order_total', text: with_currency(11.30)) - expect(page).to have_selector('#tax-row', text: with_currency(1.30)) - - click_on "Complete order" - - # DB checks - order_outside_zone.reload - expect(order_outside_zone.included_tax_total).to eq(0.0) - expect(order_outside_zone.additional_tax_total).to eq(1.3) - - # UI checks - Order confirmation page should reflect changes - expect(page).to have_content("Confirmed") - expect(page).to have_selector('#order_total', text: with_currency(11.30)) - expect(page).to have_selector('#tax-row', text: with_currency(1.30)) - end + expect(page).to have_selector('#order_total', text: with_currency(11.30)) + expect(page).to have_selector('#tax-row', text: with_currency(1.30)) end end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 0597ff5d68..712f3db302 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -145,7 +145,7 @@ describe 'White label setting' do set_order(order) end - shared_examples "hides the OFN navigation when needed only for the checkout" do + context "when the split checkout is enabled" do it_behaves_like "hides the OFN navigation when needed only" context "for cart path" do @@ -174,18 +174,6 @@ describe 'White label setting' do it_behaves_like "hides the OFN navigation for mobile view as well" end end - - context "when the split checkout is disabled" do - it_behaves_like "hides the OFN navigation when needed only for the checkout" - end - - context "when the split checkout is enabled" do - before do - Flipper.enable(:split_checkout) - end - - it_behaves_like "hides the OFN navigation when needed only for the checkout" - end end context "when the user has a complete order" do