1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-15 00:24:09 +01:00
fab-manager/test/integration/machines_test.rb

92 lines
3.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'test_helper'
class MachinesTest < ActionDispatch::IntegrationTest
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'create a machine' do
name = 'IJFX 350 Laser'
post '/api/machines',
params: {
machine: {
name: name,
machine_image_attributes: {
attachment: fixture_file_upload('/files/machines/Laser_cutting_machine.jpg')
},
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore...',
spec: 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium...',
machine_files_attributes: [
2022-11-24 16:30:41 +01:00
{ attachment: fixture_file_upload('/files/document.pdf', 'application/pdf', true) },
{ attachment: fixture_file_upload('/files/document2.pdf', 'application/pdf', true) }
],
2022-12-22 16:03:07 +01:00
disabled: false,
machine_category_id: 1
}
},
headers: upload_headers
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the machine was correctly created
db_machine = Machine.where(name: name).first
assert_not_nil db_machine
assert_not_nil db_machine.machine_image.attachment
assert_not_nil db_machine.machine_files[0].attachment
assert_not_nil db_machine.machine_files[1].attachment
assert_equal name, db_machine.name
assert_not_empty db_machine.spec
assert_not_empty db_machine.description
assert_not db_machine.disabled
assert_nil db_machine.deleted_at
2022-12-22 16:03:07 +01:00
assert_equal db_machine.machine_category_id, 1
end
test 'update a machine' do
description = '<p>lorem ipsum <strong>dolor</strong> sit amet</p>'
put '/api/machines/3',
params: {
machine: {
description: description
}
}.to_json,
headers: default_headers
# Check response format & status
assert_equal 200, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the machine was correctly updated
db_machine = Machine.find(3)
assert_equal description, db_machine.description
machine = json_response(response.body)
assert_equal description, machine[:description]
end
test 'delete a machine' do
2023-01-19 17:41:21 +01:00
machine = Machine.find(3)
delete "/api/machines/#{machine.id}", headers: default_headers
assert_response :success
assert_empty response.body
2023-01-19 17:41:21 +01:00
assert_raise ActiveRecord::RecordNotFound do
machine.reload
end
end
test 'soft delete a machine' do
2023-01-12 17:48:52 +01:00
machine = Machine.find(2)
assert_not machine.destroyable?
2023-01-12 17:48:52 +01:00
delete "/api/machines/#{machine.id}", headers: default_headers
assert_response :success
assert_empty response.body
machine.reload
assert_not_nil machine.deleted_at
end
end