2020-03-13 17:10:38 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-13 17:26:17 +02:00
|
|
|
class Availabilities::AsUserTest < ActionDispatch::IntegrationTest
|
2016-04-05 10:04:15 +02:00
|
|
|
setup do
|
2016-11-23 16:30:19 +01:00
|
|
|
user = User.find_by(username: 'kdumas')
|
2016-04-13 17:26:17 +02:00
|
|
|
login_as(user, scope: :user)
|
2016-04-05 10:04:15 +02:00
|
|
|
end
|
|
|
|
|
2016-04-13 17:26:17 +02:00
|
|
|
test 'get machine availabilities as user' do
|
2016-11-23 16:30:19 +01:00
|
|
|
m = Machine.find_by(slug: 'decoupeuse-vinyle')
|
2016-04-13 11:53:21 +02:00
|
|
|
|
|
|
|
get "/api/availabilities/machines/#{m.id}"
|
2016-04-13 15:19:57 +02:00
|
|
|
|
|
|
|
# Check response format & status
|
|
|
|
assert_equal 200, response.status
|
2020-03-13 17:10:38 +01:00
|
|
|
assert_equal Mime[:json], response.content_type
|
2016-04-13 15:19:57 +02:00
|
|
|
|
|
|
|
# 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-13 17:26:17 +02:00
|
|
|
|
|
|
|
# Check that we din't get availabilities from the past
|
|
|
|
availabilities.each do |a|
|
2019-12-02 15:29:05 +01:00
|
|
|
assert_not a[:start] < DateTime.current, 'retrieved a slot in the past'
|
2016-04-13 17:26:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# Check that we don't get availabilities in more than a month
|
|
|
|
availabilities.each do |a|
|
2020-03-13 17:10:38 +01:00
|
|
|
assert_not a[:start] > 1.month.from_now, 'retrieved a slot in more than 1 month for user who has no yearly subscription'
|
2016-04-13 17:26:17 +02:00
|
|
|
end
|
2016-04-05 10:04:15 +02:00
|
|
|
end
|
|
|
|
end
|