Give distributors a payment and shipping method where required

This commit is contained in:
Rohan Mitchell
2014-10-31 16:02:43 +11:00
parent e2d88e615b
commit f5b20b7afc
6 changed files with 144 additions and 143 deletions

View File

@@ -108,6 +108,17 @@ FactoryGirl.define do
factory :distributor_enterprise, :parent => :enterprise do
is_primary_producer false
sells "any"
ignore do
with_payment_and_shipping false
end
after(:create) do |enterprise, proxy|
if proxy.with_payment_and_shipping
create(:payment_method, distributors: [enterprise])
create(:shipping_method, distributors: [enterprise])
end
end
end
factory :enterprise_relationship do

View File

@@ -4,9 +4,7 @@ feature 'Home', js: true do
include AuthenticationWorkflow
include UIComponentHelper
let!(:distributor) { create(:distributor_enterprise) }
let!(:shipping_method) { create(:shipping_method, distributors: [distributor]) }
let!(:payment_method) { create(:payment_method, distributors: [distributor]) }
let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:invisible_distributor) { create(:distributor_enterprise, visible: false) }
let(:d1) { create(:distributor_enterprise) }
let(:d2) { create(:distributor_enterprise) }

View File

@@ -7,7 +7,7 @@ feature "As a consumer I want to check out my cart", js: true do
include CheckoutWorkflow
include UIComponentHelper
let(:distributor) { create(:distributor_enterprise) }
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:supplier) { create(:supplier_enterprise) }
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) }
let(:product) { create(:simple_product, supplier: supplier) }

View File

@@ -27,9 +27,19 @@ feature "As a consumer I want to check out my cart", js: true do
page.should have_content distributor.name
end
describe "with shipping methods" do
describe "with shipping and payment methods" do
let(:sm1) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 0.00)) }
let(:sm2) { create(:shipping_method, require_ship_address: false, name: "Donkeys", description: "blue", calculator: Spree::Calculator::FlatRate.new(preferred_amount: 4.56)) }
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") }
let!(:pm2) { create(:payment_method, distributors: [distributor]) }
let!(:pm3) do
Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', distributor_ids: [distributor.id]).tap do |pm|
pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com'
pm.preferred_password = '1406163716'
pm.preferred_signature = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AaTntNJ-AjvUJkWf4dgJIvcLsf1V'
end
end
before do
distributor.shipping_methods << sm1
distributor.shipping_methods << sm2
@@ -68,32 +78,62 @@ feature "As a consumer I want to check out my cart", js: true do
end
end
describe "with payment methods" do
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") }
let!(:pm2) { create(:payment_method, distributors: [distributor]) }
let!(:pm3) do
Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', distributor_ids: [distributor.id]).tap do |pm|
pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com'
pm.preferred_password = '1406163716'
pm.preferred_signature = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AaTntNJ-AjvUJkWf4dgJIvcLsf1V'
end
context "on the checkout page with payments open" do
before do
visit checkout_path
checkout_as_guest
toggle_payment
end
context "on the checkout page with payments open" do
before do
visit checkout_path
checkout_as_guest
it "shows all available payment methods" do
page.should have_content pm1.name
page.should have_content pm2.name
page.should have_content pm3.name
end
describe "purchasing" do
it "takes us to the order confirmation page when we submit a complete form" do
toggle_details
within "#details" do
fill_in "First Name", with: "Will"
fill_in "Last Name", with: "Marshall"
fill_in "Email", with: "test@test.com"
fill_in "Phone", with: "0468363090"
end
toggle_billing
within "#billing" do
fill_in "Address", with: "123 Your Face"
select "Australia", from: "Country"
select "Victoria", from: "State"
fill_in "City", with: "Melbourne"
fill_in "Postcode", with: "3066"
end
toggle_shipping
within "#shipping" do
choose sm2.name
fill_in 'Any notes or custom delivery instructions?', with: "SpEcIaL NoTeS"
end
toggle_payment
within "#payment" do
choose pm1.name
end
place_order
page.should have_content "Your order has been processed successfully"
ActionMailer::Base.deliveries.length.should == 2
email = ActionMailer::Base.deliveries.last
site_name = Spree::Config[:site_name]
email.subject.should include "#{site_name} Order Confirmation"
o = Spree::Order.complete.first
expect(o.special_instructions).to eq "SpEcIaL NoTeS"
end
it "shows all available payment methods" do
page.should have_content pm1.name
page.should have_content pm2.name
page.should have_content pm3.name
end
describe "purchasing" do
it "takes us to the order confirmation page when we submit a complete form" do
context "with basic details filled" do
before do
toggle_shipping
choose sm1.name
toggle_payment
choose pm1.name
toggle_details
within "#details" do
fill_in "First Name", with: "Will"
@@ -103,135 +143,93 @@ feature "As a consumer I want to check out my cart", js: true do
end
toggle_billing
within "#billing" do
fill_in "City", with: "Melbourne"
fill_in "Postcode", with: "3066"
fill_in "Address", with: "123 Your Face"
select "Australia", from: "Country"
select "Victoria", from: "State"
fill_in "City", with: "Melbourne"
fill_in "Postcode", with: "3066"
end
toggle_shipping
within "#shipping" do
choose sm2.name
fill_in 'Any notes or custom delivery instructions?', with: "SpEcIaL NoTeS"
end
toggle_payment
within "#payment" do
choose pm1.name
end
place_order
page.should have_content "Your order has been processed successfully"
ActionMailer::Base.deliveries.length.should == 2
email = ActionMailer::Base.deliveries.last
site_name = Spree::Config[:site_name]
email.subject.should include "#{site_name} Order Confirmation"
o = Spree::Order.complete.first
expect(o.special_instructions).to eq "SpEcIaL NoTeS"
check "Shipping address same as billing address?"
end
context "with basic details filled" do
before do
toggle_shipping
choose sm1.name
toggle_payment
choose pm1.name
toggle_details
within "#details" do
fill_in "First Name", with: "Will"
fill_in "Last Name", with: "Marshall"
fill_in "Email", with: "test@test.com"
fill_in "Phone", with: "0468363090"
end
toggle_billing
within "#billing" do
fill_in "City", with: "Melbourne"
fill_in "Postcode", with: "3066"
fill_in "Address", with: "123 Your Face"
select "Australia", from: "Country"
select "Victoria", from: "State"
end
toggle_shipping
check "Shipping address same as billing address?"
end
it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do
place_order
page.should have_content "Your order has been processed successfully"
end
it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do
context "when we are charged a shipping fee" do
before { choose sm2.name }
it "creates a payment for the full amount inclusive of shipping" do
place_order
page.should have_content "Your order has been processed successfully"
# There are two orders - our order and our new cart
o = Spree::Order.complete.first
o.adjustments.shipping.first.amount.should == 4.56
o.payments.first.amount.should == 10 + 1.23 + 4.56 # items + fees + shipping
end
end
context "with a credit card payment method" do
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::Gateway::Bogus") }
it "takes us to the order confirmation page when submitted with a valid credit card" do
toggle_payment
fill_in 'Card Number', with: "4111111111111111"
select 'February', from: 'secrets.card_month'
select (Date.today.year+1).to_s, from: 'secrets.card_year'
fill_in 'Security Code', with: '123'
place_order
page.should have_content "Your order has been processed successfully"
# Order should have a payment with the correct amount
o = Spree::Order.complete.first
o.payments.first.amount.should == 11.23
end
context "when we are charged a shipping fee" do
before { choose sm2.name }
it "shows the payment processing failed message when submitted with an invalid credit card" do
toggle_payment
fill_in 'Card Number', with: "9999999988887777"
select 'February', from: 'secrets.card_month'
select (Date.today.year+1).to_s, from: 'secrets.card_year'
fill_in 'Security Code', with: '123'
it "creates a payment for the full amount inclusive of shipping" do
place_order
page.should have_content "Your order has been processed successfully"
place_order
page.should have_content "Payment could not be processed, please check the details you entered"
# There are two orders - our order and our new cart
o = Spree::Order.complete.first
o.adjustments.shipping.first.amount.should == 4.56
o.payments.first.amount.should == 10 + 1.23 + 4.56 # items + fees + shipping
end
end
context "with a credit card payment method" do
let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::Gateway::Bogus") }
it "takes us to the order confirmation page when submitted with a valid credit card" do
toggle_payment
fill_in 'Card Number', with: "4111111111111111"
select 'February', from: 'secrets.card_month'
select (Date.today.year+1).to_s, from: 'secrets.card_year'
fill_in 'Security Code', with: '123'
place_order
page.should have_content "Your order has been processed successfully"
# Order should have a payment with the correct amount
o = Spree::Order.complete.first
o.payments.first.amount.should == 11.23
end
it "shows the payment processing failed message when submitted with an invalid credit card" do
toggle_payment
fill_in 'Card Number', with: "9999999988887777"
select 'February', from: 'secrets.card_month'
select (Date.today.year+1).to_s, from: 'secrets.card_year'
fill_in 'Security Code', with: '123'
place_order
page.should have_content "Payment could not be processed, please check the details you entered"
# Does not show duplicate shipping fee
visit checkout_path
page.all("th", text: "Shipping").count.should == 1
end
# Does not show duplicate shipping fee
visit checkout_path
page.all("th", text: "Shipping").count.should == 1
end
end
end
end
end
context "when the customer has a pre-set shipping and billing address" do
before do
# Load up the customer's order and give them a shipping and billing address
# This is equivalent to when the customer has ordered before and their addresses
# are pre-populated.
o = Spree::Order.last
o.ship_address = build(:address)
o.bill_address = build(:address)
o.save!
end
context "when the customer has a pre-set shipping and billing address" do
before do
# Load up the customer's order and give them a shipping and billing address
# This is equivalent to when the customer has ordered before and their addresses
# are pre-populated.
o = Spree::Order.last
o.ship_address = build(:address)
o.bill_address = build(:address)
o.save!
end
it "checks out successfully" do
visit checkout_path
checkout_as_guest
choose sm2.name
toggle_payment
choose pm1.name
it "checks out successfully" do
visit checkout_path
checkout_as_guest
choose sm2.name
toggle_payment
choose pm1.name
place_order
page.should have_content "Your order has been processed successfully"
ActionMailer::Base.deliveries.length.should == 2
end
place_order
page.should have_content "Your order has been processed successfully"
ActionMailer::Base.deliveries.length.should == 2
end
end
end

View File

@@ -8,10 +8,8 @@ feature "As a consumer I want to shop with a distributor", js: true do
describe "Viewing a distributor" do
let(:distributor) { create(:distributor_enterprise) }
let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let(:supplier) { create(:supplier_enterprise) }
let(:shipping_method) { create(:shipping_method, distributors: [distributor]) }
let(:payment_method) { create(:payment_method, distributors: [distributor]) }
let(:oc1) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) }
let(:oc2) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 3.days.from_now) }
let(:product) { create(:simple_product, supplier: supplier) }
@@ -66,10 +64,6 @@ feature "As a consumer I want to shop with a distributor", js: true do
end
it "shows products after selecting an order cycle" do
# Hubs cannot be selected without a valid shipping and payment method
shipping_method
payment_method
product.master.update_attribute(:display_name, "kitten")
product.master.update_attribute(:display_as, "rabbit")
exchange1.variants << product.master ## add product to exchange

View File

@@ -15,8 +15,8 @@ feature %q{
scenario "entering the site via a supplier's page" do
# Given a supplier with some distributed products
s = create(:supplier_enterprise)
d = create(:distributor_enterprise)
p = create(:simple_product, supplier: s) #, distributors: [d])
d = create(:distributor_enterprise, with_payment_and_shipping: true)
p = create(:simple_product, supplier: s)
oc = create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master])
# When I visit a supplier page