tag tests ruby

This commit is contained in:
Guillermo 2019-02-25 13:34:22 -03:00
parent 1d3d18b345
commit 36d09ec919
5 changed files with 123 additions and 0 deletions

View File

@ -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
*

View File

@ -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'

View File

@ -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

56
tests/ticket/add-tag.rb Normal file
View File

@ -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

View File

@ -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