Skip to content

Commit ac2980c

Browse files
committed
add some tests for payment
1 parent 77660b0 commit ac2980c

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

app/models/currency_conversion.rb

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def self.convert_currency(conference, amount, from_currency, to_currency)
3131
if conversion
3232
Money.add_rate(from_currency, to_currency, conversion.rate)
3333
amount.exchange_to(to_currency)
34+
elsif from_currency == to_currency
35+
amount
3436
else
3537
Money.from_amount(-1, 'USD')
3638
end

spec/features/ticket_purchases_spec.rb

+23
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,29 @@ def make_failed_stripe_purchase
226226
select 'GBP', from: 'currency_selector'
227227
expect(page).to have_content('£')
228228
end
229+
230+
it 'buys a ticket in EUR' do
231+
232+
select 'EUR', from: 'currency_selector'
233+
fill_in "tickets__#{third_registration_ticket.id}", with: '1'
234+
expect(page).to have_current_path(conference_tickets_path(conference.short_title), ignore_query: true)
235+
click_button 'Continue'
236+
page.find('#flash')
237+
expect(page).to have_current_path(new_conference_payment_path(conference.short_title), ignore_query: true)
238+
expect(flash).to eq('Please pay here to get tickets.')
239+
purchase = TicketPurchase.where(user_id: participant.id, ticket_id: third_registration_ticket.id).first
240+
expect(purchase.quantity).to eq(1)
241+
expect(purchase.currency).to eq('EUR')
242+
expect(purchase.amount_paid).to eq(17.80)
243+
244+
if ENV['STRIPE_PUBLISHABLE_KEY'] || Rails.application.secrets.stripe_publishable_key
245+
make_stripe_purchase
246+
expect(page).to have_current_path(new_conference_conference_registration_path(conference.short_title),
247+
ignore_query: true)
248+
expect(page).to have_content 'Your ticket is booked successfully.'
249+
end
250+
end
251+
229252
end
230253

231254
context 'who is registered' do

spec/models/payment_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
it 'assigns authorization_code' do
8181
expect(payment.authorization_code).to eq('test_ch_3')
8282
end
83+
84+
it 'assigns currency' do
85+
expect (payment.currency).to eq('USD')
86+
end
8387
end
8488

8589
context 'if the payment is not successful' do

spec/models/ticket_purchase_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
expect(subject).not_to allow_value(-1).for(:quantity)
4545
end
4646

47+
it 'is not valid without a currency' do
48+
expect(subject).to validate_presence_of(:currency)
49+
end
50+
4751
it 'is valid with a quantity greater than zero' do
4852
expect(subject).to allow_value(1).for(:quantity)
4953
end

0 commit comments

Comments
 (0)