mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
spec/ticket: add tests for purchasing free tickets
This commit is contained in:
parent
b2f75dd907
commit
b28be23284
2 changed files with 37 additions and 2 deletions
|
|
@ -2,7 +2,8 @@ require 'spec_helper'
|
|||
|
||||
feature Registration do
|
||||
let!(:ticket) { create(:ticket) }
|
||||
let!(:conference) { create(:conference, title: 'ExampleCon', tickets: [ticket], registration_period: create(:registration_period, start_date: 3.days.ago)) }
|
||||
let!(:free_ticket) { create(:ticket, price_cents: 0) }
|
||||
let!(:conference) { create(:conference, title: 'ExampleCon', tickets: [ticket, free_ticket], registration_period: create(:registration_period, start_date: 3.days.ago)) }
|
||||
let!(:participant) { create(:user) }
|
||||
|
||||
context 'as a participant' do
|
||||
|
|
@ -87,6 +88,26 @@ feature Registration do
|
|||
expect(flash).to eq('Your card was declined. Please try again with correct credentials.')
|
||||
end
|
||||
end
|
||||
|
||||
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'
|
||||
|
||||
expect(current_path).to eq(new_conference_conference_registration_path(conference.short_title))
|
||||
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: free_ticket.id).first
|
||||
expect(purchase.quantity).to eq(5)
|
||||
expect(purchase.paid).to eq(true)
|
||||
|
||||
expect(page.has_content?("5 #{free_ticket.title} Tickets for $ 0")).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'who is registered' do
|
||||
|
|
|
|||
|
|
@ -41,7 +41,21 @@ describe TicketPurchase do
|
|||
let!(:participant) { create(:user) }
|
||||
let!(:ticket_1) { create(:ticket) }
|
||||
let!(:ticket_2) { create(:ticket) }
|
||||
let!(:conference) { create(:conference, tickets: [ticket_1, ticket_2]) }
|
||||
let!(:free_ticket) { create(:ticket) }
|
||||
let!(:conference) { create(:conference, tickets: [ticket_1, ticket_2, free_ticket]) }
|
||||
|
||||
it 'creates purchase to free ticket' do
|
||||
tickets = { free_ticket.id.to_s => '10' }
|
||||
message = TicketPurchase.purchase(conference, participant, tickets)
|
||||
purchase = TicketPurchase.where(conference_id: conference.id,
|
||||
user_id: participant.id,
|
||||
ticket_id: free_ticket.id).first
|
||||
|
||||
expect(TicketPurchase.count).to eq(1)
|
||||
expect(purchase.quantity).to eq(10)
|
||||
expect(message.blank?).to be true
|
||||
|
||||
end
|
||||
|
||||
it 'creates a purchase for one ticket' do
|
||||
tickets = { ticket_1.id.to_s => '1' }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue