1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/test/integration/open_api/reservations_test.rb
Sylvain a55880a0ad (feat) OpenAPI endpoint for accounting
Also: (bug) filter by array in openAPI = error
2022-12-21 14:12:14 +01:00

70 lines
2.5 KiB
Ruby

# 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
test 'list all reservations' do
get '/open_api/v1/reservations', headers: open_api_headers(@token)
assert_response :success
assert_equal Mime[:json], response.content_type
assert_equal Reservation.count, json_response(response.body)[:reservations].length
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
assert_equal Mime[:json], response.content_type
reservations = json_response(response.body)
assert reservations[:reservations].count <= 5
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
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
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
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
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
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
end
test 'list all machine 4 reservations' do
get '/open_api/v1/reservations?reservable_type=Machine&reservable_id=4', headers: open_api_headers(@token)
assert_response :success
assert_equal Mime[:json], response.content_type
reservations = json_response(response.body)
assert_not_empty reservations[:reservations]
assert_equal [4], reservations[:reservations].pluck(:reservable_id).uniq
end
end