module Workarea::Storefront::SystemTest

Public Instance Methods

add_product_to_cart() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 69
def add_product_to_cart
  product = Catalog::Product.find('INT_PRODUCT')
  visit storefront.product_path(product)
  click_button t('workarea.storefront.products.add_to_cart')
end
add_user_data() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 33
def add_user_data
  user = User.find_by_email('bcrouse@workarea.com')

  user.auto_save_shipping_address(
    first_name: 'Ben',
    last_name: 'Crouse',
    street: '22 S. 3rd St.',
    city: 'Philadelphia',
    region: 'PA',
    postal_code: '19106',
    country: 'US',
    phone_number: '2159251800'
  )

  user.auto_save_billing_address(
    first_name: 'Ben',
    last_name: 'Crouse',
    street: '1019 S. 47th St.',
    city: 'Philadelphia',
    region: 'PA',
    postal_code: '19143',
    country: 'US',
    phone_number: '2159251800'
  )

  profile = Payment::Profile.lookup(PaymentReference.new(user))
  profile.credit_cards.create!(
    first_name: 'Ben',
    last_name: 'Crouse',
    number: '1',
    month: 1,
    year: Time.current.year + 1,
    cvv: '999'
  )
end
create_supporting_data() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 9
def create_supporting_data
  create_tax_category(
    name: 'Sales Tax',
    code: '001',
    rates: [{ percentage: 0.07, country: 'US', region: 'PA' }]
  )

  create_shipping_service(
    name: 'Ground',
    tax_code: '001',
    rates: [{ price: 7.to_m }]
  )

  create_inventory(id: 'SKU', policy: 'standard', available: 5)

  @product = create_product(
    id: 'INT_PRODUCT',
    name: 'Integration Product',
    variants: [{ sku: 'SKU',  tax_code: '001', regular: 5.to_m }]
  )

  create_user(email: 'bcrouse@workarea.com', password: 'W3bl1nc!')
end
disable_analytics_dom_events() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 141
def disable_analytics_dom_events
  page.execute_script('WORKAREA.analytics.disableDomEvents();')
end
fill_in_billing_address() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 121
def fill_in_billing_address
  fill_in 'billing_address[first_name]',   with: 'Ben'
  fill_in 'billing_address[last_name]',    with: 'Crouse'
  fill_in 'billing_address[street]',       with: '1019 S. 47th St.'
  fill_in 'billing_address[city]',         with: 'Philadelphia'

  if page.has_field?('billing_address[region]')
    fill_in 'billing_address[region]', with: 'PA'
  else
    select 'Pennsylvania', from: 'billing_address_region_select'
  end

  fill_in 'billing_address[postal_code]',  with: '19143'
  fill_in 'billing_address[phone_number]', with: '2159251800'
end
fill_in_credit_card() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 114
def fill_in_credit_card
  fill_in 'credit_card[number]', with: '1'
  next_year = (Time.current.year + 1).to_s
  select next_year, from: 'credit_card[year]'
  fill_in 'credit_card[cvv]', with: '999'
end
fill_in_email() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 90
def fill_in_email
  fill_in 'email', with: 'bcrouse-new-account@workarea.com'
end
fill_in_new_card_cvv() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 110
def fill_in_new_card_cvv
  fill_in 'cvv[new_card]', with: '999'
end
fill_in_shipping_address() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 94
def fill_in_shipping_address
  fill_in 'shipping_address[first_name]',   with: 'Ben'
  fill_in 'shipping_address[last_name]',    with: 'Crouse'
  fill_in 'shipping_address[street]',       with: '22 S. 3rd St.'
  fill_in 'shipping_address[city]',         with: 'Philadelphia'

  if page.has_field?('shipping_address[region]')
    fill_in 'shipping_address[region]', with: 'PA'
  else
    select 'Pennsylvania', from: 'shipping_address_region_select'
  end

  fill_in 'shipping_address[postal_code]',  with: '19106'
  fill_in 'shipping_address[phone_number]', with: '2159251800'
end
find_analytics_events(for_event: nil) click to toggle source
# File lib/workarea/storefront/system_test.rb, line 145
def find_analytics_events(for_event: nil)
  all_events = page.evaluate_script('WORKAREA.analytics.events')

  if for_event.blank?
    all_events
  else
    all_events.select { |e| e['name'] == for_event }
  end
end
select_shipping_service() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 137
def select_shipping_service
  choose 'Ground'
end
setup_checkout_specs() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 4
def setup_checkout_specs
  create_supporting_data
  add_product_to_cart
end
start_guest_checkout() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 75
def start_guest_checkout
  visit storefront.checkout_path
end
start_user_checkout() click to toggle source
# File lib/workarea/storefront/system_test.rb, line 79
def start_user_checkout
  visit storefront.checkout_path
  click_link t('workarea.storefront.checkouts.login_title')

  within '#login_form' do
    fill_in 'email', with: 'bcrouse@workarea.com'
    fill_in 'password', with: 'W3bl1nc!'
    click_button t('workarea.storefront.users.login')
  end
end