From d520e3838c4544e2ef44fbf188771481c4375ba0 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 28 Apr 2024 18:32:28 +0100 Subject: [PATCH] Removes unused spec related to legacy checkout We can see on the respective controller spec, that having a Stripe SCA payment, with no source does not trigger the error 400, observed on the legacy checkout. --- spec/controllers/checkout_controller_spec.rb | 25 +++++ .../requests/checkout/failed_checkout_spec.rb | 93 ------------------- 2 files changed, 25 insertions(+), 93 deletions(-) delete mode 100644 spec/requests/checkout/failed_checkout_spec.rb diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 7c4a158e4d..80e69d4a14 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -10,6 +10,9 @@ RSpec.describe CheckoutController, type: :controller do let(:exchange) { order_cycle.exchanges.outgoing.first } let(:order) { create(:order_with_line_items, line_items_count: 1, distributor:, order_cycle:) } let(:payment_method) { distributor.payment_methods.first } + let(:stripe_payment_method) { + create(:stripe_sca_payment_method, distributor_ids: [distributor.id], environment: Rails.env) + } let(:shipping_method) { distributor.shipping_methods.first } before do @@ -287,6 +290,7 @@ RSpec.describe CheckoutController, type: :controller do expect(response).to redirect_to checkout_step_path(:summary) expect(order.reload.state).to eq "confirmation" + expect(response.status).to be 302 end describe "with a voucher" do @@ -308,6 +312,27 @@ RSpec.describe CheckoutController, type: :controller do end end + context "with no payment source" do + let(:checkout_params) do + { + order: { + payments_attributes: [ + { payment_method_id: stripe_payment_method.id } + ] + } + } + end + + it "updates and redirects to summary step" do + put(:update, params:) + + expect(response).to redirect_to checkout_step_path(:summary) + expect(order.reload.state).to eq "confirmation" + expect(order.payments.first.source).to eq nil + expect(response.status).to be 302 + end + end + context "with payment fees" do let(:payment_method_with_fee) do create(:payment_method, :flat_rate, amount: "1.23", distributors: [distributor]) diff --git a/spec/requests/checkout/failed_checkout_spec.rb b/spec/requests/checkout/failed_checkout_spec.rb deleted file mode 100644 index f7a767f630..0000000000 --- a/spec/requests/checkout/failed_checkout_spec.rb +++ /dev/null @@ -1,93 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe "checking out an order that initially fails", type: :request do - include ShopWorkflow - - let!(:shop) { create(:enterprise) } - let!(:order_cycle) { create(:simple_order_cycle) } - let!(:exchange) { - create(:exchange, order_cycle:, sender: order_cycle.coordinator, receiver: shop, - incoming: false, pickup_time: "Monday") - } - let!(:address) { create(:address) } - let!(:line_item) { create(:line_item, order:, quantity: 3, price: 5.00) } - let!(:payment_method) { - create(:stripe_sca_payment_method, distributor_ids: [shop.id], environment: Rails.env) - } - let!(:check_payment_method) { - create(:payment_method, distributor_ids: [shop.id], environment: Rails.env) - } - let!(:shipping_method) { create(:shipping_method, distributor_ids: [shop.id]) } - let!(:shipment) { create(:shipment_with, :shipping_method, shipping_method:) } - let!(:order) { - create(:order, shipments: [shipment], distributor: shop, order_cycle:) - } - let(:params) do - { order: { - shipping_method_id: shipping_method.id, - payments_attributes: [{ payment_method_id: payment_method.id }], - bill_address_attributes: address.attributes.slice("firstname", "lastname", "address1", - "address2", "phone", "city", "zipcode", - "state_id", "country_id"), - ship_address_attributes: address.attributes.slice("firstname", "lastname", "address1", - "address2", "phone", "city", "zipcode", - "state_id", "country_id") - } } - end - - before do - order_cycle_distributed_variants = double(:order_cycle_distributed_variants) - allow(OrderCycles::DistributedVariantsService).to receive(:new) - .and_return(order_cycle_distributed_variants) - allow(order_cycle_distributed_variants) - .to receive(:distributes_order_variants?).and_return(true) - - order.reload.update_totals - set_order order - end - - pending "when shipping and payment fees apply" do - let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) } - - before do - payment_method.calculator = calculator.dup - payment_method.save! - check_payment_method.calculator = calculator.dup - check_payment_method.save! - shipping_method.calculator = calculator.dup - shipping_method.save! - end - - it "clears shipments and payments before rendering the checkout" do - put update_checkout_path, params:, as: :json - - # Checking out a bogus Stripe Gateway without a source fails at :payment - # Shipments and payments should then be cleared before rendering checkout - expect(response.status).to be 400 - expect(flash[:error]) - .to eq 'Payment could not be processed, please check the details you entered' - order.reload - expect(order.shipments.count).to be 0 - expect(order.payments.count).to be 0 - expect(order.adjustment_total).to eq 0 - - # Add another line item to change the fee totals - create(:line_item, order:, quantity: 3, price: 5.00) - - # Use a check payment method, which should work - params[:order][:payments_attributes][0][:payment_method_id] = check_payment_method.id - - put update_checkout_path, params:, as: :json - - expect(response.status).to be 200 - order.reload - expect(order.total).to eq 36 - expect(order.adjustment_total).to eq 6 - expect(order.item_total).to eq 30 - expect(order.shipments.count).to eq 1 - expect(order.payments.count).to eq 1 - end - end -end