1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-07 01:54:16 +01:00

fix test Events::AsUserTest

the event price calculalation was using a variable not reinitialized
This commit is contained in:
Sylvain 2021-04-26 16:38:00 +02:00
parent 53e9a1c4f2
commit da372cf8ad
2 changed files with 108 additions and 105 deletions

View File

@ -21,16 +21,17 @@ class CartItem::EventReservation < CartItem::Reservation
end end
elements = { slots: [] } elements = { slots: [] }
total = 0
@slots.each do |slot| @slots.each do |slot|
amount += get_slot_price(amount, total += get_slot_price(amount,
slot, slot,
is_privileged, is_privileged,
elements: elements, elements: elements,
is_division: false) is_division: false)
end end
{ elements: elements, amount: amount } { elements: elements, amount: total }
end end
def name def name

View File

@ -1,7 +1,10 @@
# frozen_string_literal: true # frozen_string_literal: true
module Events require 'test_helper'
class AsUserTest < ActionDispatch::IntegrationTest
module Events; end
class Events::AsUserTest < ActionDispatch::IntegrationTest
test 'reserve event with many prices and payment means and VAT' do test 'reserve event with many prices and payment means and VAT' do
vlonchamp = User.find_by(username: 'vlonchamp') vlonchamp = User.find_by(username: 'vlonchamp')
login_as(vlonchamp, scope: :user) login_as(vlonchamp, scope: :user)
@ -29,8 +32,8 @@ module Events
post '/api/stripe/confirm_payment', post '/api/stripe/confirm_payment',
params: { params: {
payment_method_id: stripe_payment_method, payment_method_id: stripe_payment_method,
customer_id: User.find_by(username: 'vlonchamp').id,
cart_items: { cart_items: {
customer_id: User.find_by(username: 'vlonchamp').id,
reservation: { reservation: {
reservable_id: radio.id, reservable_id: radio.id,
reservable_type: 'Event', reservable_type: 'Event',
@ -95,7 +98,7 @@ module Events
VCR.use_cassette('reserve_event_with_many_prices_and_payment_means_retrieve_invoice_from_stripe') do VCR.use_cassette('reserve_event_with_many_prices_and_payment_means_retrieve_invoice_from_stripe') do
stp_intent = invoice.payment_gateway_object.gateway_object.retrieve stp_intent = invoice.payment_gateway_object.gateway_object.retrieve
assert_equal stp_intent.amount, (invoice.total - invoice.wallet_amount) # total minus coupon minus wallet = amount really payed by the user assert_equal stp_intent.amount, (invoice.total - invoice.wallet_amount) # total minus coupon minus wallet = amount really paid by the user
end end
# wallet assertions # wallet assertions
@ -111,4 +114,3 @@ module Events
assert_not_empty Notification.where(attached_object: invoice) assert_not_empty Notification.where(attached_object: invoice)
end end
end end
end