mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
adds tests for public availabilities
This commit is contained in:
parent
b11bb11968
commit
d197f16cd9
@ -40,7 +40,6 @@ class Availabilities::AvailabilitiesService
|
||||
|
||||
if @level == 'slot'
|
||||
slots = availabilities.map(&:slots).flatten
|
||||
|
||||
blocked_slots = Slots::InterblockingService.new.blocked_slots_for_machines(machines, slots)
|
||||
flag_or_remove_blocked_slots(slots, blocked_slots, @current_user)
|
||||
else
|
||||
|
@ -3,7 +3,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class Availabilities::AsPublicTest < ActionDispatch::IntegrationTest
|
||||
test 'get public machines availabilities if machines module is active' do
|
||||
test "[level == 'availability'] get public machines availabilities if machines module is active" do
|
||||
start_date = Time.current.to_date
|
||||
end_date = 7.days.from_now.to_date
|
||||
|
||||
@ -24,6 +24,24 @@ class Availabilities::AsPublicTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
test "[level == 'slot'] get public machines availabilities if machines module is active" do
|
||||
start_date = Time.current.to_date
|
||||
end_date = start_date + 1.day
|
||||
|
||||
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_machines}"
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status
|
||||
assert_match Mime[:json].to_s, response.content_type
|
||||
|
||||
# Check the correct availabilities was returned
|
||||
availabilities = json_response(response.body)
|
||||
assert_not_empty availabilities, 'no availabilities were found'
|
||||
availabilities.each do |a|
|
||||
assert_not_empty a[:machine_ids]
|
||||
end
|
||||
end
|
||||
|
||||
test 'get anymore machines availabilities if machines module is inactive' do
|
||||
Setting.set('machines_module', false)
|
||||
start_date = Time.current.to_date
|
||||
@ -61,6 +79,45 @@ class Availabilities::AsPublicTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
test "[level == 'availability'] get public spaces availabilities" do
|
||||
start_date = Time.current.to_date
|
||||
end_date = 7.days.from_now.to_date
|
||||
|
||||
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_spaces}"
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status
|
||||
assert_match Mime[:json].to_s, response.content_type
|
||||
|
||||
# Check the correct availabilities was returned
|
||||
availabilities = json_response(response.body)
|
||||
assert_not_empty availabilities, 'no availabilities were found'
|
||||
availabilities.each_with_index do |a, index|
|
||||
assert_not_nil a, "availability #{index} was unexpectedly nil"
|
||||
assert_equal 'space', a[:available_type], "availability #{index} is not a space availability"
|
||||
assert Time.zone.parse(a[:start]) > start_date, "availability #{index} starts before the requested period"
|
||||
assert Time.zone.parse(a[:end]) < end_date, "availability #{index} ends after the requested period"
|
||||
end
|
||||
end
|
||||
|
||||
test "[level == 'slot'] get public spaces availabilities" do
|
||||
start_date = Time.current.to_date
|
||||
end_date = start_date + 1.day
|
||||
|
||||
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_spaces}"
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status
|
||||
assert_match Mime[:json].to_s, response.content_type
|
||||
|
||||
# Check the correct availabilities was returned
|
||||
availabilities = json_response(response.body)
|
||||
assert_not_empty availabilities, 'no availabilities were found'
|
||||
availabilities.each do |a|
|
||||
assert_not_nil a[:space_id]
|
||||
end
|
||||
end
|
||||
|
||||
test 'get public spaces availabilities' do
|
||||
start_date = Time.current.to_date
|
||||
end_date = 7.days.from_now.to_date
|
||||
|
Loading…
x
Reference in New Issue
Block a user