mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
tests for availabilities
This commit is contained in:
parent
6f4e795d9f
commit
3016ac1e82
41
test/fixtures/availabilities.yml.erb
vendored
41
test/fixtures/availabilities.yml.erb
vendored
@ -117,4 +117,45 @@ availability_12:
|
||||
created_at: 2012-04-04 15:24:01.517486000 Z
|
||||
updated_at: 2012-04-04 15:24:01.517486000 Z
|
||||
nb_total_places:
|
||||
destroying: false
|
||||
|
||||
availability_13:
|
||||
id: 13
|
||||
start_at: 2015-06-15 12:00:28.000000000 Z
|
||||
end_at: 2015-06-15 18:00:28.000000000 Z
|
||||
available_type: machines
|
||||
created_at: 2015-05-30 18:40:39.141601000 Z
|
||||
updated_at: 2015-05-30 18:40:39.141601000 Z
|
||||
nb_total_places:
|
||||
destroying: false
|
||||
|
||||
|
||||
availability_14:
|
||||
id: 14
|
||||
start_at: <%= 20.days.from_now.utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
end_at: <%= 20.days.from_now.utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
available_type: machines
|
||||
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
|
||||
|
||||
availability_15:
|
||||
id: 15
|
||||
start_at: <%= 40.days.from_now.utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
end_at: <%= 40.days.from_now.utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
available_type: machines
|
||||
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
|
||||
|
||||
availability_16:
|
||||
id: 16
|
||||
start_at: <%= 80.days.from_now.utc.change({hour: 6}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
end_at: <%= 80.days.from_now.utc.change({hour: 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||
available_type: machines
|
||||
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
|
20
test/fixtures/machines_availabilities.yml
vendored
20
test/fixtures/machines_availabilities.yml
vendored
@ -83,3 +83,23 @@ machines_availability_17:
|
||||
id: 17
|
||||
machine_id: 6
|
||||
availability_id: 7
|
||||
|
||||
machines_availability_18:
|
||||
id: 18
|
||||
machine_id: 2
|
||||
availability_id: 13
|
||||
|
||||
machines_availability_19:
|
||||
id: 19
|
||||
machine_id: 2
|
||||
availability_id: 14
|
||||
|
||||
machines_availability_20:
|
||||
id: 20
|
||||
machine_id: 2
|
||||
availability_id: 15
|
||||
|
||||
machines_availability_21:
|
||||
id: 21
|
||||
machine_id: 2
|
||||
availability_id: 16
|
||||
|
45
test/integration/availabilities/as_admin_test.rb
Normal file
45
test/integration/availabilities/as_admin_test.rb
Normal file
@ -0,0 +1,45 @@
|
||||
module Availabilities
|
||||
class AsAdminTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
admin = User.with_role(:admin).first
|
||||
login_as(admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'return availability by id' do
|
||||
a = Availability.take
|
||||
|
||||
get "/api/availabilities/#{a.id}"
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status
|
||||
assert_equal Mime::JSON, response.content_type
|
||||
|
||||
# Check the correct availability was returned
|
||||
availability = json_response(response.body)
|
||||
assert_equal a.id, availability[:id], 'availability id does not match'
|
||||
end
|
||||
|
||||
test 'get machine availabilities as admin' do
|
||||
m = Machine.find_by_slug('decoupeuse-vinyle')
|
||||
|
||||
get "/api/availabilities/machines/#{m.id}"
|
||||
|
||||
# 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_nil availabilities[0][:machine], "first availability's machine was unexpectedly nil"
|
||||
assert_equal m.id, availabilities[0][:machine][:id], "first availability's machine does not match the required machine"
|
||||
|
||||
# Check that we din't get availabilities from the past
|
||||
availabilities.each do |a|
|
||||
assert_not a[:start] < DateTime.now, 'retrieved a slot in the past'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,24 +1,10 @@
|
||||
class AvailabilitiesTest < ActionDispatch::IntegrationTest
|
||||
class Availabilities::AsUserTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
admin = User.with_role(:admin).first
|
||||
login_as(admin, scope: :user)
|
||||
user = User.find_by_username('kdumas')
|
||||
login_as(user, scope: :user)
|
||||
end
|
||||
|
||||
test 'return availability by id' do
|
||||
a = Availability.take
|
||||
|
||||
get "/api/availabilities/#{a.id}"
|
||||
|
||||
# Check response format & status
|
||||
assert_equal 200, response.status
|
||||
assert_equal Mime::JSON, response.content_type
|
||||
|
||||
# Check the correct availability was returned
|
||||
availability = json_response(response.body)
|
||||
assert_equal a.id, availability[:id], 'availability id does not match'
|
||||
end
|
||||
|
||||
test 'get machine availabilities' do
|
||||
test 'get machine availabilities as user' do
|
||||
m = Machine.find_by_slug('decoupeuse-vinyle')
|
||||
|
||||
get "/api/availabilities/machines/#{m.id}"
|
||||
@ -33,5 +19,16 @@ class AvailabilitiesTest < ActionDispatch::IntegrationTest
|
||||
assert_not_nil availabilities[0], 'first availability was unexpectedly nil'
|
||||
assert_not_nil availabilities[0][:machine], "first availability's machine was unexpectedly nil"
|
||||
assert_equal m.id, availabilities[0][:machine][:id], "first availability's machine does not match the required machine"
|
||||
|
||||
# Check that we din't get availabilities from the past
|
||||
availabilities.each do |a|
|
||||
assert_not a[:start] < DateTime.now, 'retrieved a slot in the past'
|
||||
end
|
||||
|
||||
# Check that we don't get availabilities in more than a month
|
||||
availabilities.each do |a|
|
||||
assert_not a[:start] > 1.month.from_now , 'retrieved a slot in more than 1 month for user who has no yearly subscription'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user