2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe QueryTicketLevels do
|
|
|
|
include_context :shared_donation_charge_context
|
|
|
|
describe '.gross_amount_from_tickets' do
|
|
|
|
it 'handles free tickets only properly' do
|
2019-07-30 21:29:24 +00:00
|
|
|
result = QueryTicketLevels.gross_amount_from_tickets(['ticket_level_id' => free_ticket_level.id, 'quantity' => 5], nil)
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(result).to eq 0
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles nonfree tickets only properly' do
|
2019-07-30 21:29:24 +00:00
|
|
|
result = QueryTicketLevels.gross_amount_from_tickets(['ticket_level_id' => ticket_level.id, 'quantity' => 5], nil)
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(result).to eq 2000
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles mix of tickets properly' do
|
|
|
|
result = QueryTicketLevels.gross_amount_from_tickets(
|
2019-07-30 21:29:24 +00:00
|
|
|
[{ 'ticket_level_id' => ticket_level.id, 'quantity' => 5 },
|
|
|
|
{ 'ticket_level_id' => ticket_level2.id, 'quantity' => 2 },
|
|
|
|
{ 'ticket_level_id' => free_ticket_level.id, 'quantity' => 4000 }], nil
|
|
|
|
)
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(result).to eq 3000
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'handles mix of tickets properly with discount code properly' do
|
|
|
|
result = QueryTicketLevels.gross_amount_from_tickets(
|
2019-07-30 21:29:24 +00:00
|
|
|
[{ 'ticket_level_id' => ticket_level.id, 'quantity' => 5 },
|
|
|
|
{ 'ticket_level_id' => ticket_level2.id, 'quantity' => 2 },
|
|
|
|
{ 'ticket_level_id' => free_ticket_level.id, 'quantity' => 4000 }], event_discount.id
|
|
|
|
)
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(result).to eq 2400
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.verify_tickets_available' do
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:ticket_level_1) { force_create(:ticket_level, limit: 3) }
|
|
|
|
let(:ticket_level_2) { force_create(:ticket_level, limit: 2) }
|
|
|
|
let(:tickets) do
|
|
|
|
[
|
2018-03-25 17:30:42 +00:00
|
|
|
force_create(:ticket, ticket_level: ticket_level_1, quantity: 1),
|
|
|
|
force_create(:ticket, ticket_level: ticket_level_1, quantity: 1)
|
2019-07-30 21:29:24 +00:00
|
|
|
]
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
it 'fails when ticket level is too many' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect do
|
|
|
|
QueryTicketLevels.verify_tickets_available([
|
|
|
|
{ ticket_level_id: ticket_level_1.id, quantity: 50 },
|
|
|
|
{ ticket_level_id: ticket_level_2.id, quantity: 1 }
|
|
|
|
])
|
|
|
|
end .to raise_error(NotEnoughQuantityError)
|
|
|
|
expect do
|
|
|
|
QueryTicketLevels.verify_tickets_available([
|
|
|
|
{ ticket_level_id: ticket_level_2.id, quantity: 3 }
|
|
|
|
])
|
|
|
|
end .to raise_error(NotEnoughQuantityError)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows when a full item is at 0 and other is acceptable' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect do
|
|
|
|
QueryTicketLevels.verify_tickets_available([
|
|
|
|
{ ticket_level_id: ticket_level_1.id, quantity: 0 },
|
|
|
|
{ ticket_level_id: ticket_level_2.id, quantity: 2 }
|
|
|
|
])
|
|
|
|
end .to_not raise_error
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows when only acceptable are passed ' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect do
|
|
|
|
QueryTicketLevels.verify_tickets_available([
|
|
|
|
{ ticket_level_id: ticket_level_2.id, quantity: 2 }
|
|
|
|
])
|
|
|
|
end .to_not raise_error
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|