diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd85b1971..0865cd1c2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -80,6 +80,7 @@ test:unit:mysql: - rake test:units - rake test:controllers - ruby -I test/ test/integration/object_manager_test.rb + - ruby -I test/ test/integration/object_manager_attributes_controller_test.rb - ruby -I test/ test/integration/package_test.rb - rake db:drop @@ -96,6 +97,7 @@ test:unit:postgresql: - rake test:units - rake test:controllers - ruby -I test/ test/integration/object_manager_test.rb + - ruby -I test/ test/integration/object_manager_attributes_controller_test.rb - ruby -I test/ test/integration/package_test.rb - rake db:drop diff --git a/test/controllers/object_manager_attributes_controller_test.rb b/test/controllers/object_manager_attributes_controller_test.rb deleted file mode 100644 index 7888b8b98..000000000 --- a/test/controllers/object_manager_attributes_controller_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'test_helper' - -class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest - setup do - - # set accept header - @headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' } - - # create agent - roles = Role.where(name: 'Admin') - groups = Group.all - - UserInfo.current_user_id = 1 - @admin = User.create_or_update( - login: 'tickets-admin', - firstname: 'Tickets', - lastname: 'Admin', - email: 'tickets-admin@example.com', - password: 'adminpw', - active: true, - roles: roles, - groups: groups, - ) - end - test '01 converts string to boolean for default value for boolean data type' do - credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin@example.com', 'adminpw') - - post '/api/v1/object_manager_attributes', params: { 'name' => 'customdescription2', 'object' => 'Ticket', 'display' => 'custom description 2', 'active' => true, 'data_type' => 'boolean', 'data_option' => { 'options' => { 'true' => '', 'false' => '' }, 'default' => 'true' }, 'screens' => { 'create_middle' => { 'ticket.customer' => { 'shown' => true, 'item_class' => 'column' }, 'ticket.agent' => { 'shown' => true, 'item_class' => 'column' } }, 'edit' => { 'ticket.customer' => { 'shown' => true }, 'ticket.agent' => { 'shown' => true } } }, 'id' => 'c-192' }.to_json, headers: @headers.merge('Authorization' => credentials) - assert_response :success - result = JSON.parse @response.body - object = ObjectManager::Attribute.find result['id'] - assert_equal true, object.data_option['default'] - assert_equal 'boolean', object.data_type - object.destroy - end -end diff --git a/test/controllers/object_manager_attributes_controller.rb b/test/integration/object_manager_attributes_controller_test.rb similarity index 78% rename from test/controllers/object_manager_attributes_controller.rb rename to test/integration/object_manager_attributes_controller_test.rb index 7415ff49d..470292093 100644 --- a/test/controllers/object_manager_attributes_controller.rb +++ b/test/integration/object_manager_attributes_controller_test.rb @@ -3,6 +3,8 @@ require 'test_helper' require 'rake' class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest + self.use_transactional_tests = false + setup do # set accept header @@ -446,4 +448,110 @@ class ObjectManagerAttributesControllerTest < ActionDispatch::IntegrationTest assert_equal(result['display'], 'Test 7') end + test '01 converts string to boolean for default value for boolean data type with true' do + credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin@example.com', 'adminpw') + + params = { + 'name': "customerdescription#{rand(999_999_999)}", + 'object': 'Ticket', + 'display': "custom description#{rand(999_999_999)}", + 'active': true, + 'data_type': 'boolean', + 'data_option': { + 'options': { + 'true': '', + 'false': '', + }, + 'default': 'true', + 'screens': { + 'create_middle': { + 'ticket.customer': { + 'shown': true, + 'item_class': 'column' + }, + 'ticket.agent': { + 'shown': true, + 'item_class': 'column' + } + }, + 'edit': { + 'ticket.customer': { + 'shown': true + }, + 'ticket.agent': { + 'shown': true + } + } + } + }, + 'id': 'c-201' + } + + post '/api/v1/object_manager_attributes', params: params.to_json, headers: @headers.merge('Authorization' => credentials) + + migration = ObjectManager::Attribute.migration_execute + assert_equal(migration, true) + + assert_response(201) # created + result = JSON.parse(@response.body) + + assert(result) + assert(result['data_option']['default']) + assert_equal(result['data_option']['default'], true) + assert_equal(result['data_type'], 'boolean') + end + + test '02 converts string to boolean for default value for boolean data type with false' do + credentials = ActionController::HttpAuthentication::Basic.encode_credentials('tickets-admin@example.com', 'adminpw') + + params = { + 'name': "customerdescription_#{rand(999_999_999)}", + 'object': 'Ticket', + 'display': "custom description #{rand(999_999_999)}", + 'active': true, + 'data_type': 'boolean', + 'data_option': { + 'options': { + 'true': '', + 'false': '', + }, + 'default': 'false', + 'screens': { + 'create_middle': { + 'ticket.customer': { + 'shown': true, + 'item_class': 'column' + }, + 'ticket.agent': { + 'shown': true, + 'item_class': 'column' + } + }, + 'edit': { + 'ticket.customer': { + 'shown': true + }, + 'ticket.agent': { + 'shown': true + } + } + } + }, + 'id': 'c-202' + } + + post '/api/v1/object_manager_attributes', params: params.to_json, headers: @headers.merge('Authorization' => credentials) + + migration = ObjectManager::Attribute.migration_execute + assert_equal(migration, true) + + assert_response(201) # created + result = JSON.parse(@response.body) + + assert(result) + assert_not(result['data_option']['default']) + assert_equal(result['data_option']['default'], false) + assert_equal(result['data_type'], 'boolean') + end + end