1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

fix tests + fix price.compute flor slots

This commit is contained in:
Sylvain 2020-05-11 13:52:27 +02:00
parent 10825e198c
commit 9f8fb1a95c
4 changed files with 15 additions and 12 deletions

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
MINUTES_PER_HOUR = 60
SECONDS_PER_MINUTE = 60
MINUTES_PER_HOUR = 60.0
SECONDS_PER_MINUTE = 60.0
# Store customized price for various items (Machine, Space), depending on the group and on the plan
# Also provides a static helper method to compute the price details of a shopping cart
@ -51,9 +51,9 @@ class Price < ApplicationRecord
when Machine
base_amount = reservable.prices.find_by(group_id: user.group_id, plan_id: plan.try(:id)).amount
if plan
space_credit = plan.machine_credits.select { |credit| credit.creditable_id == reservable.id }.first
if space_credit
hours_available = credits_hours(space_credit, user, new_plan_being_bought)
machine_credit = plan.machine_credits.select { |credit| credit.creditable_id == reservable.id }.first
if machine_credit
hours_available = credits_hours(machine_credit, user, new_plan_being_bought)
slots.each_with_index do |slot, index|
total_amount += get_slot_price(base_amount, slot, admin, elements: all_elements, has_credits: (index < hours_available))
end

View File

@ -57,7 +57,7 @@ module Reservations
# invoice_items assertions
invoice_item = InvoiceItem.last
assert_equal invoice_item.amount, machine.prices.find_by(group_id: @user_without_subscription.group_id, plan_id: nil).amount
assert_equal machine.prices.find_by(group_id: @user_without_subscription.group_id, plan_id: nil).amount, invoice_item.amount
# invoice assertions
invoice = Invoice.find_by(invoiced: reservation)
@ -244,7 +244,7 @@ module Reservations
# invoice_items assertions
invoice_item = InvoiceItem.last
assert_equal invoice_item.amount, machine.prices.find_by(group_id: @vlonchamp.group_id, plan_id: nil).amount
assert_equal machine.prices.find_by(group_id: @vlonchamp.group_id, plan_id: nil).amount, invoice_item.amount
# invoice assertions
invoice = Invoice.find_by(invoiced: reservation)

View File

@ -1,5 +1,7 @@
# frozen_string_literal: true
require 'test_helper'
module Reservations
class CreateTest < ActionDispatch::IntegrationTest
setup do
@ -67,7 +69,7 @@ module Reservations
# invoice_items assertions
invoice_item = InvoiceItem.last
assert_equal invoice_item.amount, machine.prices.find_by(group_id: @user_without_subscription.group_id, plan_id: nil).amount
assert_equal machine.prices.find_by(group_id: @user_without_subscription.group_id, plan_id: nil).amount, invoice_item.amount
assert invoice_item.check_footprint
# invoice assertions
@ -413,7 +415,7 @@ module Reservations
# invoice_items assertions
invoice_item = InvoiceItem.last
assert_equal invoice_item.amount, machine.prices.find_by(group_id: @vlonchamp.group_id, plan_id: nil).amount
assert_equal machine.prices.find_by(group_id: @vlonchamp.group_id, plan_id: nil).amount, invoice_item.amount
assert invoice_item.check_footprint
# invoice assertions

View File

@ -1,11 +1,12 @@
# frozen_string_literal: true
require 'test_helper'
class AvailabilityTest < ActiveSupport::TestCase
test "length must be at least 1h" do
test 'any duration is allowed' do
a = Availability.first
a.end_at = a.start_at + 15.minutes
assert a.invalid?
assert a.errors.key?(:end_at)
assert a.valid?
end
test "if type available_type is 'machines' check that there is minimum 1 association" do