Fix bug preventing the addition of tickets via Event Attendee Dashboard
This commit is contained in:
parent
44ce86901b
commit
70b4e7bf76
3 changed files with 28 additions and 21 deletions
|
@ -10,6 +10,7 @@ class TicketsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
authenticate_event_editor! if params[:kind] == 'offsite'
|
authenticate_event_editor! if params[:kind] == 'offsite'
|
||||||
render_json do
|
render_json do
|
||||||
|
params[:current_user] = current_user
|
||||||
InsertTickets.create(params)
|
InsertTickets.create(params)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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(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})
|
entities = RetrieveActiveRecordItems.retrieve_from_keys(data, {Supporter => :supporter_id, Nonprofit => :nonprofit_id, Event => :event_id})
|
||||||
|
|
||||||
|
|
|
@ -380,6 +380,14 @@ describe InsertTickets do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'succeeds' do
|
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.stripe_account_id = Stripe::Account.create()['id']
|
||||||
nonprofit.save!
|
nonprofit.save!
|
||||||
card.stripe_customer_id = 'some other id'
|
card.stripe_customer_id = 'some other id'
|
||||||
|
@ -387,15 +395,15 @@ describe InsertTickets do
|
||||||
|
|
||||||
success_expectations
|
success_expectations
|
||||||
expect(InsertCharge).to receive(:with_stripe).with({
|
expect(InsertCharge).to receive(:with_stripe).with({
|
||||||
kind: "Ticket",
|
kind: "Ticket",
|
||||||
towards: event.name,
|
towards: event.name,
|
||||||
metadata: {kind: "Ticket", event_id: event.id, nonprofit_id: nonprofit.id},
|
metadata: {kind: "Ticket", event_id: event.id, nonprofit_id: nonprofit.id},
|
||||||
statement: "Tickets #{event.name}",
|
statement: "Tickets #{event.name}",
|
||||||
amount: 1600,
|
amount: 1600,
|
||||||
nonprofit_id: nonprofit.id,
|
nonprofit_id: nonprofit.id,
|
||||||
supporter_id: supporter.id,
|
supporter_id: supporter.id,
|
||||||
card_id: card.id
|
card_id: card.id
|
||||||
}).and_call_original
|
}).and_call_original
|
||||||
|
|
||||||
stripe_charge_id = nil
|
stripe_charge_id = nil
|
||||||
expect(Stripe::Charge).to receive(:create).with({application_fee: 66,
|
expect(Stripe::Charge).to receive(:create).with({application_fee: 66,
|
||||||
|
@ -410,7 +418,7 @@ describe InsertTickets do
|
||||||
a}
|
a}
|
||||||
result = InsertTickets.create(include_valid_token.merge(event_discount_id:event_discount.id))
|
result = InsertTickets.create(include_valid_token.merge(event_discount_id:event_discount.id))
|
||||||
expected = generate_expected_tickets(
|
expected = generate_expected_tickets(
|
||||||
gross_amount: 1600,
|
{gross_amount: 1600,
|
||||||
payment_fee_total: 66,
|
payment_fee_total: 66,
|
||||||
payment_id: result['payment'].id,
|
payment_id: result['payment'].id,
|
||||||
nonprofit: nonprofit,
|
nonprofit: nonprofit,
|
||||||
|
@ -421,21 +429,19 @@ describe InsertTickets do
|
||||||
event_discount_id: event_discount.id,
|
event_discount_id: event_discount.id,
|
||||||
card: card,
|
card: card,
|
||||||
tickets: [{
|
tickets: [{
|
||||||
id: result['tickets'][0]['id'],
|
id: result['tickets'][0]['id'],
|
||||||
quantity: 1,
|
quantity: 1,
|
||||||
ticket_level_id: ticket_level.id},
|
ticket_level_id: ticket_level.id},
|
||||||
{
|
{
|
||||||
id: result['tickets'][0]['id'],
|
id: result['tickets'][0]['id'],
|
||||||
quantity: 2,
|
quantity: 2,
|
||||||
ticket_level_id: ticket_level2.id
|
ticket_level_id: ticket_level2.id
|
||||||
}])
|
}]}.merge(other_elements))
|
||||||
|
|
||||||
expect(result['payment'].attributes).to eq expected[:payment]
|
expect(result['payment'].attributes).to eq expected[:payment]
|
||||||
expect(result['charge'].attributes).to eq expected[:charge]
|
expect(result['charge'].attributes).to eq expected[:charge]
|
||||||
expect(result['tickets'].map{|i| i.attributes}[0]).to eq expected[:tickets][0]
|
expect(result['tickets'].map{|i| i.attributes}[0]).to eq expected[:tickets][0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'errors where kind == free and positive gross_amount' do
|
it 'errors where kind == free and positive gross_amount' do
|
||||||
|
|
Loading…
Reference in a new issue