2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2021-02-23 18:17:45 -08:00
|
|
|
feature Registration, feature: true, js: true do
|
2014-08-28 15:21:05 +02:00
|
|
|
let!(:ticket) { create(:ticket) }
|
2016-08-18 23:23:38 +05:30
|
|
|
let!(:free_ticket) { create(:ticket, price_cents: 0) }
|
2017-08-12 03:01:36 +05:30
|
|
|
let!(:first_registration_ticket) { create(:registration_ticket, price_cents: 0) }
|
|
|
|
|
let!(:second_registration_ticket) { create(:registration_ticket, price_cents: 0) }
|
2021-03-10 16:17:34 -08:00
|
|
|
let!(:third_registration_ticket) { create(:registration_ticket, price_cents: 2000) }
|
2021-03-04 22:05:55 -08:00
|
|
|
let!(:conference) { create(:conference, title: 'ExampleCon', tickets: [ticket, free_ticket, first_registration_ticket, second_registration_ticket, third_registration_ticket], registration_period: create(:registration_period, start_date: 3.days.ago)) }
|
2014-08-28 15:21:05 +02:00
|
|
|
let!(:participant) { create(:user) }
|
|
|
|
|
|
2021-03-10 16:20:01 -08:00
|
|
|
def make_stripe_purchase(card_number = '4242424242424242')
|
2021-03-10 03:30:22 -08:00
|
|
|
find('.stripe-button-el').click
|
|
|
|
|
|
|
|
|
|
stripe_iframe = all('iframe[name=stripe_checkout_app]').last
|
|
|
|
|
sleep(5)
|
|
|
|
|
Capybara.within_frame stripe_iframe do
|
2021-03-10 16:17:34 -08:00
|
|
|
expect(page).to have_content(:all, "#{ENV['OSEM_NAME']} tickets")
|
2021-03-10 03:30:22 -08:00
|
|
|
fill_in 'Card number', with: card_number
|
|
|
|
|
fill_in 'Expiry', with: '08/22'
|
|
|
|
|
fill_in 'CVC', with: '123'
|
|
|
|
|
click_button '$20.00'
|
|
|
|
|
sleep(20)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def make_failed_stripe_purchase
|
|
|
|
|
make_stripe_purchase('4000000000000341')
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
context 'as a participant' do
|
|
|
|
|
before(:each) do
|
|
|
|
|
sign_in participant
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
|
sign_out
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'who is not registered' do
|
|
|
|
|
|
2021-03-10 03:30:22 -08:00
|
|
|
scenario 'purchases and pays for a ticket succcessfully' do
|
2014-08-28 15:21:05 +02:00
|
|
|
visit root_path
|
2014-12-05 16:04:34 +01:00
|
|
|
click_link 'Register'
|
|
|
|
|
|
2016-07-05 00:10:18 +05:30
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
2014-12-05 16:04:34 +01:00
|
|
|
click_button 'Register'
|
2014-08-28 15:21:05 +02:00
|
|
|
|
|
|
|
|
fill_in "tickets__#{ticket.id}", with: '2'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
2016-07-27 19:44:32 +05:30
|
|
|
click_button 'Continue'
|
2018-10-25 16:16:56 -07:00
|
|
|
page.find('#flash')
|
2016-07-27 19:44:32 +05:30
|
|
|
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
|
2016-08-16 00:46:11 +05:30
|
|
|
expect(flash).to eq('Please pay here to get tickets.')
|
2014-08-28 15:21:05 +02:00
|
|
|
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
|
|
|
|
|
expect(purchase.quantity).to eq(2)
|
2016-08-16 00:46:11 +05:30
|
|
|
|
2021-03-10 03:30:22 -08:00
|
|
|
if ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.secrets.stripe_publishable_key
|
|
|
|
|
make_stripe_purchase
|
|
|
|
|
# expect(current_path).to eq(conference_conference_registration_path(conference.short_title))
|
|
|
|
|
expect(current_path).to eq(conference_physical_tickets_path(conference.short_title))
|
|
|
|
|
expect(page).to have_content 'Your ticket is booked successfully.'
|
2016-08-16 00:46:11 +05:30
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'purchases ticket but payment fails', feature: true, js: true do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
fill_in "tickets__#{ticket.id}", with: '2'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_button 'Continue'
|
2018-10-25 16:16:56 -07:00
|
|
|
page.find('#flash')
|
2016-08-16 00:46:11 +05:30
|
|
|
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
|
|
|
|
|
expect(flash).to eq('Please pay here to get tickets.')
|
|
|
|
|
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
|
|
|
|
|
expect(purchase.quantity).to eq(2)
|
|
|
|
|
|
2021-03-10 03:30:22 -08:00
|
|
|
if ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.secrets.stripe_publishable_key
|
|
|
|
|
make_failed_stripe_purchase
|
2018-10-25 16:16:56 -07:00
|
|
|
page.find('#flash')
|
2016-08-17 23:57:40 +05:30
|
|
|
expect(current_path).to eq(conference_payments_path(conference.short_title))
|
|
|
|
|
expect(flash).to eq('Your card was declined. Please try again with correct credentials.')
|
2016-08-16 00:46:11 +05:30
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
2016-08-18 23:23:38 +05:30
|
|
|
|
|
|
|
|
scenario 'purchases free tickets' do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
fill_in "tickets__#{free_ticket.id}", with: '5'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_button 'Continue'
|
|
|
|
|
|
2017-09-26 21:43:18 +05:30
|
|
|
expect(current_path).to eq(conference_physical_tickets_path(conference.short_title))
|
2016-08-18 23:23:38 +05:30
|
|
|
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: free_ticket.id).first
|
|
|
|
|
expect(purchase.quantity).to eq(5)
|
2016-08-19 00:51:49 +05:30
|
|
|
expect(purchase.paid).to be true
|
2016-08-18 23:23:38 +05:30
|
|
|
end
|
2017-08-12 03:01:36 +05:30
|
|
|
|
2021-03-04 22:05:55 -08:00
|
|
|
scenario 'purchases a free registartion ticket' do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
fill_in "tickets__#{first_registration_ticket.id}", with: '1'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_button 'Continue'
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
expect(flash).to eq('Thanks! Your ticket is booked successfully. Please register for the conference.')
|
|
|
|
|
|
|
|
|
|
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: first_registration_ticket.id).first
|
|
|
|
|
expect(purchase.quantity).to eq(1)
|
|
|
|
|
expect(purchase.paid).to be true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'purchases a non-free registartion ticket' do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
fill_in "tickets__#{third_registration_ticket.id}", with: '1'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_button 'Continue'
|
|
|
|
|
page.find('#flash')
|
|
|
|
|
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
|
|
|
|
|
expect(flash).to eq('Please pay here to get tickets.')
|
|
|
|
|
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: third_registration_ticket.id).first
|
|
|
|
|
expect(purchase.quantity).to eq(1)
|
|
|
|
|
|
2021-03-10 16:17:34 -08:00
|
|
|
if ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.secrets.stripe_publishable_key
|
|
|
|
|
make_stripe_purchase
|
2021-03-04 22:05:55 -08:00
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
2021-03-10 16:17:34 -08:00
|
|
|
expect(page).to have_content 'Your ticket is booked successfully.'
|
2021-03-04 22:05:55 -08:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-12 03:01:36 +05:30
|
|
|
scenario 'purchases more than one registration tickets of a single type' do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
fill_in "tickets__#{first_registration_ticket.id}", with: '5'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_button 'Continue'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'purchases one registration ticket of a different types' do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
fill_in "tickets__#{first_registration_ticket.id}", with: '1'
|
|
|
|
|
fill_in "tickets__#{second_registration_ticket.id}", with: '1'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_button 'Continue'
|
2018-10-25 16:16:56 -07:00
|
|
|
page.find('#flash')
|
2017-08-12 03:01:36 +05:30
|
|
|
expect(flash).to eq('Oops, something went wrong with your purchase! You cannot buy more than one registration tickets.')
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
2016-09-26 20:57:11 +05:30
|
|
|
|
|
|
|
|
context 'who is registered' do
|
|
|
|
|
|
2021-02-23 18:17:45 -08:00
|
|
|
scenario 'unregisters from conference, but ticket purchases dont delete' do
|
2021-03-10 16:36:09 -08:00
|
|
|
skip('SNAPCON: Investigate failure on the unregister button')
|
2016-09-26 20:57:11 +05:30
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
fill_in "tickets__#{ticket.id}", with: '2'
|
|
|
|
|
expect(current_path).to eq(conference_tickets_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_button 'Continue'
|
2018-10-25 16:16:56 -07:00
|
|
|
page.find('#flash')
|
2016-09-26 20:57:11 +05:30
|
|
|
expect(current_path).to eq(new_conference_payment_path(conference.short_title))
|
|
|
|
|
expect(flash).to eq('Please pay here to get tickets.')
|
|
|
|
|
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
|
|
|
|
|
expect(purchase.quantity).to eq(2)
|
|
|
|
|
|
2021-03-10 03:30:22 -08:00
|
|
|
if ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.secrets.stripe_publishable_key
|
|
|
|
|
make_stripe_purchase
|
|
|
|
|
# expect(current_path).to eq(conference_conference_registration_path(conference.short_title))
|
|
|
|
|
expect(current_path).to eq(conference_physical_tickets_path(conference.short_title))
|
|
|
|
|
expect(page).to have_content 'Your ticket is booked successfully.'
|
2016-09-26 20:57:11 +05:30
|
|
|
|
|
|
|
|
click_button 'Unregister'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
|
|
|
|
|
expect(purchase.quantity).to eq(2)
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
end
|