1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

test space availabilities api

This commit is contained in:
Sylvain 2017-02-15 16:22:19 +01:00
parent 23b9851218
commit 34e8ffeffd
4 changed files with 71 additions and 4 deletions

View File

@ -168,4 +168,14 @@ availability_17:
created_at: 2016-04-04 15:44:04.023557000 Z
updated_at: 2016-04-04 15:44:04.023557000 Z
nb_total_places:
destroying: false
destroying: false
availability_18:
id: 18
start_at: <%= 2.days.from_now.utc.change({hour: 8}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
end_at: <%= 2.days.from_now.utc.change({hour: 12}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
available_type: space
created_at: 2017-02-15 15:53:35.154433000 Z
updated_at: 2017-02-15 15:53:35.154433000 Z
nb_total_places: 5
destroying: false

View File

@ -1 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
space_1:
id: 1
name: Atelier Bois
default_places: 10
description: Devenez un véritable menuisier à l'espace atelier bois de votre fablab
slug: atelier-bois
created_at: 2017-02-15 15:55:04.123928000 Z
updated_at: 2017-02-15 15:55:04.123928000 Z
characteristics: Scie à chantourner, rabot, dégauchisseuse, chanfreineuse et pyrograveur

View File

@ -1 +1,6 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
spaces_availability_1:
id: 1
space_id: 1
availability_id: 18
created_at: 2017-02-15 15:59:08.892741000 Z
updated_at: 2017-02-15 15:59:08.892741000 Z

View File

@ -40,6 +40,50 @@ module Availabilities
assert_not a[:start] < DateTime.now, 'retrieved a slot in the past'
end
end
end
test 'get calendar availabilities without spaces' do
# disable spaces in application
Rails.application.secrets.fablab_without_spaces = true
# this simulates a fullCalendar (v2) call
start_date = DateTime.now.utc.strftime('%Y-%m-%d')
end_date = 7.days.from_now.utc.strftime('%Y-%m-%d')
tz = Time.zone.tzinfo.name
get "/api/availabilities?start=#{start_date}&end=#{end_date}&timezone=#{tz}&_=1487169767960"
# Check response format & status
assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type
# Check the correct availabilities was returned
availabilities = json_response(response.body)
assert_not_empty availabilities, 'no availabilities were found'
assert_not_nil availabilities[0], 'first availability was unexpectedly nil'
assert_not availabilities.map {|a| a[:available_type] }.include?('space'), 'unexpected space availability instead that it was disabled'
# re-enable spaces to keep tests ENV-safe
Rails.application.secrets.fablab_without_spaces = false
end
test 'get calendar availabilities with spaces' do
# this simulates a fullCalendar (v2) call
start_date = DateTime.now.utc.strftime('%Y-%m-%d')
end_date = 7.days.from_now.utc.strftime('%Y-%m-%d')
tz = Time.zone.tzinfo.name
get "/api/availabilities?start=#{start_date}&end=#{end_date}&timezone=#{tz}&_=1487169767960"
# Check response format & status
assert_equal 200, response.status
assert_equal Mime::JSON, response.content_type
# Check the correct availabilities was returned
availabilities = json_response(response.body)
assert_not_empty availabilities, 'no availabilities were found'
assert_not_nil availabilities[0], 'first availability was unexpectedly nil'
assert availabilities.map {|a| a[:available_type] }.include?('space'), 'space availability not found instead that it was enabled'
end
end
end