mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Redirect /checkout/whatever to /checkout when split_checkout is activate
+ constraint the legacy checkout routes when `split_checkout` feature is disabled + add specs
This commit is contained in:
committed by
Filipe
parent
ee70645d04
commit
b2db63178f
@@ -91,11 +91,17 @@ Openfoodnetwork::Application.routes.draw do
|
||||
get '/checkout/:step', to: 'split_checkout#edit', as: :checkout_step
|
||||
put '/checkout/:step', to: 'split_checkout#update', as: :checkout_update
|
||||
end
|
||||
|
||||
# Redirects to the new checkout for any other 'step' (ie. /checkout/cart from the legacy checkout)
|
||||
get '/checkout/:other', to: redirect('/checkout')
|
||||
end
|
||||
|
||||
get '/checkout', to: 'checkout#edit'
|
||||
put '/checkout', to: 'checkout#update', as: :update_checkout
|
||||
get '/checkout/:state', to: 'checkout#edit', as: :checkout_state
|
||||
# When the split_checkout feature is disabled for the current user, use the legacy checkout
|
||||
constraints ->(request) { OpenFoodNetwork::FeatureToggle.disabled? :split_checkout, request.env['warden']&.user } do
|
||||
get '/checkout', to: 'checkout#edit'
|
||||
put '/checkout', to: 'checkout#update', as: :update_checkout
|
||||
get '/checkout/:state', to: 'checkout#edit', as: :checkout_state
|
||||
end
|
||||
|
||||
get 'embedded_shopfront/shopfront_session', to: 'application#shopfront_session'
|
||||
post 'embedded_shopfront/enable', to: 'application#enable_embedded_styles'
|
||||
|
||||
@@ -12,5 +12,9 @@ module OpenFoodNetwork
|
||||
feature.add unless feature.exist?
|
||||
feature.enabled?(user)
|
||||
end
|
||||
|
||||
def self.disabled?(feature_name, user = nil)
|
||||
!enabled?(feature_name, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
64
spec/requests/checkout/routes_spec.rb
Normal file
64
spec/requests/checkout/routes_spec.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe 'checkout endpoints', type: :request do
|
||||
include ShopWorkflow
|
||||
|
||||
let!(:shop) { create(:enterprise) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle) }
|
||||
let!(:exchange) {
|
||||
create(:exchange, order_cycle: order_cycle, sender: order_cycle.coordinator, receiver: shop,
|
||||
incoming: false, pickup_time: "Monday")
|
||||
}
|
||||
let!(:line_item) { create(:line_item, order: order, quantity: 3, price: 5.00) }
|
||||
let!(:payment_method) {
|
||||
create(:bogus_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: shipping_method) }
|
||||
let!(:order) {
|
||||
create(:order, shipments: [shipment], distributor: shop, order_cycle: order_cycle)
|
||||
}
|
||||
|
||||
before do
|
||||
order_cycle_distributed_variants = double(:order_cycle_distributed_variants)
|
||||
allow(OrderCycleDistributedVariants).to receive(:new)
|
||||
.and_return(order_cycle_distributed_variants)
|
||||
allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?)
|
||||
.and_return(true)
|
||||
|
||||
set_order order
|
||||
end
|
||||
|
||||
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")
|
||||
|
||||
# follow the redirect
|
||||
get response.redirect_url
|
||||
expect(response.status).to redirect_to("/checkout/details")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user