diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 11f0eae004..375c49c2d3 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -64,6 +64,33 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do context 'login in as user' do let(:user) { create(:user) } + def fill_out_form + 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 + check "Save as default billing address" + within "#billing" do + fill_in "City", with: "Melbourne" + fill_in "Postcode", with: "3066" + fill_in "Address", with: "123 Your Head" + select "Australia", from: "Country" + select "Victoria", from: "State" + end + + toggle_shipping + check "Shipping address same as billing address?" + check "Save as default shipping address" + end + before do quick_login_as(user) end @@ -71,30 +98,7 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do context "with details filled out" do before do visit checkout_path - 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 - check "Save as default billing address" - within "#billing" do - fill_in "City", with: "Melbourne" - fill_in "Postcode", with: "3066" - fill_in "Address", with: "123 Your Head" - select "Australia", from: "Country" - select "Victoria", from: "State" - end - - toggle_shipping - check "Shipping address same as billing address?" - check "Save as default shipping address" + fill_out_form end it "sets user's default billing address and shipping address" do @@ -145,11 +149,13 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do month: "01", year: "2025", cc_type: "Visa", - number: "1111111111111111") + number: "1111111111111111", + payment_method_id: stripe_pm.id) } before do visit checkout_path + fill_out_form toggle_payment choose stripe_pm.name end @@ -162,6 +168,12 @@ feature "As a consumer I want to check out my cart", js: true, retry: 3 do select "Visa XXXX XXXX XXXX 1111 Exp 01/2025", from: "selected_card" page.should have_css "#secrets\\.card_number[disabled]" end + + it "allows use of a saved card" do + select "Visa XXXX XXXX XXXX 1111 Exp 01/2025", from: "selected_card" + place_order + page.should have_content "Your order has been processed successfully" + end end end diff --git a/spec/requests/stripe_connect_checkout_spec.rb b/spec/requests/stripe_connect_checkout_spec.rb index cd4ff0ed19..10ebfd1c90 100644 --- a/spec/requests/stripe_connect_checkout_spec.rb +++ b/spec/requests/stripe_connect_checkout_spec.rb @@ -25,6 +25,16 @@ describe "Submitting Stripe Connect charge requests", type: :request do order.update_attributes(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) order.reload.update_totals set_order order + + stub_request(:post, "https://sk_test_123456:@api.stripe.com/v1/customers") + .to_return(status: 200, body: JSON.generate({ id: "cus_A123", default_card: "card_XyZ456", sources: { data: [{id: "1"}] } }), headers: {}) + + stub_request(:post, "https://api.stripe.com/v1/tokens") + .to_return(status: 200, body: JSON.generate({id: "tok_123"}), headers: {}) + +# stub_request(:post, "https://sk_test_123456:@api.stripe.com/v1/charges") +# .to_return(status: 200, body: JSON.generate({id: "ch_123"}), headers: {}) + end context "when the charge request is accepted" do @@ -32,7 +42,6 @@ describe "Submitting Stripe Connect charge requests", type: :request do before do stub_request(:post, "https://sk_test_123456:@api.stripe.com/v1/charges") - .with { |request| request.body.starts_with?("card=#{token}") } .to_return(body: JSON.generate(response_mock)) end @@ -48,8 +57,7 @@ describe "Submitting Stripe Connect charge requests", type: :request do before do stub_request(:post, "https://sk_test_123456:@api.stripe.com/v1/charges") - .with { |request| request.body.starts_with?("card=#{token}") } - .to_return(body: JSON.generate(response_mock)) + .to_return(body: JSON.generate(response_mock)) end it "should not process the payment" do