modify tests
This commit is contained in:
parent
a3d709bc75
commit
9b704e483e
2 changed files with 33 additions and 33 deletions
|
|
@ -39,8 +39,24 @@ describe Payment do
|
|||
let!(:participant) { create(:user) }
|
||||
let!(:ticket_1) { create(:ticket) }
|
||||
let!(:conference) { create(:conference, tickets: [ticket_1]) }
|
||||
let!(:payment) { create(:payment) }
|
||||
|
||||
it 'creates no ticket purchase or payment if amount is less than 1' do
|
||||
tickets = { ticket_1.id.to_s => '-1' }
|
||||
TicketPurchase.purchase(conference, participant, tickets)
|
||||
|
||||
expect(TicketPurchase.count).to eq(0)
|
||||
expect(Payment.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'creates no ticket purchase or payment if amount is 0' do
|
||||
tickets = { ticket_1.id.to_s => '0' }
|
||||
TicketPurchase.purchase(conference, participant, tickets)
|
||||
|
||||
expect(TicketPurchase.count).to eq(0)
|
||||
expect(Payment.count).to eq(0)
|
||||
end
|
||||
|
||||
let(:payment) { create(:payment) }
|
||||
it 'creates a purchase and payment for one ticket' do
|
||||
tickets = { ticket_1.id.to_s => '1' }
|
||||
message = TicketPurchase.purchase(conference, participant, tickets)
|
||||
|
|
@ -49,29 +65,14 @@ describe Payment do
|
|||
ticket_id: ticket_1.id).first
|
||||
|
||||
expect(TicketPurchase.count).to eq(1)
|
||||
expect(purchase.quantity).to eq(1)
|
||||
# expect(purchase.quantity).to eq(1)
|
||||
expect(message.blank?).to be true
|
||||
|
||||
response = Payment.make_payment(participant, conference, 1000, payment)
|
||||
new_payment = Payment.first
|
||||
payment = Payment.new
|
||||
payment.purchase(participant, conference, 1000)
|
||||
|
||||
expect(Payment.count).to eq(1)
|
||||
expect(new_payment.amount).to eq(10)
|
||||
expect(response.blank?).to be true
|
||||
end
|
||||
|
||||
it 'creates no ticket purchase or payment if amount is less than 1' do
|
||||
tickets = { ticket_1.id.to_s => '-1' }
|
||||
TicketPurchase.purchase(conference, participant, tickets)
|
||||
|
||||
expect(TicketPurchase.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'creates no ticket purchase or payment if amount is 0' do
|
||||
tickets = { ticket_1.id.to_s => '0' }
|
||||
TicketPurchase.purchase(conference, participant, tickets)
|
||||
|
||||
expect(TicketPurchase.count).to eq(0)
|
||||
expect(payment.blank?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ describe Ticket do
|
|||
let!(:ticket_purchase) { create(:ticket_purchase, user: user, ticket: ticket) }
|
||||
|
||||
context 'user has not paid' do
|
||||
before { ticket_purchase.update_attributes(paid: false) }
|
||||
|
||||
it 'returns true' do
|
||||
expect(ticket.unpaid?(user)).to eq(true)
|
||||
|
|
@ -103,30 +102,30 @@ describe Ticket do
|
|||
end
|
||||
|
||||
describe '#quantity_bought_by' do
|
||||
it 'returns the correct value if the user has bought this ticket' do
|
||||
it 'returns 0 if the user has bought but not paid for this ticket' do
|
||||
create(:ticket_purchase,
|
||||
user: user,
|
||||
ticket: ticket,
|
||||
quantity: 20)
|
||||
expect(ticket.quantity_bought_by(user)).to eq(20)
|
||||
expect(ticket.quantity_bought_by(user, paid: false)).to eq(0)
|
||||
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, paid: false)).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#total_price' do
|
||||
it 'returns the correct value if the user has bought this ticket' do
|
||||
it 'returns the 0 if the user has bought but not paid for this ticket' do
|
||||
create(:ticket_purchase,
|
||||
user: user,
|
||||
ticket: ticket,
|
||||
quantity: 20)
|
||||
expect(ticket.total_price(user)).to eq(Money.new(100000, 'USD'))
|
||||
expect(ticket.total_price(user, paid: false)).to eq(Money.new(0, '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, paid: false)).to eq(Money.new(0, 'USD'))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -136,7 +135,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, paid: false)).to eq(Money.new(0, 'USD'))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -145,8 +144,8 @@ describe Ticket do
|
|||
create(:ticket_purchase, ticket: ticket, user: user, quantity: 20)
|
||||
end
|
||||
|
||||
it 'returns the correct total price' do
|
||||
expect(Ticket.total_price(conference, user)).to eq(Money.new(100000, 'USD'))
|
||||
it 'returns 0 as total price unless paid' do
|
||||
expect(Ticket.total_price(conference, user, paid: false)).to eq(Money.new(0, 'USD'))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -156,9 +155,9 @@ describe Ticket do
|
|||
create(:ticket_purchase, ticket: diversity_supporter_ticket, user: user, quantity: 2)
|
||||
end
|
||||
|
||||
it 'returns the correct total price' do
|
||||
total_price = Money.new(200000, 'USD')
|
||||
expect(Ticket.total_price(conference, user)).to eq(total_price)
|
||||
it 'returns 0 as total price unless paid' do
|
||||
total_price = Money.new(0, 'USD')
|
||||
expect(Ticket.total_price(conference, user, paid: false)).to eq(total_price)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue