From 36d09ec919e039238bc5f82d10a5217b4070d3a3 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Mon, 25 Feb 2019 13:34:22 -0300 Subject: [PATCH] tag tests ruby --- server/controllers/ticket/add-tag.php | 1 + tests/init.rb | 2 + tests/scripts.rb | 8 ++++ tests/ticket/add-tag.rb | 56 +++++++++++++++++++++++++++ tests/ticket/remove-tag.rb | 56 +++++++++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 tests/ticket/add-tag.rb create mode 100644 tests/ticket/remove-tag.rb diff --git a/server/controllers/ticket/add-tag.php b/server/controllers/ticket/add-tag.php index 0f5e1e79..425e333b 100644 --- a/server/controllers/ticket/add-tag.php +++ b/server/controllers/ticket/add-tag.php @@ -20,6 +20,7 @@ DataValidator::with('CustomValidations', true); * @apiUse NO_PERMISSION * @apiUse INVALID_TICKET * @apiUse INVALID_TAG + * @apiUse TAG_EXISTS * * @apiSuccess {Object} data Empty object * diff --git a/tests/init.rb b/tests/init.rb index 7e0eaef4..ca0a90b3 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -66,5 +66,7 @@ require './ticket/create-tag.rb' require './ticket/edit-tag.rb' require './ticket/get-tags.rb' require './ticket/delete-tag.rb' +require './ticket/add-tag.rb' +require './ticket/delete-tag.rb' require './system/disable-user-system.rb' require './system/get-stats.rb' diff --git a/tests/scripts.rb b/tests/scripts.rb index 304349d0..309d6bba 100644 --- a/tests/scripts.rb +++ b/tests/scripts.rb @@ -107,4 +107,12 @@ class Scripts description: description }) end + def self.createTag(name, color) + request('/ticket/create-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + name: name, + color: color + }) + end end diff --git a/tests/ticket/add-tag.rb b/tests/ticket/add-tag.rb new file mode 100644 index 00000000..14b765fe --- /dev/null +++ b/tests/ticket/add-tag.rb @@ -0,0 +1,56 @@ +describe '/ticket/add-tag' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + Scripts.createTag('test tag', 'orange') + result = Scripts.createTicket('test ticket') + + @ticketNumber = result['ticketNumber'] + + it 'should fail if the tagId is invalid' do + result = request('/ticket/add-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: 100, + ticketNumber: @ticketNumber + }) + (result['status']).should.equal('fail') + (result['message']).should.equal('INVALID_TAG') + + end + + it 'should fail if the ticketNumber is invalid' do + result = request('/ticket/add-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: 3, + ticketNumber: 0 + }) + (result['status']).should.equal('fail') + (result['message']).should.equal('INVALID_TICKET') + end + + it 'should add a tag' do + result = request('/ticket/add-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: 3, + ticketNumber: @ticketNumber + }) + tag_ticket = $database.getRow('tag_ticket', 3 , 'id') + ticket = $database.getRow('ticket', @ticketNumber ,'ticket_number') + + (result['status']).should.equal('success') + end + + it 'should fail if the tag is already attached' do + result = request('/ticket/add-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: 3, + ticketNumber: @ticketNumber + }) + (result['status']).should.equal('fail') + (result['message']).should.equal('TAG_EXISTS') + end +end diff --git a/tests/ticket/remove-tag.rb b/tests/ticket/remove-tag.rb new file mode 100644 index 00000000..7fb11043 --- /dev/null +++ b/tests/ticket/remove-tag.rb @@ -0,0 +1,56 @@ +describe '/ticket/remove-tag' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + result = $database.getRow('ticket', 'test ticket' , 'title') + tag = $database.getRow('tag', 'test tag', 'name') + + @ticketNumber = result['ticketNumber'] + + it 'should fail if the ticket number is invalid'do + result = request('/ticket/remove-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: tag['id'], + ticketNumber: 0 + }) + (result['status']).should.equal('fail') + (result['message']).should.equal('INVALID_TICKET') + end + + it 'should fail is the tag id is not valid'do + result = request('/ticket/remove-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: 100, + ticketNumber: @ticketNumber + }) + (result['status']).should.equal('fail') + (result['message']).should.equal('INVALID_TAG') + end + + it 'should remove an attached tag' do + result = request('/ticket/remove-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: tag['id'], + ticketNumber: @ticketNumber + }) + + (result['status']).should.equal('success') + + end + + + it 'should fail if the tag is not attached' do + result = request('/ticket/remove-tag', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + tagId: tag['id'], + ticketNumber: @ticketNumber + }) + + (result['status']).should.equal('fail') + (result['message']).should.equal('INVALID_TAG') + end +end