2021-06-28 09:50:37 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
module OpenApi; end
|
|
|
|
|
|
|
|
class OpenApi::ReservationsTest < ActionDispatch::IntegrationTest
|
|
|
|
def setup
|
|
|
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
|
|
|
end
|
|
|
|
|
2023-03-03 10:09:07 +01:00
|
|
|
test 'list reservations ' do
|
2021-06-28 09:50:37 +02:00
|
|
|
get '/open_api/v1/reservations', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
2022-11-23 17:35:39 +01:00
|
|
|
assert_equal Mime[:json], response.content_type
|
2022-08-30 14:16:49 +02:00
|
|
|
|
2023-03-03 10:09:07 +01:00
|
|
|
assert_not_empty json_response(response.body)[:reservations]
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'list all reservations with pagination' do
|
|
|
|
get '/open_api/v1/reservations?page=1&per_page=5', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
2022-11-23 17:35:39 +01:00
|
|
|
assert_equal Mime[:json], response.content_type
|
2022-08-30 14:16:49 +02:00
|
|
|
|
2022-11-23 17:35:39 +01:00
|
|
|
reservations = json_response(response.body)
|
|
|
|
assert reservations[:reservations].count <= 5
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'list all reservations for a user' do
|
|
|
|
get '/open_api/v1/reservations?user_id=3', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
2022-11-23 17:35:39 +01:00
|
|
|
assert_equal Mime[:json], response.content_type
|
|
|
|
|
|
|
|
reservations = json_response(response.body)
|
|
|
|
assert_not_empty reservations[:reservations]
|
|
|
|
assert_equal [3], reservations[:reservations].pluck(:user_id).uniq
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'list all reservations for a user with pagination' do
|
|
|
|
get '/open_api/v1/reservations?user_id=3&page=1&per_page=5', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
2022-11-23 17:35:39 +01:00
|
|
|
assert_equal Mime[:json], response.content_type
|
|
|
|
|
|
|
|
reservations = json_response(response.body)
|
|
|
|
assert reservations[:reservations].count <= 5
|
|
|
|
assert_equal [3], reservations[:reservations].pluck(:user_id).uniq
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'list all machine reservations for a user' do
|
|
|
|
get '/open_api/v1/reservations?reservable_type=Machine&user_id=3', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
2022-11-23 17:35:39 +01:00
|
|
|
assert_equal Mime[:json], response.content_type
|
|
|
|
|
|
|
|
reservations = json_response(response.body)
|
|
|
|
assert_not_empty reservations[:reservations]
|
|
|
|
assert_equal [3], reservations[:reservations].pluck(:user_id).uniq
|
|
|
|
assert_equal ['Machine'], reservations[:reservations].pluck(:reservable_type).uniq
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|
|
|
|
|
2023-01-12 17:48:52 +01:00
|
|
|
test 'list all machine 2 reservations' do
|
|
|
|
get '/open_api/v1/reservations?reservable_type=Machine&reservable_id=2', headers: open_api_headers(@token)
|
2021-06-28 09:50:37 +02:00
|
|
|
assert_response :success
|
2022-11-23 17:35:39 +01:00
|
|
|
assert_equal Mime[:json], response.content_type
|
|
|
|
|
|
|
|
reservations = json_response(response.body)
|
|
|
|
assert_not_empty reservations[:reservations]
|
2023-01-12 17:48:52 +01:00
|
|
|
assert_equal [2], reservations[:reservations].pluck(:reservable_id).uniq
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|
|
|
|
end
|