Skip to content

Commit

Permalink
Dedupe shared code in checkout specs
Browse files Browse the repository at this point in the history
  • Loading branch information
brchristian committed Jan 25, 2021
1 parent df1dc42 commit 78b5e66
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 102 deletions.
57 changes: 57 additions & 0 deletions lib/solidus_stripe/testing_support/stripe_checkout_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

module StripeCheckoutHelper
def initialize_checkout
FactoryBot.create(:store)
zone.members << Spree::ZoneMember.create!(zoneable: country)
FactoryBot.create(:free_shipping_method)

Spree::PaymentMethod::StripeCreditCard.create!(
name: "Stripe",
preferred_secret_key: "sk_test_VCZnDv3GLU15TRvn8i2EsaAN",
preferred_publishable_key: "pk_test_Cuf0PNtiAkkMpTVC2gwYDMIg",
preferred_v3_elements: preferred_v3_elements,
preferred_v3_intents: preferred_v3_intents
)

FactoryBot.create(:product, name: "DL-44")

visit spree.root_path
click_link "DL-44"
click_button "Add To Cart"

expect(page).to have_current_path("/cart")
click_button "Checkout"

expect(page).to have_current_path("/checkout/registration")
click_link "Create a new account"
within("#new_spree_user") do
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "superStrongPassword"
fill_in "Password Confirmation", with: "superStrongPassword"
end
click_button "Create"

# Address
expect(page).to have_current_path("/checkout/address")

within("#billing") do
fill_in_name
fill_in "Street Address", with: "YT-1300"
fill_in "City", with: "Mos Eisley"
select "United States of America", from: "Country"
select country.states.first.name, from: "order_bill_address_attributes_state_id"
fill_in "Zip", with: "12010"
fill_in "Phone", with: "(555) 555-5555"
end
click_on "Save and Continue"

# Delivery
expect(page).to have_current_path("/checkout/delivery")
expect(page).to have_content("UPS Ground")
click_on "Save and Continue"

# Payment
expect(page).to have_current_path("/checkout/payment")
end
end
52 changes: 1 addition & 51 deletions spec/features/stripe_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,7 @@
let(:card_3d_secure) { "4000 0025 0000 3155" }

before do
FactoryBot.create(:store)
zone.members << Spree::ZoneMember.create!(zoneable: country)
FactoryBot.create(:free_shipping_method)

Spree::PaymentMethod::StripeCreditCard.create!(
name: "Stripe",
preferred_secret_key: "sk_test_VCZnDv3GLU15TRvn8i2EsaAN",
preferred_publishable_key: "pk_test_Cuf0PNtiAkkMpTVC2gwYDMIg",
preferred_v3_elements: preferred_v3_elements,
preferred_v3_intents: preferred_v3_intents
)

FactoryBot.create(:product, name: "DL-44")

visit spree.root_path
click_link "DL-44"
click_button "Add To Cart"

expect(page).to have_current_path("/cart")
click_button "Checkout"

expect(page).to have_current_path("/checkout/registration")
click_link "Create a new account"
within("#new_spree_user") do
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "superStrongPassword"
fill_in "Password Confirmation", with: "superStrongPassword"
end
click_button "Create"

# Address
expect(page).to have_current_path("/checkout/address")

within("#billing") do
fill_in_name
fill_in "Street Address", with: "YT-1300"
fill_in "City", with: "Mos Eisley"
select "United States of America", from: "Country"
select country.states.first.name, from: "order_bill_address_attributes_state_id"
fill_in "Zip", with: "12010"
fill_in "Phone", with: "(555) 555-5555"
end
click_on "Save and Continue"

# Delivery
expect(page).to have_current_path("/checkout/delivery")
expect(page).to have_content("UPS Ground")
click_on "Save and Continue"

# Payment
expect(page).to have_current_path("/checkout/payment")
initialize_checkout
end

# This will fetch a token from Stripe.com and then pass that to the webserver.
Expand Down
51 changes: 1 addition & 50 deletions spec/features/stripe_customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,8 @@
let(:country) { FactoryBot.create(:country) }

before do
FactoryBot.create(:store)
zone.members << Spree::ZoneMember.create!(zoneable: country)
FactoryBot.create(:free_shipping_method)
initialize_checkout

Spree::PaymentMethod::StripeCreditCard.create!(
name: "Stripe",
preferred_secret_key: "sk_test_VCZnDv3GLU15TRvn8i2EsaAN",
preferred_publishable_key: "pk_test_Cuf0PNtiAkkMpTVC2gwYDMIg",
preferred_v3_elements: preferred_v3_elements,
preferred_v3_intents: preferred_v3_intents
)

FactoryBot.create(:product, name: "DL-44")

visit spree.root_path
click_link "DL-44"
click_button "Add To Cart"

expect(page).to have_current_path("/cart")
click_button "Checkout"

expect(page).to have_current_path("/checkout/registration")
click_link "Create a new account"
within("#new_spree_user") do
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "superStrongPassword"
fill_in "Password Confirmation", with: "superStrongPassword"
end
click_button "Create"

# Address
expect(page).to have_current_path("/checkout/address")

within("#billing") do
fill_in_name
fill_in "Street Address", with: "YT-1300"
fill_in "City", with: "Mos Eisley"
select "United States of America", from: "Country"
select country.states.first.name, from: "order_bill_address_attributes_state_id"
fill_in "Zip", with: "12010"
fill_in "Phone", with: "(555) 555-5555"
end
click_on "Save and Continue"

# Delivery
expect(page).to have_current_path("/checkout/delivery")
expect(page).to have_content("UPS Ground")
click_on "Save and Continue"

# Payment
expect(page).to have_current_path("/checkout/payment")
fill_in_card
click_button "Save and Continue"

Expand Down
4 changes: 3 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
# Requires factories defined in lib/solidus_stripe/testing_support/factories.rb
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusStripe::Engine)

# Requires card input helper defined in lib/solidus_stripe/testing_support/card_input_helper.rb
# Requires helpers defined in lib/solidus_stripe/testing_support
require 'solidus_stripe/testing_support/card_input_helper'
require 'solidus_stripe/testing_support/stripe_checkout_helper'

RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.use_transactional_fixtures = false

config.include SolidusAddressNameHelper, type: :feature
config.include SolidusCardInputHelper, type: :feature
config.include StripeCheckoutHelper, type: :feature

if Spree.solidus_gem_version < Gem::Version.new('2.11')
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
Expand Down

0 comments on commit 78b5e66

Please sign in to comment.