1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

fix running test renew_as_admin_test

This commit is contained in:
Sylvain 2021-04-26 11:40:26 +02:00
parent 0a5380d310
commit b9e8c8867c
14 changed files with 21 additions and 21 deletions

View File

@ -13,7 +13,7 @@ class API::SubscriptionsController < API::ApiController
# otherwise, they must use payments_controller#confirm_payment.
# Managers can create subscriptions for other users
def create
user_id = current_user.admin? || current_user.manager? ? params[:subscription][:user_id] : current_user.id
user_id = current_user.admin? || current_user.manager? ? params[:customer_id] : current_user.id
transaction = transaction_amount(user_id)
authorize SubscriptionContext.new(Subscription, transaction[:amount], user_id)
@ -57,7 +57,7 @@ class API::SubscriptionsController < API::ApiController
plan_id: subscription_params[:plan_id]
},
coupon_code: coupon_params[:coupon_code],
payment_schedule: subscription_params[:payment_schedule])
payment_schedule: params[:payment_schedule])
price_details = cart.total
user = User.find(user_id)

View File

@ -5,7 +5,7 @@ class CartItem::EventReservation < CartItem::Reservation
# @param normal_tickets {Number} number of tickets at the normal price
# @param other_tickets {Array<{booked: Number, event_price_category_id: Number}>}
def initialize(customer, operator, event, slots, normal_tickets: 0, other_tickets: [])
raise TypeError unless event.class == Event
raise TypeError unless event.is_a? Event
super(customer, operator, event, slots)
@normal_tickets = normal_tickets

View File

@ -5,7 +5,7 @@ class CartItem::MachineReservation < CartItem::Reservation
# @param plan {Plan} a subscription bought at the same time of the reservation OR an already running subscription
# @param new_subscription {Boolean} true is new subscription is being bought at the same time of the reservation
def initialize(customer, operator, machine, slots, plan: nil, new_subscription: false)
raise TypeError unless machine.class == Machine
raise TypeError unless machine.is_a? Machine
super(customer, operator, machine, slots)
@plan = plan

View File

@ -3,7 +3,7 @@
# A payment schedule applied to plan in the shopping cart
class CartItem::PaymentSchedule
def initialize(plan, coupon, requested)
raise TypeError unless coupon.class == CartItem::Coupon
raise TypeError unless coupon.is_a? CartItem::Coupon
@plan = plan
@coupon = coupon

View File

@ -5,7 +5,7 @@ class CartItem::SpaceReservation < CartItem::Reservation
# @param plan {Plan} a subscription bought at the same time of the reservation OR an already running subscription
# @param new_subscription {Boolean} true is new subscription is being bought at the same time of the reservation
def initialize(customer, operator, space, slots, plan: nil, new_subscription: false)
raise TypeError unless space.class == Space
raise TypeError unless space.is_a? Space
super(customer, operator, space, slots)
@plan = plan

View File

@ -3,7 +3,7 @@
# A subscription added to the shopping cart
class CartItem::Subscription < CartItem::BaseItem
def initialize(plan)
raise TypeError unless plan.class == Plan
raise TypeError unless plan.is_a? Plan
@plan = plan
end

View File

@ -5,7 +5,7 @@ class CartItem::TrainingReservation < CartItem::Reservation
# @param plan {Plan} a subscription bought at the same time of the reservation OR an already running subscription
# @param new_subscription {Boolean} true is new subscription is being bought at the same time of the reservation
def initialize(customer, operator, training, slots, plan: nil, new_subscription: false)
raise TypeError unless training.class == Training
raise TypeError unless training.is_a? Training
super(customer, operator, training, slots)
@plan = plan

View File

@ -9,7 +9,7 @@ class ShoppingCart
# @param payment_schedule {CartItem::PaymentSchedule}
# @param customer {User}
def initialize(customer, coupon, payment_schedule, payment_method = '', items: [])
raise TypeError unless customer.class == User
raise TypeError unless customer.is_a? User
@customer = customer
@payment_method = payment_method

View File

@ -33,12 +33,12 @@ class CartService
private
def plan(cart_items)
plan = if @customer.subscribed_plan
new_plan_being_bought = false
@customer.subscribed_plan
elsif cart_items[:subscription] && cart_items[:subscription][:plan_id]
plan = if cart_items[:subscription] && cart_items[:subscription][:plan_id]
new_plan_being_bought = true
Plan.find(cart_items[:subscription][:plan_id])
elsif @customer.subscribed_plan
new_plan_being_bought = false
@customer.subscribed_plan
else
new_plan_being_bought = false
nil

View File

@ -64,7 +64,7 @@ class FootprintService
# Return a comparable value for jsonb fields (with keys ordered alphabetically)
def comparable(value)
return value unless value.class == Hash
return value unless value.is_a? Hash
value.sort.to_h
end

View File

@ -121,7 +121,7 @@ class InvoicesService
# This method must be called if reservation.reservable is an Event
##
def self.generate_event_item(invoice, reservation, payment_details)
raise TypeError unless reservation.reservable.class == Event
raise TypeError unless reservation.reservable.is_a? Event
reservation.slots.each do |slot|
description = "#{reservation.reservable.name}\n"

View File

@ -9,7 +9,7 @@ class PaymentDocumentService
reference = replace_invoice_number_pattern(pattern)
reference = replace_date_pattern(reference, date)
if document.class == Avoir
if document.is_a? Avoir
# information about refund/avoir (R[text])
reference.gsub!(/R\[([^\]]+)\]/, '\1')
@ -17,14 +17,14 @@ class PaymentDocumentService
reference.gsub!(/X\[([^\]]+)\]/, ''.to_s)
# remove information about payment schedule (S[text])
reference.gsub!(/S\[([^\]]+)\]/, ''.to_s)
elsif document.class == PaymentSchedule
elsif document.is_a? PaymentSchedule
# information about payment schedule
reference.gsub!(/S\[([^\]]+)\]/, '\1')
# remove information about online selling (X[text])
reference.gsub!(/X\[([^\]]+)\]/, ''.to_s)
# remove information about refunds (R[text])
reference.gsub!(/R\[([^\]]+)\]/, ''.to_s)
elsif document.class == Invoice
elsif document.is_a? Invoice
# information about online selling (X[text])
if document.paid_by_card?
reference.gsub!(/X\[([^\]]+)\]/, '\1')

View File

@ -80,7 +80,7 @@ class WalletService
# @param coupon {Coupon|String} Coupon object or code
##
def self.wallet_amount_debit(payment, user, coupon = nil)
total = if payment.class == PaymentSchedule
total = if payment.is_a? PaymentSchedule
payment.payment_schedule_items.first.amount
else
payment.total

View File

@ -15,9 +15,9 @@ class Subscriptions::RenewAsAdminTest < ActionDispatch::IntegrationTest
VCR.use_cassette('subscriptions_admin_renew_success') do
post '/api/subscriptions',
params: {
customer_id: user.id,
subscription: {
plan_id: plan.id,
user_id: user.id
plan_id: plan.id
}
}.to_json, headers: default_headers
end