1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

(quality) add machine category test

This commit is contained in:
Du Peng 2022-12-22 16:03:07 +01:00
parent 774ce35fa8
commit 8f3951bd0e
3 changed files with 72 additions and 1 deletions

5
test/fixtures/machine_categories.yml vendored Normal file
View File

@ -0,0 +1,5 @@
machine_category_1:
id: 1
name: Category 1
created_at: 2022-12-20 14:11:34.544995000 Z
updated_at: 2022-12-20 14:11:34.544995000 Z

View File

@ -0,0 +1,64 @@
# frozen_string_literal: true
require 'test_helper'
class MachineCategoriesTest < ActionDispatch::IntegrationTest
def setup
@admin = User.find_by(username: 'admin')
login_as(@admin, scope: :user)
end
test 'create a machine category' do
name = 'Category 2'
post '/api/machine_categories',
params: {
machine_category: {
name: name,
machine_ids: [1]
}
}.to_json,
headers: default_headers
# Check response format & status
assert_equal 201, response.status, response.body
assert_equal Mime[:json], response.content_type
# Check the machine category was correctly created
category = MachineCategory.where(name: name).first
machine1 = Machine.find(1)
assert_not_nil category
assert_equal name, category.name
assert_equal category.machines.length, 1
assert_equal category.id, machine1.machine_category_id
end
test 'update a machine category' do
name = 'category update'
put '/api/machine_categories/1',
params: {
machine_category: {
name: name,
machine_ids: [2, 3]
}
}.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 category was correctly updated
category = MachineCategory.find(1)
assert_equal name, category.name
json = json_response(response.body)
assert_equal name, json[:name]
assert_equal category.machines.length, 2
assert_equal category.machine_ids, [2, 3]
end
test 'delete a machine category' do
delete '/api/machine_categories/1', headers: default_headers
assert_response :success
assert_empty response.body
end
end

View File

@ -23,7 +23,8 @@ class MachinesTest < ActionDispatch::IntegrationTest
{ attachment: fixture_file_upload('/files/document.pdf', 'document/pdf', true) },
{ attachment: fixture_file_upload('/files/document2.pdf', 'document/pdf', true) }
],
disabled: false
disabled: false,
machine_category_id: 1
}
},
headers: upload_headers
@ -43,6 +44,7 @@ class MachinesTest < ActionDispatch::IntegrationTest
assert_not_empty db_machine.description
assert_not db_machine.disabled
assert_nil db_machine.deleted_at
assert_equal db_machine.machine_category_id, 1
end
test 'update a machine' do