2021-06-28 09:50:37 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
module OpenApi; end
|
|
|
|
|
|
|
|
class OpenApi::MachinesTest < ActionDispatch::IntegrationTest
|
|
|
|
def setup
|
|
|
|
@token = OpenAPI::Client.find_by(name: 'minitest').token
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'list all machines' do
|
|
|
|
get '/open_api/v1/machines', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
2022-11-23 11:59:06 +01:00
|
|
|
machines = json_response(response.body)
|
|
|
|
assert_not_empty machines[:machines]
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'create a machine' do
|
|
|
|
post '/open_api/v1/machines',
|
|
|
|
params: {
|
|
|
|
machine: {
|
|
|
|
name: 'IJFX 350 Laser',
|
2022-11-23 11:59:06 +01:00
|
|
|
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et...',
|
2021-06-28 09:50:37 +02:00
|
|
|
spec: 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium...',
|
|
|
|
disabled: true
|
|
|
|
}
|
|
|
|
}.to_json,
|
|
|
|
headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'update a machine' do
|
|
|
|
patch '/open_api/v1/machines/3',
|
|
|
|
params: {
|
|
|
|
machine: {
|
|
|
|
disabled: true,
|
|
|
|
name: '[DISABLED] Shopbot'
|
|
|
|
}
|
|
|
|
}.to_json,
|
|
|
|
headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'get a machine' do
|
|
|
|
get '/open_api/v1/machines/3', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'delete a machine' do
|
|
|
|
delete '/open_api/v1/machines/3', headers: open_api_headers(@token)
|
|
|
|
assert_response :success
|
|
|
|
end
|
2022-11-23 11:59:06 +01:00
|
|
|
|
|
|
|
test 'soft delete a machine' do
|
2023-01-12 17:48:52 +01:00
|
|
|
assert_not Machine.find(2).destroyable?
|
|
|
|
delete '/open_api/v1/machines/2', headers: open_api_headers(@token)
|
2022-11-23 11:59:06 +01:00
|
|
|
assert_response :success
|
2023-01-12 17:48:52 +01:00
|
|
|
get '/open_api/v1/machines/2', headers: open_api_headers(@token)
|
2022-11-23 11:59:06 +01:00
|
|
|
assert_response :not_found
|
|
|
|
get '/open_api/v1/machines', headers: open_api_headers(@token)
|
|
|
|
machines = json_response(response.body)
|
2023-01-12 17:48:52 +01:00
|
|
|
assert_not(machines[:machines].any? { |m| m[:id] == 2 })
|
2022-11-23 11:59:06 +01:00
|
|
|
end
|
2021-06-28 09:50:37 +02:00
|
|
|
end
|