2016-04-05 10:04:15 +02:00
|
|
|
class AvailabilitiesTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
2016-04-05 12:28:42 +02:00
|
|
|
admin = User.with_role(:admin).first
|
|
|
|
login_as(admin, scope: :user)
|
2016-04-05 10:04:15 +02:00
|
|
|
end
|
|
|
|
|
2016-04-13 11:53:21 +02:00
|
|
|
test 'return availability by id' do
|
2016-04-05 12:28:42 +02:00
|
|
|
a = Availability.take
|
2016-04-05 10:04:15 +02:00
|
|
|
|
|
|
|
get "/api/availabilities/#{a.id}"
|
2016-04-13 11:53:21 +02:00
|
|
|
|
|
|
|
# Check response format & status
|
2016-04-05 10:04:15 +02:00
|
|
|
assert_equal 200, response.status
|
2016-04-13 11:53:21 +02:00
|
|
|
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
|
|
|
|
m = Machine.find_by_slug('decoupeuse-vinyle')
|
|
|
|
|
|
|
|
get "/api/availabilities/machines/#{m.id}"
|
2016-04-13 15:19:57 +02:00
|
|
|
|
|
|
|
# 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"
|
2016-04-05 10:04:15 +02:00
|
|
|
end
|
|
|
|
end
|