Split out opening payments into own context

This commit is contained in:
Rohan Mitchell
2014-08-22 14:38:44 +10:00
parent e173c69ee3
commit dd42b0c239

View File

@@ -79,53 +79,24 @@ feature "As a consumer I want to check out my cart", js: true do
end
end
before do
visit checkout_path
checkout_as_guest
toggle_payment
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
ActionMailer::Base.deliveries.clear
toggle_shipping
choose sm2.name
context "on the checkout page with payments open" do
before do
visit checkout_path
checkout_as_guest
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 "Address", with: "123 Your Face"
select "Australia", from: "Country"
select "Victoria", from: "State"
fill_in "City", with: "Melbourne"
fill_in "Postcode", with: "3066"
end
place_order
page.should have_content "Your order has been processed successfully"
ActionMailer::Base.deliveries.length.should == 1
email = ActionMailer::Base.deliveries.last
site_name = Spree::Config[:site_name]
email.subject.should include "#{site_name} Order Confirmation"
end
context "with basic details filled" do
before do
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
ActionMailer::Base.deliveries.clear
toggle_shipping
choose sm1.name
choose sm2.name
toggle_payment
choose pm1.name
toggle_details
@@ -137,52 +108,83 @@ 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"
end
toggle_shipping
check "Shipping address same as billing address?"
end
fill_in "City", with: "Melbourne"
fill_in "Postcode", with: "3066"
it "takes us to the order confirmation page when submitted with 'same as billing address' checked" do
end
place_order
page.should have_content "Your order has been processed successfully"
ActionMailer::Base.deliveries.length.should == 1
email = ActionMailer::Base.deliveries.last
site_name = Spree::Config[:site_name]
email.subject.should include "#{site_name} Order Confirmation"
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
context "with basic details filled" do
before do
toggle_shipping
choose sm1.name
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
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 "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 "takes us to the order confirmation page when submitted with 'same as billing address' checked" do
place_order
page.should have_content "Payment could not be processed, please check the details you entered"
page.should have_content "Your order has been processed successfully"
end
# Does not show duplicate shipping fee
visit checkout_path
page.all("th", text: "Shipping").count.should == 1
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
end
end
end