mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #8739 from Matt-Yorkley/split-checkout-completion
Split checkout completion
This commit is contained in:
@@ -8,6 +8,7 @@ class SplitCheckoutController < ::BaseController
|
||||
include OrderStockCheck
|
||||
include Spree::BaseHelper
|
||||
include CheckoutCallbacks
|
||||
include OrderCompletion
|
||||
include CablecarResponses
|
||||
|
||||
helper 'terms_and_conditions'
|
||||
@@ -45,6 +46,7 @@ class SplitCheckoutController < ::BaseController
|
||||
|
||||
@order.customer.touch :terms_and_conditions_accepted_at
|
||||
@order.confirm!
|
||||
order_completion_reset @order
|
||||
end
|
||||
|
||||
def update_order
|
||||
|
||||
@@ -11,6 +11,39 @@ FactoryBot.define do
|
||||
completed_at { nil }
|
||||
email { user&.email || customer.email }
|
||||
|
||||
factory :order_ready_for_details do
|
||||
distributor { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
order_cycle { create(:order_cycle, distributors: [distributor]) }
|
||||
|
||||
after(:create) do |order|
|
||||
order.line_items << build(:line_item, order: order)
|
||||
order.updater.update_totals_and_states
|
||||
|
||||
order.order_cycle.exchanges.outgoing.first.variants << order.line_items.first.variant
|
||||
end
|
||||
|
||||
factory :order_ready_for_payment do
|
||||
bill_address
|
||||
ship_address
|
||||
|
||||
after(:create) do |order, evaluator|
|
||||
order.select_shipping_method evaluator.shipping_method.id
|
||||
OrderWorkflow.new(order).advance_to_payment
|
||||
end
|
||||
|
||||
factory :order_ready_for_confirmation do
|
||||
transient do
|
||||
payment_method { create(:payment_method, distributors: [distributor]) }
|
||||
end
|
||||
|
||||
after(:create) do |order, evaluator|
|
||||
order.payments << build(:payment, amount: order.total, payment_method: evaluator.payment_method)
|
||||
order.next!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
factory :order_with_totals do
|
||||
after(:create) do |order|
|
||||
create(:line_item, order: order)
|
||||
|
||||
@@ -8,7 +8,7 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
|
||||
let!(:zone) { create(:zone_with_member) }
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_guest_orders: false) }
|
||||
let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true) }
|
||||
let(:product) {
|
||||
create(:taxed_product, supplier: supplier, price: 10, zone: zone, tax_rate_amount: 0.1)
|
||||
}
|
||||
@@ -19,7 +19,8 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
}
|
||||
let(:order) {
|
||||
create(:order, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil,
|
||||
ship_address_id: nil, state: "cart")
|
||||
ship_address_id: nil, state: "cart",
|
||||
line_items: [create(:line_item, variant: variant)])
|
||||
}
|
||||
|
||||
let(:fee_tax_rate) { create(:tax_rate, amount: 0.10, zone: zone, included_in_price: true) }
|
||||
@@ -45,7 +46,6 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
|
||||
add_enterprise_fee enterprise_fee
|
||||
set_order order
|
||||
add_product_to_cart order, product
|
||||
|
||||
distributor.shipping_methods << free_shipping
|
||||
distributor.shipping_methods << shipping_with_fee
|
||||
@@ -53,6 +53,7 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
|
||||
context "guest checkout when distributor doesn't allow guest orders" do
|
||||
before do
|
||||
distributor.update_columns allow_guest_orders: false
|
||||
visit checkout_step_path(:details)
|
||||
end
|
||||
|
||||
@@ -70,8 +71,6 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
|
||||
context "as a guest user" do
|
||||
before do
|
||||
distributor.update!(allow_guest_orders: true)
|
||||
order.update!(distributor_id: distributor.id)
|
||||
visit checkout_path
|
||||
end
|
||||
|
||||
@@ -222,6 +221,25 @@ describe "As a consumer, I want to checkout my order", js: true do
|
||||
expect(page).to have_content("Select a shipping method")
|
||||
end
|
||||
end
|
||||
|
||||
context "summary step" do
|
||||
let(:order) { create(:order_ready_for_confirmation, distributor: distributor) }
|
||||
|
||||
describe "completing the checkout" do
|
||||
it "keeps the distributor selected for the current user after completion" do
|
||||
visit checkout_step_path(:summary)
|
||||
|
||||
expect(page).to have_content "Shopping @ #{distributor.name}"
|
||||
|
||||
click_on "Complete order"
|
||||
|
||||
expect(page).to have_content "Back To Store"
|
||||
expect(order.reload.state).to eq "complete"
|
||||
|
||||
expect(page).to have_content "Shopping @ #{distributor.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when I have an out of stock product in my cart" do
|
||||
|
||||
Reference in New Issue
Block a user