Fix bug preventing the addition of tickets via Event Attendee Dashboard

This commit is contained in:
Eric Schultz 2018-03-30 13:30:45 -05:00
parent 44ce86901b
commit 70b4e7bf76
3 changed files with 28 additions and 21 deletions

View file

@ -10,6 +10,7 @@ class TicketsController < ApplicationController
def create
authenticate_event_editor! if params[:kind] == 'offsite'
render_json do
params[:current_user] = current_user
InsertTickets.create(params)
end
end

View file

@ -31,7 +31,7 @@ module InsertTickets
ParamValidation.new(t, {quantity: {is_integer: true, required: true, min: 1}, ticket_level_id: {is_reference: true, required: true}})
}
ParamValidation.new(data[:offsite_payment], {kind: {included_in: %w(cash check)}}) if data[:offsite_payment]
ParamValidation.new(data[:offsite_payment], {kind: {included_in: %w(cash check)}}) if data[:offsite_payment] && !data[:offsite_payment][:kind].blank?
entities = RetrieveActiveRecordItems.retrieve_from_keys(data, {Supporter => :supporter_id, Nonprofit => :nonprofit_id, Event => :event_id})

View file

@ -380,6 +380,14 @@ describe InsertTickets do
end
it 'succeeds' do
success()
end
it 'succeeds if offsite_donation is there with empty kind' do
success({offsite_donation: {kind: nil}})
end
def success(other_elements={})
nonprofit.stripe_account_id = Stripe::Account.create()['id']
nonprofit.save!
card.stripe_customer_id = 'some other id'
@ -387,15 +395,15 @@ describe InsertTickets do
success_expectations
expect(InsertCharge).to receive(:with_stripe).with({
kind: "Ticket",
towards: event.name,
metadata: {kind: "Ticket", event_id: event.id, nonprofit_id: nonprofit.id},
statement: "Tickets #{event.name}",
amount: 1600,
nonprofit_id: nonprofit.id,
supporter_id: supporter.id,
card_id: card.id
}).and_call_original
kind: "Ticket",
towards: event.name,
metadata: {kind: "Ticket", event_id: event.id, nonprofit_id: nonprofit.id},
statement: "Tickets #{event.name}",
amount: 1600,
nonprofit_id: nonprofit.id,
supporter_id: supporter.id,
card_id: card.id
}).and_call_original
stripe_charge_id = nil
expect(Stripe::Charge).to receive(:create).with({application_fee: 66,
@ -410,7 +418,7 @@ describe InsertTickets do
a}
result = InsertTickets.create(include_valid_token.merge(event_discount_id:event_discount.id))
expected = generate_expected_tickets(
gross_amount: 1600,
{gross_amount: 1600,
payment_fee_total: 66,
payment_id: result['payment'].id,
nonprofit: nonprofit,
@ -421,21 +429,19 @@ describe InsertTickets do
event_discount_id: event_discount.id,
card: card,
tickets: [{
id: result['tickets'][0]['id'],
quantity: 1,
ticket_level_id: ticket_level.id},
{
id: result['tickets'][0]['id'],
quantity: 2,
ticket_level_id: ticket_level2.id
}])
id: result['tickets'][0]['id'],
quantity: 1,
ticket_level_id: ticket_level.id},
{
id: result['tickets'][0]['id'],
quantity: 2,
ticket_level_id: ticket_level2.id
}]}.merge(other_elements))
expect(result['payment'].attributes).to eq expected[:payment]
expect(result['charge'].attributes).to eq expected[:charge]
expect(result['tickets'].map{|i| i.attributes}[0]).to eq expected[:tickets][0]
end
end
it 'errors where kind == free and positive gross_amount' do