1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +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. # otherwise, they must use payments_controller#confirm_payment.
# Managers can create subscriptions for other users # Managers can create subscriptions for other users
def create 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) transaction = transaction_amount(user_id)
authorize SubscriptionContext.new(Subscription, 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] plan_id: subscription_params[:plan_id]
}, },
coupon_code: coupon_params[:coupon_code], coupon_code: coupon_params[:coupon_code],
payment_schedule: subscription_params[:payment_schedule]) payment_schedule: params[:payment_schedule])
price_details = cart.total price_details = cart.total
user = User.find(user_id) 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 normal_tickets {Number} number of tickets at the normal price
# @param other_tickets {Array<{booked: Number, event_price_category_id: Number}>} # @param other_tickets {Array<{booked: Number, event_price_category_id: Number}>}
def initialize(customer, operator, event, slots, normal_tickets: 0, other_tickets: []) 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) super(customer, operator, event, slots)
@normal_tickets = normal_tickets @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 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 # @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) 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) super(customer, operator, machine, slots)
@plan = plan @plan = plan

View File

@ -3,7 +3,7 @@
# A payment schedule applied to plan in the shopping cart # A payment schedule applied to plan in the shopping cart
class CartItem::PaymentSchedule class CartItem::PaymentSchedule
def initialize(plan, coupon, requested) def initialize(plan, coupon, requested)
raise TypeError unless coupon.class == CartItem::Coupon raise TypeError unless coupon.is_a? CartItem::Coupon
@plan = plan @plan = plan
@coupon = coupon @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 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 # @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) 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) super(customer, operator, space, slots)
@plan = plan @plan = plan

View File

@ -3,7 +3,7 @@
# A subscription added to the shopping cart # A subscription added to the shopping cart
class CartItem::Subscription < CartItem::BaseItem class CartItem::Subscription < CartItem::BaseItem
def initialize(plan) def initialize(plan)
raise TypeError unless plan.class == Plan raise TypeError unless plan.is_a? Plan
@plan = plan @plan = plan
end 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 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 # @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) 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) super(customer, operator, training, slots)
@plan = plan @plan = plan

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -80,7 +80,7 @@ class WalletService
# @param coupon {Coupon|String} Coupon object or code # @param coupon {Coupon|String} Coupon object or code
## ##
def self.wallet_amount_debit(payment, user, coupon = nil) 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 payment.payment_schedule_items.first.amount
else else
payment.total payment.total

View File

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