Fix custom tags tests errors

This commit is contained in:
Ivan Diaz 2019-02-14 19:43:22 -03:00
parent ef023d139b
commit 28f26d0956
13 changed files with 121 additions and 270 deletions

View File

@ -16,7 +16,7 @@ $ticketControllers->addController(new ReOpenController);
$ticketControllers->addController(new ChangePriorityController);
$ticketControllers->addController(new SeenController);
$ticketControllers->addController(new DeleteController);
$ticketControllers->addController(new AddTagController);
$ticketControllers->addController(new CreateTagController);
$ticketControllers->addController(new EditTagController);
$ticketControllers->addController(new DeleteTagController);
$ticketControllers->addController(new GetTagsController);

View File

@ -25,8 +25,8 @@ DataValidator::with('CustomValidations', true);
*
*/
class AddTagController extends Controller {
const PATH = '/add-tag';
class CreateTagController extends Controller {
const PATH = '/create-tag';
const METHOD = 'POST';
public function validations() {
@ -42,7 +42,6 @@ class AddTagController extends Controller {
}
public function handler() {
$name = Controller::request('name');
$color = Controller::request('color');

View File

@ -50,7 +50,8 @@ class EditTagController extends Controller {
if($name) $tagInstance->name = $name;
if($color) $tagInstance->color = $color;
if (!Tag::getDataStore($name, 'name')->isNull()) {
$newNameTagInstance = Tag::getDataStore($name, 'name');
if (!$newNameTagInstance ->isNull() && $newNameTagInstance->id !== $tagInstance->id) {
throw new RequestException(ERRORS::TAG_EXISTS);
}

View File

@ -62,9 +62,9 @@ require './system/delete-api-key.rb'
require './system/get-api-keys.rb'
require './system/file-upload-download.rb'
require './system/csv-import.rb'
require './system/disable-user-system.rb'
require './system/get-stats.rb'
require './ticket/add-tag.rb'
require './ticket/create-tag.rb'
require './ticket/edit-tag.rb'
require './ticket/get-tags.rb'
require './ticket/delete-tag.rb'
require './system/disable-user-system.rb'
require './system/get-stats.rb'

View File

@ -20,7 +20,7 @@ class Scripts
departments = request('/system/get-settings', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})['departments']
})['data']['departments']
departments = departments.collect { |x| x.id }
response = request('/staff/add', {

View File

@ -1,114 +0,0 @@
describe '/ticket/add-tag' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
Scripts.createStaff('lvl1@opensupports.com', 'pass1', 'name1','1')
Scripts.createStaff('lvl2@opensupports.com', 'pass2', 'name2','2')
it 'should add a tag if is a Staff 3 logged' do
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'tag1',
color: 'blue'
})
tag = $database.getRow('tag', 1 , 'id')
(request['status']).should.equal('success')
(tag['name']).should.equal('tag1')
end
it 'should add a tag if a Staff 1 is logged' do
request('/user/logout')
Scripts.login('lvl1@opensupports.com', 'pass1',true)
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'tag2',
color: 'red'
})
tag = $database.getRow('tag', 2 , 'id')
(result['status']).should.equal('success')
(tag['name']).should.equal('tag2')
end
it 'should add a tag if a Staff 2 is logged' do
request('/user/logout')
Scripts.login('lvl2@opensupports.com', 'pass2',true)
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'tag3',
color:'green'
})
tag = $database.getRow('tag', 3 , 'id')
(result['status']).should.equal('success')
(tag['name']).should.equal('tag3')
end
it 'should fail if the name is invalid' do
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
color: 'black'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'T',
color: 'black'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
long_text = ''
200.times {long_text << 'a'}
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: long_text,
color: 'black'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'tag1',
color: 'black'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('TAG_EXISTS')
end
it 'should fail if a user is logged' do
request('/user/logout')
Scripts.login()
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'usertag',
color: 'pink'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
request('/user/logout')
end
end

View File

@ -0,0 +1,64 @@
describe '/ticket/create-tag' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
it 'should add a tag' do
result = request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'tag1',
color: 'blue'
})
tag = $database.getRow('tag', 1 , 'id')
(result['status']).should.equal('success')
(tag['name']).should.equal('tag1')
(tag['color']).should.equal('blue')
end
it 'should not add tag if already exits' do
result = request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'tag1',
color: 'blue'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('TAG_EXISTS')
end
it 'should fail if the name is invalid' do
result = request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
color: 'black'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
result = request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'T',
color: 'black'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
long_text = ''
200.times {long_text << 'a'}
result = request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: long_text,
color: 'black'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
end
end

View File

@ -1,8 +1,7 @@
describe '/ticket/delete-tag' do
it 'should fail if a user is logged' do
request('/user/logout')
Scripts.login()
Scripts.login
result = request('/ticket/delete-tag', {
csrf_userid: $csrf_userid,
@ -12,44 +11,17 @@ describe '/ticket/delete-tag' do
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
request('/user/logout')
end
Scripts.login($staff[:email], $staff[:password], true)
it 'should delete a tag if is a Staff 3 logged' do
Scripts.login($staff[:email], $staff[:password], true)
result = request('/ticket/delete-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
tagId: 1
})
(request['status']).should.equal('success')
end
it 'should delete a tag if a Staff 1 is logged' do
request('/user/logout')
Scripts.login('lvl1@opensupports.com', 'pass1',true)
result = request('/ticket/add-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
tagId: 2
})
(result['status']).should.equal('success')
end
it 'should delete a tag if a Staff 2 is logged' do
request('/user/logout')
Scripts.login('lvl2@opensupports.com', 'pass2',true)
result = request('/ticket/delete-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
tagId: 3
})
(result['status']).should.equal('success')
end

View File

@ -1,9 +1,8 @@
describe '/ticket/edit-tag' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
it 'should edit a tag if is a Staff 3 logged' do
it 'should edit a tag' do
result = request('/ticket/edit-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
@ -11,57 +10,26 @@ describe '/ticket/edit-tag' do
name: 'TAG1',
color: 'yellow'
})
(result['status']).should.equal('success')
tag = $database.getRow('tag', 1, 'id')
(tag['name']).should.equal('TAG1')
(tag['color']).should.equal('yellow')
(request['status']).should.equal('success')
end
it 'should edit a tag if a Staff 1 is logged' do
request('/user/logout')
Scripts.login('lvl1@opensupports.com', 'pass1',true)
it 'should fail if the name already exists' do
request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'TAG2',
color: 'blue'
})
result = request('/ticket/edit-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
tagId: 2,
name:'TAG2',
color:'orange'
})
tag = $database.getRow('tag', 2 , 'id')
(result['status']).should.equal('success')
(tag['name']).should.equal('TAG2')
(tag['color']).should.equal('orange')
end
it 'should edit a tag if a Staff 2 is logged' do
request('/user/logout')
Scripts.login('lvl2@opensupports.com', 'pass2',true)
result = request('/ticket/edit-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
tagId: 3,
name: 'TAG3',
color: 'grey'
})
tag = $database.getRow('tag', 3 , 'id')
(tag['name']).should.equal('TAG3')
(tag['color']).should.equal('grey')
(result['status']).should.equal('success')
end
it 'should fail if the name already exists' do
result = request('/ticket/edit-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
tagId: 1,
name: 'TAG1'
})
@ -79,21 +47,4 @@ describe '/ticket/edit-tag' do
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_TAG')
end
it 'should fail if a user is logged' do
request('/user/logout')
Scripts.login()
result = request('/ticket/edit-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
tagId: 1,
name: 'usertag',
color:'pink'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
request('/user/logout')
end
end

View File

@ -1,8 +1,7 @@
describe '/ticket/get-tags' do
it 'should fail if a user is logged' do
request('/user/logout')
Scripts.login()
Scripts.login('steve@jobs.com', 'custompassword')
result = request('/ticket/get-tags', {
csrf_userid: $csrf_userid,
@ -11,60 +10,29 @@ describe '/ticket/get-tags' do
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
request('/user/logout')
end
Scripts.login($staff[:email], $staff[:password], true)
it 'should get the tags if is a Staff 3 logged' do
Scripts.login($staff[:email], $staff[:password], true)
request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'TAG3',
color: 'grey'
})
result = request('/ticket/get-tags', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(request['status']).should.equal('success')
(request['data'][0]['name']).should.equal('TAG1')
(request['data'][0]['color']).should.equal('yellow')
(request['data'][1]['name']).should.equal('TAG2')
(request['data'][1]['color']).should.equal('orange')
(request['data'][2]['name']).should.equal('TAG3')
(request['data'][2]['color']).should.equal('grey')
end
it 'should get the tags if a Staff 1 is logged' do
request('/user/logout')
Scripts.login('lvl1@opensupports.com', 'pass1',true)
result = request('/ticket/get-tags', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(request['status']).should.equal('success')
(request['data'][0]['name']).should.equal('TAG1')
(request['data'][0]['color']).should.equal('yellow')
(request['data'][1]['name']).should.equal('TAG2')
(request['data'][1]['color']).should.equal('orange')
(request['data'][2]['name']).should.equal('TAG3')
(request['data'][2]['color']).should.equal('grey')
end
it 'should get the tags if a Staff 2 is logged' do
request('/user/logout')
Scripts.login('lvl2@opensupports.com', 'pass2',true)
result = request('/ticket/get-tags', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(request['status']).should.equal('success')
(request['data'][0]['name']).should.equal('TAG1')
(request['data'][0]['color']).should.equal('yellow')
(request['data'][1]['name']).should.equal('TAG2')
(request['data'][1]['color']).should.equal('orange')
(request['data'][2]['name']).should.equal('TAG3')
(request['data'][2]['color']).should.equal('grey')
(result['status']).should.equal('success')
(result['data'][0]['name']).should.equal('TAG1')
(result['data'][0]['color']).should.equal('yellow')
(result['data'][1]['name']).should.equal('TAG2')
(result['data'][1]['color']).should.equal('blue')
(result['data'][2]['name']).should.equal('TAG3')
(result['data'][2]['color']).should.equal('grey')
end
end

View File

@ -3,7 +3,7 @@ describe '/user/edit-email' do
request('/user/logout')
result = request('/user/login', {
email: 'steve@jobs.com',
password: 'newpassword'
password: 'custompassword'
})
$csrf_userid = result['data']['userId']
@ -35,5 +35,11 @@ describe '/user/edit-email' do
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
result = request('/user/edit-email', {
newEmail: 'steve@jobs.com',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
end
end

View File

@ -3,7 +3,7 @@ describe '/user/edit-password' do
request('/user/logout')
result = request('/user/login', {
email: 'steve@jobs.com',
password: 'custom'
password: 'custompassword'
})
$csrf_userid = result['data']['userId']
@ -12,7 +12,7 @@ describe '/user/edit-password' do
it 'should fail if new password is incorrect' do
result = request('/user/edit-password', {
oldPassword: 'custom',
oldPassword: 'custompassword',
newPassword: 'np',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
@ -24,7 +24,7 @@ describe '/user/edit-password' do
250.times {long_text << 'a'}
result = request('/user/edit-password', {
oldPassword: 'custom',
oldPassword: 'custompassword',
newPassword: long_text,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
@ -46,7 +46,7 @@ describe '/user/edit-password' do
it 'should change password' do
result = request('/user/edit-password',{
oldPassword: 'custom',
oldPassword: 'custompassword',
newPassword: 'newpassword',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
@ -55,9 +55,13 @@ describe '/user/edit-password' do
request('/user/logout')
result = request('/user/login',{
email: 'steve@jobs.com',
password: 'newpassword'
Scripts.login('steve@jobs.com','newpassword')
result = request('/user/edit-password',{
oldPassword: 'newpassword',
newPassword: 'custompassword',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
end

View File

@ -3,7 +3,7 @@ describe '/user/signup' do
response = request('/user/signup', {
:name => 'Steve Jobs',
:email => 'steve@jobs.com',
:password => 'custom'
:password => 'custompassword'
})
userRow = $database.getRow('user', response['data']['userId'])