2020-06-24 16:07:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class Availabilities::AsPublicTest < ActionDispatch::IntegrationTest
|
2022-12-20 18:42:19 +01:00
|
|
|
test 'get public machines availabilities if machines module is active' do
|
2023-02-17 11:44:04 +01:00
|
|
|
start_date = Time.current.to_date
|
|
|
|
end_date = 7.days.from_now.to_date
|
2020-06-24 16:07:15 +02:00
|
|
|
|
2022-12-20 18:42:19 +01:00
|
|
|
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_machines}"
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# Check response format & status
|
|
|
|
assert_equal 200, response.status
|
2023-02-24 17:26:55 +01:00
|
|
|
assert_match Mime[:json].to_s, response.content_type
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# 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 'machines', a[:available_type], "availability #{index} is not a machines availability"
|
2023-02-17 11:44:04 +01:00
|
|
|
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"
|
2020-06-24 16:07:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-20 18:42:19 +01:00
|
|
|
test 'get anymore machines availabilities if machines module is inactive' do
|
|
|
|
Setting.set('machines_module', false)
|
2023-02-17 11:44:04 +01:00
|
|
|
start_date = Time.current.to_date
|
|
|
|
end_date = 7.days.from_now.to_date
|
2022-12-20 18:42:19 +01:00
|
|
|
|
|
|
|
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_machines}"
|
|
|
|
|
|
|
|
# Check response format & status
|
|
|
|
assert_equal 200, response.status
|
2023-02-24 17:26:55 +01:00
|
|
|
assert_match Mime[:json].to_s, response.content_type
|
2022-12-20 18:42:19 +01:00
|
|
|
|
|
|
|
# Check the correct availabilities was returned
|
|
|
|
availabilities = json_response(response.body)
|
|
|
|
assert_empty availabilities
|
|
|
|
end
|
|
|
|
|
2020-06-24 16:07:15 +02:00
|
|
|
test 'get public trainings availabilities' do
|
2023-02-17 11:44:04 +01:00
|
|
|
start_date = Time.current.to_date
|
|
|
|
end_date = 7.days.from_now.to_date
|
2020-06-24 16:07:15 +02:00
|
|
|
|
2022-12-20 18:42:19 +01:00
|
|
|
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_trainings}"
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# Check response format & status
|
|
|
|
assert_equal 200, response.status
|
2023-02-24 17:26:55 +01:00
|
|
|
assert_match Mime[:json].to_s, response.content_type
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# 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 'training', a[:available_type], "availability #{index} is not a training availability"
|
2023-02-17 11:44:04 +01:00
|
|
|
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"
|
2020-06-24 16:07:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'get public spaces availabilities' do
|
2023-02-17 11:44:04 +01:00
|
|
|
start_date = Time.current.to_date
|
|
|
|
end_date = 7.days.from_now.to_date
|
2020-06-24 16:07:15 +02:00
|
|
|
|
2022-12-20 18:42:19 +01:00
|
|
|
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&#{all_spaces}"
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# Check response format & status
|
|
|
|
assert_equal 200, response.status
|
2023-02-24 17:26:55 +01:00
|
|
|
assert_match Mime[:json].to_s, response.content_type
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# 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"
|
2023-02-17 11:44:04 +01:00
|
|
|
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"
|
2020-06-24 16:07:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'get public events availabilities' do
|
2022-07-18 17:17:21 +02:00
|
|
|
start_date = 8.days.from_now.to_date
|
|
|
|
end_date = 16.days.from_now.to_date
|
2020-06-24 16:07:15 +02:00
|
|
|
|
2022-12-20 18:42:19 +01:00
|
|
|
get "/api/availabilities/public?start=#{start_date}&end=#{end_date}&timezone=Europe%2FParis&evt=true"
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# Check response format & status
|
|
|
|
assert_equal 200, response.status
|
2023-02-24 17:26:55 +01:00
|
|
|
assert_match Mime[:json].to_s, response.content_type
|
2020-06-24 16:07:15 +02:00
|
|
|
|
|
|
|
# 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 'event', a[:available_type], "availability #{index} is not a event availability"
|
2023-02-17 11:44:04 +01:00
|
|
|
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"
|
2020-06-24 16:07:15 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def all_machines
|
|
|
|
Machine.all.map { |m| "m%5B%5D=#{m.id}" }.join('&')
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_trainings
|
|
|
|
Training.all.map { |m| "t%5B%5D=#{m.id}" }.join('&')
|
|
|
|
end
|
|
|
|
|
|
|
|
def all_spaces
|
|
|
|
Space.all.map { |m| "s%5B%5D=#{m.id}" }.join('&')
|
|
|
|
end
|
2022-07-18 17:17:21 +02:00
|
|
|
end
|