From f52604db1b4691bebc5297bc8f2fc494dcb2c315 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 1 Jun 2023 05:51:32 +0100 Subject: [PATCH] remove legacy checkout tests --- .../admin/bulk_line_items_controller_spec.rb | 1 + .../stripe_controller_spec.rb | 28 +-- .../split_checkout_controller_spec.rb | 2 - spec/helpers/injection_helper_spec.rb | 4 - .../accordion_controller_spec.js.coffee | 24 -- .../checkout_controller_spec.js.coffee | 100 -------- .../details_controller_spec.js.coffee | 37 --- .../payment_controller_spec.js.coffee | 17 -- .../shop_variant_controller_spec.js.coffee | 164 ------------- spec/models/spree/order/state_machine_spec.rb | 6 + spec/models/spree/order_spec.rb | 7 +- spec/requests/checkout/routes_spec.rb | 27 +- spec/requests/voucher_adjustments_spec.rb | 2 - .../checkout/form_data_adapter_spec.rb | 85 ------- .../consumer/shopping/checkout_auth_spec.rb | 98 +++----- spec/system/consumer/split_checkout_spec.rb | 2 - .../consumer/split_checkout_tax_incl_spec.rb | 171 ++++--------- .../split_checkout_tax_not_incl_spec.rb | 230 +++++++----------- spec/system/consumer/white_label_spec.rb | 8 - 19 files changed, 192 insertions(+), 821 deletions(-) delete mode 100644 spec/javascripts/unit/darkswarm/controllers/checkout/accordion_controller_spec.js.coffee delete mode 100644 spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee delete mode 100644 spec/javascripts/unit/darkswarm/controllers/checkout/details_controller_spec.js.coffee delete mode 100644 spec/javascripts/unit/darkswarm/controllers/checkout/payment_controller_spec.js.coffee delete mode 100644 spec/javascripts/unit/darkswarm/controllers/checkout/shop_variant_controller_spec.js.coffee delete mode 100644 spec/services/checkout/form_data_adapter_spec.rb diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index 4e31f4f12db9..3e72f9e825de 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 @@ order.refresh_shipment_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 3984a4a3827d..5612accebdd8 100644 --- a/spec/controllers/payment_gateways/stripe_controller_spec.rb +++ b/spec/controllers/payment_gateways/stripe_controller_spec.rb @@ -46,21 +46,6 @@ module PaymentGateways order.payments << payment end - shared_examples "successful order completion" do - it "completes the order and redirects to the order confirmation page" do - expect(controller).to receive(:processing_succeeded).and_call_original - expect(controller).to receive(:order_completion_reset).and_call_original - - get :confirm, params: { payment_intent: "pi_123" } - - expect(order.completed?).to be true - expect(response).to redirect_to order_path(order, order_token: order.token) - expect(flash[:notice]).to eq 'Your order has been processed successfully' - end - end - - include_examples "successful order completion" - it "creates a customer record" do order.update_columns(customer_id: nil) Customer.delete_all @@ -89,12 +74,19 @@ module PaymentGateways context "using split checkout" do before do - Flipper.enable(:split_checkout) - order.update_attribute :state, "confirmation" end - include_examples "successful order completion" + it "completes the order and redirects to the order confirmation page" do + expect(controller).to receive(:processing_succeeded).and_call_original + expect(controller).to receive(:order_completion_reset).and_call_original + + get :confirm, params: { payment_intent: "pi_123" } + + expect(order.completed?).to be true + expect(response).to redirect_to order_path(order, order_token: order.token) + expect(flash[:notice]).to eq 'Your order has been processed successfully' + end end end diff --git a/spec/controllers/split_checkout_controller_spec.rb b/spec/controllers/split_checkout_controller_spec.rb index c57710a2bbe7..114a947c3951 100644 --- a/spec/controllers/split_checkout_controller_spec.rb +++ b/spec/controllers/split_checkout_controller_spec.rb @@ -16,8 +16,6 @@ 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 c4abbdbf17ff..06319fa87bfa 100644 --- a/spec/helpers/injection_helper_spec.rb +++ b/spec/helpers/injection_helper_spec.rb @@ -37,8 +37,6 @@ 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 @@ 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 3858f2a922c4..000000000000 --- 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 75d6fd8d36a0..000000000000 --- 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 163a6c0f0b74..000000000000 --- 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 46b152b00a00..000000000000 --- 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 c1e780e7834f..000000000000 --- 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/order/state_machine_spec.rb b/spec/models/spree/order/state_machine_spec.rb index dc4b767ce708..3426532cb116 100644 --- a/spec/models/spree/order/state_machine_spec.rb +++ b/spec/models/spree/order/state_machine_spec.rb @@ -24,6 +24,8 @@ 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 @@ 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 @@ 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_spec.rb b/spec/models/spree/order_spec.rb index 5c250f970e85..f62c21f739d8 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -689,6 +689,7 @@ before do allow(order).to receive(:tax_zone) { shipping_tax_rate.zone } + order.update_attribute(:state, 'payment') order.reload order.create_tax_charge! end @@ -1268,7 +1269,8 @@ 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 @@ -1302,7 +1304,8 @@ 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 d0f37c5b6a78..d328542ae259 100644 --- a/spec/requests/checkout/routes_spec.rb +++ b/spec/requests/checkout/routes_spec.rb @@ -37,28 +37,13 @@ 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 - - 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") + 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 e663c1a6a9db..9154f7ea3275 100644 --- a/spec/requests/voucher_adjustments_spec.rb +++ b/spec/requests/voucher_adjustments_spec.rb @@ -10,8 +10,6 @@ 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 30aaab213845..000000000000 --- 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/consumer/shopping/checkout_auth_spec.rb b/spec/system/consumer/shopping/checkout_auth_spec.rb index 2808bb00984e..b44deee4810c 100644 --- a/spec/system/consumer/shopping/checkout_auth_spec.rb +++ b/spec/system/consumer/shopping/checkout_auth_spec.rb @@ -29,93 +29,51 @@ 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 + 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 + + 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 - it "renders the login buttons when logged out" do + describe "logging in" do + before do visit checkout_path - within "section[role='main']" do - expect(page).to have_content "Login" - click_button "Login" - end + 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 - 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 + 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 end end - describe "shared examples" do - context "legacy checkout" do - it_behaves_like "with different checkout types", "legacy_checkout" - end - - context "split checkout" do - before do - Flipper.enable(:split_checkout) - end - include_examples "with different checkout types", "split_checkout" - end - end - context "using the guest checkout" do it "allows user to checkout as guest" do visit checkout_path 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 269551b7ffd5..ebafdb03a4a8 100644 --- a/spec/system/consumer/split_checkout_spec.rb +++ b/spec/system/consumer/split_checkout_spec.rb @@ -70,8 +70,6 @@ } 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 b4935aca7c67..66edeff00805 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 @@ 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 + before do + set_order order_within_zone + login_as(user_within_zone) + end - find(:xpath, '//*[@id="shipping"]/ng-form/dd').click - choose free_shipping.name.to_s + it "will be charged tax on the order" do + visit checkout_step_path(:details) - within "#payment" do - choose free_payment.name.to_s - end + choose "Delivery" - click_on "Place order now" + click_button "Next - Payment method" + click_on "Next - Order summary" + click_on "Complete order" - # 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)) + # 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 + # DB checks + assert_db_tax_incl end - context "on split-checkout" do - before do - Flipper.enable(:split_checkout) - - set_order order_within_zone - login_as(user_within_zone) + 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) - - 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" + # DB check + order_within_zone.reload + voucher_adjustment = order_within_zone.voucher_adjustments.first - # 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) - - 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_step_path(:details) - it "will not be charged tax on the order" do - pending("#7540") - visit checkout_step_path(:details) + choose "Delivery" + check "order_save_bill_address" + check "ship_address_same_as_billing" - choose "Delivery" - check "order_save_bill_address" - check "ship_address_same_as_billing" - - click_button "Next - Payment method" - click_on "Next - Order summary" - click_on "Complete order" + 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") + # 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 2b734adfe422..c7b0de4b614a 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 @@ 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 + 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 + it "will be charged tax on the order" do + visit checkout_step_path(:details) - find(:xpath, '//*[@id="shipping"]/ng-form/dd').click - choose free_shipping.name.to_s + choose "Delivery" - within "#payment" do - choose free_payment.name.to_s - end + click_button "Next - Payment method" + click_on "Next - Order summary" + click_on "Complete order" - click_on "Place order now" + # DB checks + order_within_zone.reload + expect(order_within_zone.additional_tax_total).to eq(1.3) - # 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 + # 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 "on split-checkout" do - before do - Flipper.enable(:split_checkout) - - set_order order_within_zone - login_as(user_within_zone) + 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) - end - - 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") + # Voucher + within "#line-items" do + expect(page).to have_content(voucher.code) + expect(page).to have_content(with_currency(-8.85)) - 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 + 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 + # 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 + 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 + it "will not be charged tax on the order" do + visit checkout_step_path(:details) - find(:xpath, '//*[@id="shipping"]/ng-form/dd').click - choose free_shipping.name.to_s + choose "Delivery" - within "#payment" do - choose free_payment.name.to_s - end + click_button "Next - Payment method" + click_on "Next - Order summary" + click_on "Complete order" - 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) - # 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 + # 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 - context "on split-checkout" do + # 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" - 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 - 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 + # 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 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" + # 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" + choose "Delivery" + click_button "Next - Payment method" - click_on "Next - Order summary" + 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)) + # 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" + 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) + # 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 + # 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 end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index a4b46b542815..aab3675b024c 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -91,15 +91,7 @@ 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