improve tests[WIP]

This commit is contained in:
Rishabh Saxena 2016-06-18 18:33:36 +05:30
parent 809e2b7156
commit ee71456060
3 changed files with 33 additions and 25 deletions

View file

@ -40,9 +40,9 @@ describe ConferenceRegistrationsController, type: :controller do
get :show, conference_id: conference.short_title
end
it 'assigns price of purchased tickets to total_price and purchased tickets to tickets' do
expect(assigns(:total_price)).to eq Money.new(10000, 'USD')
expect(assigns(:tickets)).to match_array [@purchased_ticket]
it 'does not assign price of purchased tickets to total_price and purchased tickets to tickets without payment' do
expect(assigns(:total_price)).to eq Money.new(0, 'USD')
expect(assigns(:tickets)).not_to match_array [@purchased_ticket]
end
end

View file

@ -26,27 +26,35 @@ feature Registration do
fill_in "tickets__#{ticket.id}", with: '2'
expect(current_path).to eq(conference_tickets_path(conference.short_title))
click_button 'Support'
click_button 'Continue'
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: ticket.id).first
expect(purchase.quantity).to eq(2)
expect(current_path).to eq(conference_conference_registration_path(conference.short_title))
expect(current_path).to eq(new_conference_payment_path)
expect(flash).
to eq("Thank you for supporting #{conference.title} by purchasing a ticket.")
to eq('Please pay here to purchase tickets.')
fill_in 'first_name', with: 'foo'
fill_in 'last_name', with: 'bar'
fill_in 'expiration_year', Date.current.year + 2
fill_in 'card_verification_value', with: '123'
fill_in 'credit_card_number', with: '4242424242424242'
click_button 'Charge Card'
payment = Payment.where(user_id: participant, conference_id: conference.id).first
expect(payment.amount).to eq(20)
expect(payment.status).to eq(1)
expect(payment.first_name).to eq('foo')
expect(payment.first_name).to eq('bar')
expect(payment.last4).not_to be_empty
expect(payment.authorization_code).not_to be_empty
expect(current_path).to eq(conference_conference_registrations_path(conference.short_title))
expect(flash).
to eq('Thanks! You have purchased your tickets successfully.')
expect(page.has_content?("2 #{ticket.title} Tickets for 10")).to be true
end
scenario 'deletes a purchased ticket', feature: true, js: true do
create(:registration, conference: conference, user: participant)
create(:ticket_purchase, conference: conference, user: participant, ticket: ticket, quantity: 4)
visit conference_conference_registration_path(conference.short_title)
expect(page.has_content?("4 #{ticket.title} Tickets for 10")).to be true
click_link "ticket-#{ticket.id}-delete"
expect(flash).to eq('Ticket successfully deleted.')
expect(TicketPurchase.count).to eq(0)
end
end
end
end

View file

@ -88,11 +88,11 @@ describe Ticket do
user: user,
ticket: ticket,
quantity: 20)
expect(ticket.quantity_bought_by(user)).to eq(20)
expect(ticket.quantity_bought_by(user, 'f')).to eq(20)
end
it 'returns zero if the user has not bought this ticket' do
expect(ticket.quantity_bought_by(user)).to eq(0)
expect(ticket.quantity_bought_by(user, 'f')).to eq(0)
end
end
@ -102,11 +102,11 @@ describe Ticket do
user: user,
ticket: ticket,
quantity: 20)
expect(ticket.total_price(user)).to eq(Money.new(100000, 'USD'))
expect(ticket.total_price(user, 'f')).to eq(Money.new(100000, 'USD'))
end
it 'returns zero if the user has not bought this ticket' do
expect(ticket.total_price(user)).to eq(Money.new(0, 'USD'))
expect(ticket.total_price(user, 'f')).to eq(Money.new(0, 'USD'))
end
end
@ -116,7 +116,7 @@ describe Ticket do
describe 'user has bought' do
context 'no tickets' do
it 'returns zero' do
expect(Ticket.total_price(conference, user)).to eq(Money.new(0, 'USD'))
expect(Ticket.total_price(conference, user, 'f')).to eq(Money.new(0, 'USD'))
end
end
@ -126,7 +126,7 @@ describe Ticket do
end
it 'returns the correct total price' do
expect(Ticket.total_price(conference, user)).to eq(Money.new(100000, 'USD'))
expect(Ticket.total_price(conference, user, 'f')).to eq(Money.new(100000, 'USD'))
end
end
@ -138,7 +138,7 @@ describe Ticket do
it 'returns the correct total price' do
total_price = Money.new(200000, 'USD')
expect(Ticket.total_price(conference, user)).to eq(total_price)
expect(Ticket.total_price(conference, user, 'f')).to eq(total_price)
end
end
end