[DEV-26] Update length validations (#1075)

* Update length validations

* Fix language validations

* Remove unnecessary import

* Delete some semicolons
This commit is contained in:
LautaroCesso 2021-11-11 17:17:39 -03:00 committed by GitHub
parent c5f1aa2b92
commit d7ccff1a5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 151 additions and 118 deletions

View File

@ -36,8 +36,8 @@ class AddTopicController extends Controller {
'permission' => 'staff_2', 'permission' => 'staff_2',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_TITLE 'error' => ERRORS::INVALID_NAME
], ],
] ]
]; ];

View File

@ -14,7 +14,7 @@ DataValidator::with('CustomValidations', true);
* *
* @apiPermission staff2 * @apiPermission staff2
* *
* @apiParam {String} title Title of the new article. * @apiParam {String} name Name of the new article.
* @apiParam {String} content Content of the new article. * @apiParam {String} content Content of the new article.
* @apiParam {Number} position Position of the new article. * @apiParam {Number} position Position of the new article.
* @apiParam {Number} topicId Id of the articles's topic. * @apiParam {Number} topicId Id of the articles's topic.
@ -39,8 +39,8 @@ class AddArticleController extends Controller {
return [ return [
'permission' => 'staff_2', 'permission' => 'staff_2',
'requestData' => [ 'requestData' => [
'title' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(1, 100), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
'content' => [ 'content' => [
@ -64,7 +64,7 @@ class AddArticleController extends Controller {
$article = new Article(); $article = new Article();
$article->setProperties([ $article->setProperties([
'title' => Controller::request('title', true), 'title' => Controller::request('name', true),
'content' => $this->replaceWithImagePaths($imagePaths, $content), 'content' => $this->replaceWithImagePaths($imagePaths, $content),
'lastEdited' => Date::getCurrentDate(), 'lastEdited' => Date::getCurrentDate(),
'position' => Controller::request('position') || 1 'position' => Controller::request('position') || 1

View File

@ -40,7 +40,7 @@ class EditTopicController extends Controller {
'error' => ERRORS::INVALID_TOPIC 'error' => ERRORS::INVALID_TOPIC
], ],
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],

View File

@ -17,7 +17,7 @@ DataValidator::with('CustomValidations', true);
* @apiParam {Number} articleId Id of the article. * @apiParam {Number} articleId Id of the article.
* @apiParam {Number} topicId Id of the topic of the article. Optional. * @apiParam {Number} topicId Id of the topic of the article. Optional.
* @apiParam {String} content The new content of the article. Optional. * @apiParam {String} content The new content of the article. Optional.
* @apiParam {String} title The new title of the article. Optional. * @apiParam {String} name The new name of the article. Optional.
* @apiParam {Number} position The new position of the article. Optional. * @apiParam {Number} position The new position of the article. Optional.
* @apiParam {Number} images The number of images in the content * @apiParam {Number} images The number of images in the content
* @apiParam image_i The image file of index `i` (mutiple params accepted) * @apiParam image_i The image file of index `i` (mutiple params accepted)
@ -42,9 +42,12 @@ class EditArticleController extends Controller {
'validation' => DataValidator::dataStoreId('article'), 'validation' => DataValidator::dataStoreId('article'),
'error' => ERRORS::INVALID_TOPIC 'error' => ERRORS::INVALID_TOPIC
], ],
'title' => [ 'name' => [
'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(1, 200),DataValidator::nullType()), 'validation' => DataValidator::oneOf(
'error' => ERRORS::INVALID_TITLE DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
DataValidator::nullType()
),
'error' => ERRORS::INVALID_NAME
], ],
'content' => [ 'content' => [
'validation' => DataValidator::oneOf(DataValidator::content(),DataValidator::nullType()), 'validation' => DataValidator::oneOf(DataValidator::content(),DataValidator::nullType()),
@ -78,8 +81,8 @@ class EditArticleController extends Controller {
$article->content = $this->replaceWithImagePaths($imagePaths, $content); $article->content = $this->replaceWithImagePaths($imagePaths, $content);
} }
if(Controller::request('title')) { if(Controller::request('name')) {
$article->title = Controller::request('title'); $article->title = Controller::request('name');
} }
if(Controller::request('position')) { if(Controller::request('position')) {

View File

@ -42,7 +42,10 @@ class EditStaffController extends Controller {
'error' => ERRORS::INVALID_EMAIL 'error' => ERRORS::INVALID_EMAIL
], ],
'password' => [ 'password' => [
'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(5, 200), DataValidator::falseVal()), 'validation' => DataValidator::oneOf(
DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD),
DataValidator::falseVal()
),
'error' => ERRORS::INVALID_PASSWORD 'error' => ERRORS::INVALID_PASSWORD
], ],
'level' => [ 'level' => [

View File

@ -48,7 +48,7 @@ class InviteStaffController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 55), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
'email' => [ 'email' => [

View File

@ -35,7 +35,7 @@ class SearchTicketStaffController extends Controller {
'permission' => 'staff_1', 'permission' => 'staff_1',
'requestData' => [ 'requestData' => [
'query' => [ 'query' => [
'validation' => DataValidator::notBlank()->length(1), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_QUERY),
'error' => ERRORS::INVALID_QUERY 'error' => ERRORS::INVALID_QUERY
], ],
'page' => [ 'page' => [

View File

@ -35,7 +35,7 @@ class AddAPIKeyController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 55)->alnum(), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME)->alnum(),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
] ]
] ]

View File

@ -37,11 +37,11 @@ class AddCustomFieldController extends Controller {
'permission' => 'staff_2', 'permission' => 'staff_2',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 100), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
'description' => [ 'description' => [
'validation' => DataValidator::notBlank()->length(2, 100), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_DESCRIPTION, LengthConfig::MAX_LENGTH_DESCRIPTION),
'error' => ERRORS::INVALID_DESCRIPTION 'error' => ERRORS::INVALID_DESCRIPTION
], ],
'type' => [ 'type' => [

View File

@ -31,7 +31,7 @@ class AddDepartmentController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 100), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
] ]
] ]

View File

@ -31,7 +31,7 @@ class DeleteAPIKeyController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 55), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
] ]
] ]

View File

@ -39,7 +39,7 @@ class EditDepartmentController extends Controller {
'error' => ERRORS::INVALID_DEPARTMENT 'error' => ERRORS::INVALID_DEPARTMENT
], ],
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
] ]

View File

@ -46,15 +46,15 @@ class EditMailTemplateController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'template' => [ 'template' => [
'validation' => DataValidator::notBlank()->length(4), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TEMPLATE),
'error' => ERRORS::INVALID_TEMPLATE 'error' => ERRORS::INVALID_TEMPLATE
], ],
'language' => [ 'language' => [
'validation' => DataValidator::notBlank()->length(2,2), 'validation' => DataValidator::oneOf(DataValidator::in(Language::getSupportedLanguages()), DataValidator::nullType()),
'error' => ERRORS::INVALID_LANGUAGE 'error' => ERRORS::INVALID_LANGUAGE
], ],
'subject' => [ 'subject' => [
'validation' => DataValidator::notBlank()->length(4), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_SUBJECT),
'error' => ERRORS::INVALID_SUBJECT 'error' => ERRORS::INVALID_SUBJECT
], ],
] ]

View File

@ -12,7 +12,7 @@ class EmailPollingController extends Controller {
'permission' => 'any', 'permission' => 'any',
'requestData' => [ 'requestData' => [
'token' => [ 'token' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TOKEN, LengthConfig::MAX_LENGTH_TOKEN),
'error' => ERRORS::INVALID_TOKEN 'error' => ERRORS::INVALID_TOKEN
] ]
] ]

View File

@ -31,11 +31,11 @@ class GetMailTemplateController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'template' => [ 'template' => [
'validation' => DataValidator::notBlank()->length(4), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TEMPLATE),
'error' => ERRORS::INVALID_TEMPLATE 'error' => ERRORS::INVALID_TEMPLATE
], ],
'language' => [ 'language' => [
'validation' => DataValidator::notBlank()->length(2, 2), 'validation' => DataValidator::oneOf(DataValidator::in(Language::getSupportedLanguages()), DataValidator::nullType()),
'error' => ERRORS::INVALID_LANGUAGE 'error' => ERRORS::INVALID_LANGUAGE
], ],
] ]

View File

@ -36,7 +36,7 @@ class InitAdminController extends Controller {
'permission' => 'any', 'permission' => 'any',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 55), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
'email' => [ 'email' => [
@ -44,7 +44,7 @@ class InitAdminController extends Controller {
'error' => ERRORS::INVALID_EMAIL 'error' => ERRORS::INVALID_EMAIL
], ],
'password' => [ 'password' => [
'validation' => DataValidator::notBlank()->length(5, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD),
'error' => ERRORS::INVALID_PASSWORD 'error' => ERRORS::INVALID_PASSWORD
], ],
] ]

View File

@ -33,11 +33,11 @@ class RecoverMailTemplateController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'template' => [ 'template' => [
'validation' => DataValidator::notBlank()->length(4), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TEMPLATE),
'error' => ERRORS::INVALID_TEMPLATE 'error' => ERRORS::INVALID_TEMPLATE
], ],
'language' => [ 'language' => [
'validation' => DataValidator::notBlank()->length(2, 2), 'validation' => DataValidator::oneOf(DataValidator::in(Language::getSupportedLanguages()), DataValidator::nullType()),
'error' => ERRORS::INVALID_LANGUAGE 'error' => ERRORS::INVALID_LANGUAGE
], ],
] ]

View File

@ -36,7 +36,7 @@ class AddCustomResponseController extends Controller {
'permission' => 'staff_2', 'permission' => 'staff_2',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(5, 100), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_TITLE 'error' => ERRORS::INVALID_TITLE
], ],
'content' => [ 'content' => [

View File

@ -34,7 +34,7 @@ class CreateTagController extends Controller {
'permission' => 'staff_3', 'permission' => 'staff_3',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 100), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
'color' => [ 'color' => [

View File

@ -56,7 +56,7 @@ class CreateController extends Controller {
'permission' => 'user', 'permission' => 'user',
'requestData' => [ 'requestData' => [
'title' => [ 'title' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE),
'error' => ERRORS::INVALID_TITLE 'error' => ERRORS::INVALID_TITLE
], ],
'content' => [ 'content' => [
@ -84,7 +84,7 @@ class CreateController extends Controller {
'error' => ERRORS::INVALID_EMAIL 'error' => ERRORS::INVALID_EMAIL
]; ];
$validations['requestData']['name'] = [ $validations['requestData']['name'] = [
'validation' => DataValidator::notBlank()->length(2, 55), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
]; ];
} }

View File

@ -36,14 +36,17 @@ class EditCustomResponseController extends Controller {
'requestData' => [ 'requestData' => [
'id' => [ 'id' => [
'validation' => DataValidator::dataStoreId('customresponse'), 'validation' => DataValidator::dataStoreId('customresponse'),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_CUSTOM_RESPONSE
], ],
'content' => [ 'content' => [
'validation' => DataValidator::content(), 'validation' => DataValidator::content(),
'error' => ERRORS::INVALID_CONTENT 'error' => ERRORS::INVALID_CONTENT
], ],
'name' => [ 'name' => [
'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(1, 200),DataValidator::nullType()), 'validation' => DataValidator::oneOf(
DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
DataValidator::nullType()
),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
] ]

View File

@ -43,7 +43,7 @@ class EditTagController extends Controller {
'error' => ERRORS::INVALID_COLOR 'error' => ERRORS::INVALID_COLOR
], ],
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
] ]
] ]

View File

@ -34,7 +34,7 @@ class EditTitleController extends Controller {
'permission' => 'user', 'permission' => 'user',
'requestData' => [ 'requestData' => [
'title' => [ 'title' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_TITLE, LengthConfig::MAX_LENGTH_TITLE),
'error' => ERRORS::INVALID_TITLE 'error' => ERRORS::INVALID_TITLE
], ],
'ticketNumber' => [ 'ticketNumber' => [

View File

@ -33,7 +33,7 @@ class EditPassword extends Controller {
'permission' => 'user', 'permission' => 'user',
'requestData' => [ 'requestData' => [
'newPassword' => [ 'newPassword' => [
'validation' => DataValidator::notBlank()->length(5, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD),
'error' => ERRORS::INVALID_PASSWORD 'error' => ERRORS::INVALID_PASSWORD
] ]
] ]

View File

@ -45,7 +45,7 @@ class InviteUserController extends Controller {
'permission' => 'staff_1', 'permission' => 'staff_1',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 55), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
'email' => [ 'email' => [

View File

@ -47,7 +47,7 @@ class RecoverPasswordController extends Controller {
'error' => ERRORS::INVALID_EMAIL 'error' => ERRORS::INVALID_EMAIL
], ],
'password' => [ 'password' => [
'validation' => DataValidator::notBlank()->length(5, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD),
'error' => ERRORS::INVALID_PASSWORD 'error' => ERRORS::INVALID_PASSWORD
] ]
] ]

View File

@ -56,7 +56,7 @@ class SignUpController extends Controller {
'permission' => 'any', 'permission' => 'any',
'requestData' => [ 'requestData' => [
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(2, 55), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
'email' => [ 'email' => [
@ -64,7 +64,7 @@ class SignUpController extends Controller {
'error' => ERRORS::INVALID_EMAIL 'error' => ERRORS::INVALID_EMAIL
], ],
'password' => [ 'password' => [
'validation' => DataValidator::notBlank()->length(5, 200), 'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_PASSWORD, LengthConfig::MAX_LENGTH_PASSWORD),
'error' => ERRORS::INVALID_PASSWORD 'error' => ERRORS::INVALID_PASSWORD
] ]
] ]

View File

@ -405,6 +405,7 @@ class ERRORS {
const UNAVAILABLE_STATS = 'UNAVAILABLE_STATS'; const UNAVAILABLE_STATS = 'UNAVAILABLE_STATS';
const INVALID_COLOR = 'INVALID_COLOR'; const INVALID_COLOR = 'INVALID_COLOR';
const INVALID_API_KEY_PERMISSION = 'INVALID_API_KEY_PERMISSION'; const INVALID_API_KEY_PERMISSION = 'INVALID_API_KEY_PERMISSION';
const INVALID_CUSTOM_RESPONSE = 'INVALID_CUSTOM_RESPONSE';
const MANDATORY_LOGIN_IS_DESACTIVATED = 'MANDATORY_LOGIN_IS_DESACTIVATED'; const MANDATORY_LOGIN_IS_DESACTIVATED = 'MANDATORY_LOGIN_IS_DESACTIVATED';
const REGISTRATION_IS_DESACTIVATED = 'REGISTRATION_IS_DESACTIVATED'; const REGISTRATION_IS_DESACTIVATED = 'REGISTRATION_IS_DESACTIVATED';
const INVALID_SUPERVISED_USERS = 'INVALID_SUPERVISED_USERS'; const INVALID_SUPERVISED_USERS = 'INVALID_SUPERVISED_USERS';

View File

@ -0,0 +1,25 @@
<?php
class LengthConfig {
const MIN_LENGTH_NAME = 1;
const MAX_LENGTH_NAME = 200;
const MIN_LENGTH_TITLE = 1;
const MAX_LENGTH_TITLE = 200;
const MIN_LENGTH_PASSWORD = 6;
const MAX_LENGTH_PASSWORD = 200;
const MIN_LENGTH_DESCRIPTION = 2;
const MAX_LENGTH_DESCRIPTION = 100;
const MIN_LENGTH_TOKEN = 1;
const MAX_LENGTH_TOKEN = 200;
const MIN_LENGTH_QUERY = 1;
const MIN_LENGTH_SUBJECT = 4;
const MIN_LENGTH_TEMPLATE = 4;
}

View File

@ -28,7 +28,7 @@ describe 'Article path' do
it 'should create article' do it 'should create article' do
result = request('/article/add', { result = request('/article/add', {
title: 'Some article', name: 'Some article',
content: 'This is an article about server management.', content: 'This is an article about server management.',
topicId: @topic_id, topicId: @topic_id,
position: 1, position: 1,
@ -108,7 +108,7 @@ describe 'Article path' do
it 'should retrieve all articles' do it 'should retrieve all articles' do
request('/article/add', { request('/article/add', {
title: 'Some article', name: 'Some article',
content: 'This is an article about server management.', content: 'This is an article about server management.',
topicId: @topic_id, topicId: @topic_id,
position: 1, position: 1,

View File

@ -53,7 +53,7 @@ class Database
end end
def query(query_string) def query(query_string)
return @connection.query(query_string); return @connection.query(query_string)
end end
end end
@ -153,6 +153,6 @@ $database = Database.new
# $mail_server.check # $mail_server.check
$staff = { $staff = {
:email => 'staff@opensupports.com', :email => 'admin@opensupports.com',
:password => 'staff' :password => 'admin22'
} }

View File

@ -15,7 +15,7 @@ describe'/staff/get-all' do
end end
(result['data'][0]['name']).should.equal('Emilia Clarke') (result['data'][0]['name']).should.equal('Emilia Clarke')
(result['data'][0]['email']).should.equal('staff@opensupports.com') (result['data'][0]['email']).should.equal($staff[:email])
(result['data'][0]['profilePic']).should.equal('') (result['data'][0]['profilePic']).should.equal('')
(result['data'][0]['level']).should.equal('3') (result['data'][0]['level']).should.equal('3')
(result['data'][0]['departments'][0]['id']).should.equal('1') (result['data'][0]['departments'][0]['id']).should.equal('1')

View File

@ -11,7 +11,7 @@ describe '/staff/get/' do
(result['status']).should.equal('success') (result['status']).should.equal('success')
(result['data']['name']).should.equal('Emilia Clarke') (result['data']['name']).should.equal('Emilia Clarke')
(result['data']['staff']).should.equal(true) (result['data']['staff']).should.equal(true)
(result['data']['email']).should.equal('staff@opensupports.com') (result['data']['email']).should.equal($staff[:email])
(result['data']['level']).should.equal('3') (result['data']['level']).should.equal('3')
(result['data']['sendEmailOnNewTicket']).should.equal('1') (result['data']['sendEmailOnNewTicket']).should.equal('1')
end end

View File

@ -55,7 +55,7 @@ describe'/staff/invite' do
result = request('/staff/invite', { result = request('/staff/invite', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'Tyrion LannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannister', name: 'Tyrion LannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannister',
email: 'tyrion@opensupports.com', email: 'tyrion@opensupports.com',
level: 1, level: 1,
profilePic: '', profilePic: '',
@ -67,7 +67,7 @@ describe'/staff/invite' do
result = request('/staff/invite', { result = request('/staff/invite', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'T', name: '',
email: 'tyrion@opensupports.com', email: 'tyrion@opensupports.com',
level: 1, level: 1,
profilePic: '', profilePic: '',

View File

@ -34,7 +34,7 @@ describe'system/add-api-key' do
result= request('/system/add-api-key', { result= request('/system/add-api-key', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'A', name: '',
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('fail')
@ -43,7 +43,7 @@ describe'system/add-api-key' do
result= request('/system/add-api-key', { result= request('/system/add-api-key', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'APIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAME', name: 'APIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAMEAPIKEYNAME',
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('fail')

View File

@ -11,7 +11,7 @@ describe '/system/apikey-permissions' do
request('/system/disable-mandatory-login', { request('/system/disable-mandatory-login', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,
"csrf_token" => $csrf_token, "csrf_token" => $csrf_token,
"password" => "staff" "password" => $staff[:password]
}) })
request('/system/edit-settings', { request('/system/edit-settings', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,

View File

@ -8,7 +8,7 @@ describe 'Custom fields' do
result = request('/system/add-custom-field', { result = request('/system/add-custom-field', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'A', name: '',
type: 'text', type: 'text',
description: 'custom field description', description: 'custom field description',
options: nil options: nil
@ -21,7 +21,7 @@ describe 'Custom fields' do
it 'should fail if the name is to long' do it 'should fail if the name is to long' do
long_text = '' long_text = ''
101.times {long_text << 'A'} 201.times {long_text << 'A'}
result = request('/system/add-custom-field', { result = request('/system/add-custom-field', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,

View File

@ -1,10 +1,10 @@
describe '/system/default-department' do describe '/system/default-department' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
it 'should fail if try to turn a private department default' do it 'should fail if try to turn a private department default' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
privatedepartment = $database.getRow('department', 1, 'private') privatedepartment = $database.getRow('department', 1, 'private')
@ -47,7 +47,7 @@ describe '/system/default-department' do
it 'should set a new default deparment' do it 'should set a new default deparment' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
publicdepartment = $database.getRow('department', 'Suggestions', 'name') publicdepartment = $database.getRow('department', 'Suggestions', 'name')
@ -62,7 +62,7 @@ describe '/system/default-department' do
it 'should fail if try to delete the default department' do it 'should fail if try to delete the default department' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
defaultDepartment = $database.getRow('setting', 'default-department-id', 'name') defaultDepartment = $database.getRow('setting', 'default-department-id', 'name')
transferDepartment = $database.getRow('department','<b>new department</b>','name') transferDepartment = $database.getRow('department','<b>new department</b>','name')
@ -80,7 +80,8 @@ describe '/system/default-department' do
it 'should fail if try to edit default department into private' do it 'should fail if try to edit default department into private' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
defaultDepartmentId = $database.getRow('setting', 'default-department-id', 'name') defaultDepartmentId = $database.getRow('setting', 'default-department-id', 'name')
department = $database.getRow('department',defaultDepartmentId['value'],'id') department = $database.getRow('department',defaultDepartmentId['value'],'id')
@ -98,7 +99,7 @@ describe '/system/default-department' do
it 'should create ticket in default department if Staff does not give department with locked on' do it 'should create ticket in default department if Staff does not give department with locked on' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.updateLockedDepartmentSetting(1) Scripts.updateLockedDepartmentSetting(1)
result = request('/ticket/create', { result = request('/ticket/create', {
@ -117,7 +118,7 @@ describe '/system/default-department' do
it 'should create ticket in default department if staff does not give department with locked off'do it 'should create ticket in default department if staff does not give department with locked off'do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.updateLockedDepartmentSetting(0) Scripts.updateLockedDepartmentSetting(0)
result = request('/ticket/create', { result = request('/ticket/create', {
@ -136,7 +137,7 @@ describe '/system/default-department' do
it 'should create ticket in selected department if staff give department and lockd is off'do it 'should create ticket in selected department if staff give department and lockd is off'do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.updateLockedDepartmentSetting(0) Scripts.updateLockedDepartmentSetting(0)
result = request('/ticket/create', { result = request('/ticket/create', {
@ -155,7 +156,7 @@ describe '/system/default-department' do
it 'should create ticket in selected department if staff give department and locked is on' do it 'should create ticket in selected department if staff give department and locked is on' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.updateLockedDepartmentSetting(1) Scripts.updateLockedDepartmentSetting(1)
result = request('/ticket/create', { result = request('/ticket/create', {
@ -173,9 +174,8 @@ describe '/system/default-department' do
end end
it 'should create ticket on default department if user does not give department and locked is on' do it 'should create ticket on default department if user does not give department and locked is on' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.updateLockedDepartmentSetting(1) Scripts.updateLockedDepartmentSetting(1)
Scripts.logout() Scripts.logout()
@ -198,9 +198,8 @@ describe '/system/default-department' do
end end
it 'should create ticket on default department if user does not give department and locked is off'do it 'should create ticket on default department if user does not give department and locked is off'do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.updateLockedDepartmentSetting(0) Scripts.updateLockedDepartmentSetting(0)
Scripts.logout() Scripts.logout()
@ -221,9 +220,8 @@ describe '/system/default-department' do
end end
it 'should create ticket on selected department if user give department and locked is off'do it 'should create ticket on selected department if user give department and locked is off'do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.updateLockedDepartmentSetting(0) Scripts.updateLockedDepartmentSetting(0)
Scripts.logout() Scripts.logout()

View File

@ -93,7 +93,7 @@ describe'system/edit-settings' do
(lastLog['type']).should.equal('EDIT_SETTINGS') (lastLog['type']).should.equal('EDIT_SETTINGS')
Scripts.updateLockedDepartmentSetting(0); Scripts.updateLockedDepartmentSetting(0)
Scripts.logout() Scripts.logout()
end end
@ -102,7 +102,7 @@ describe'system/edit-settings' do
Scripts.login($staff[:email], $staff[:password], true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.createTicket('TicketToDeleteWithoutUsersCreated') Scripts.createTicket('TicketToDeleteWithoutUsersCreated')
ticket = $database.getRow('ticket', 'TicketToDeleteWithoutUsersCreated', 'title'); ticket = $database.getRow('ticket', 'TicketToDeleteWithoutUsersCreated', 'title')
result = request('/ticket/delete', { result = request('/ticket/delete', {
ticketNumber: ticket['ticket_number'], ticketNumber: ticket['ticket_number'],

View File

@ -40,7 +40,7 @@ describe 'File Upload and Download' do
it 'should download if department owner is logged' do it 'should download if department owner is logged' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
ticket = $database.getLastRow('ticket') ticket = $database.getLastRow('ticket')
file = File.open("../server/files/" + ticket['file']) file = File.open("../server/files/" + ticket['file'])

View File

@ -21,12 +21,12 @@ describe'system/mandatory-login' do
request('/system/disable-registration', { request('/system/disable-registration', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,
"csrf_token" => $csrf_token, "csrf_token" => $csrf_token,
"password" => "staff" "password" => $staff[:password]
}) })
result = request('/system/disable-mandatory-login', { result = request('/system/disable-mandatory-login', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,
"csrf_token" => $csrf_token, "csrf_token" => $csrf_token,
"password" => "staff" "password" => $staff[:password]
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('fail')
@ -38,7 +38,7 @@ describe'system/mandatory-login' do
request('/system/enable-registration', { request('/system/enable-registration', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,
"csrf_token" => $csrf_token, "csrf_token" => $csrf_token,
"password" => "staff" "password" => $staff[:password]
}) })
end end
@ -59,7 +59,7 @@ describe'system/mandatory-login' do
result = request('/system/disable-mandatory-login', { result = request('/system/disable-mandatory-login', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,
"csrf_token" => $csrf_token, "csrf_token" => $csrf_token,
"password" => "staff" "password" => $staff[:password]
}) })
(result['status']).should.equal('success') (result['status']).should.equal('success')
@ -73,7 +73,7 @@ describe'system/mandatory-login' do
result = request('/system/disable-registration', { result = request('/system/disable-registration', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,
"csrf_token" => $csrf_token, "csrf_token" => $csrf_token,
"password" => "staff" "password" => $staff[:password]
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('fail')
@ -358,7 +358,7 @@ describe'system/mandatory-login' do
result = request('/system/enable-mandatory-login', { result = request('/system/enable-mandatory-login', {
"csrf_userid" => $csrf_userid, "csrf_userid" => $csrf_userid,
"csrf_token" => $csrf_token, "csrf_token" => $csrf_token,
"password" => "staff" "password" => $staff[:password]
}) })
(result['status']).should.equal('success') (result['status']).should.equal('success')

View File

@ -41,7 +41,7 @@ describe '/ticket/create-tag' do
result = request('/ticket/create-tag', { result = request('/ticket/create-tag', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'T', name: '',
color: '#0000ff' color: '#0000ff'
}) })
@ -49,7 +49,7 @@ describe '/ticket/create-tag' do
(result['message']).should.equal('INVALID_NAME') (result['message']).should.equal('INVALID_NAME')
long_text = '' long_text = ''
200.times {long_text << 'a'} 201.times {long_text << 'a'}
result = request('/ticket/create-tag', { result = request('/ticket/create-tag', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,

View File

@ -79,7 +79,7 @@ describe '/ticket/create' do
end end
it 'should fail if an user tries to create a ticket with a private department' do it 'should fail if an user tries to create a ticket with a private department' do
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
result = request('/system/add-department', { result = request('/system/add-department', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,

View File

@ -1,6 +1,6 @@
describe 'CustomResponses' do describe 'CustomResponses' do
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
describe '/ticket/add-custom-responses/' do describe '/ticket/add-custom-responses/' do
it 'should create custom response' do it 'should create custom response' do

View File

@ -42,7 +42,7 @@ describe '/ticket/delete' do
Scripts.login('deleter@opensupports.com', 'deleterpassword') Scripts.login('deleter@opensupports.com', 'deleterpassword')
Scripts.createTicket('ticket_to_delete_2') Scripts.createTicket('ticket_to_delete_2')
ticket = $database.getRow('ticket', 'ticket_to_delete_2', 'title'); ticket = $database.getRow('ticket', 'ticket_to_delete_2', 'title')
result = request('/ticket/delete', { result = request('/ticket/delete', {
ticketNumber: ticket['ticket_number'], ticketNumber: ticket['ticket_number'],
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
@ -56,7 +56,7 @@ describe '/ticket/delete' do
Scripts.login('deleter@opensupports.com', 'deleterpassword') Scripts.login('deleter@opensupports.com', 'deleterpassword')
Scripts.createTicket('ticket_to_delete_3') Scripts.createTicket('ticket_to_delete_3')
ticket = $database.getRow('ticket', 'ticket_to_delete_3', 'title'); ticket = $database.getRow('ticket', 'ticket_to_delete_3', 'title')
Scripts.logout() Scripts.logout()
Scripts.login($staff[:email], $staff[:password], true) Scripts.login($staff[:email], $staff[:password], true)
@ -85,7 +85,7 @@ describe '/ticket/delete' do
Scripts.login($staff[:email], $staff[:password], true) Scripts.login($staff[:email], $staff[:password], true)
Scripts.createTicket('ticket_to_delete_4') Scripts.createTicket('ticket_to_delete_4')
ticket = $database.getRow('ticket', 'ticket_to_delete_4', 'title'); ticket = $database.getRow('ticket', 'ticket_to_delete_4', 'title')
request('/staff/invite', { request('/staff/invite', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,

View File

@ -1,7 +1,7 @@
describe '/ticket/edit-comment' do describe '/ticket/edit-comment' do
Scripts.logout() Scripts.logout()
Scripts.login(); Scripts.login()
Scripts.createTicket('ticket made by an user','content of the ticket made by an user') Scripts.createTicket('ticket made by an user','content of the ticket made by an user')
ticket = $database.getRow('ticket', 'ticket made by an user', 'title') ticket = $database.getRow('ticket', 'ticket made by an user', 'title')
Scripts.commentTicket(ticket['ticket_number'],'com ment of a user') Scripts.commentTicket(ticket['ticket_number'],'com ment of a user')
@ -81,7 +81,7 @@ describe '/ticket/edit-comment' do
ticketevent = $database.getRow('ticketevent', 'this is a new comment of a staff member', 'content') ticketevent = $database.getRow('ticketevent', 'this is a new comment of a staff member', 'content')
Scripts.logout() Scripts.logout()
Scripts.login(); Scripts.login()
result = request('/ticket/edit-comment', { result = request('/ticket/edit-comment', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,

View File

@ -1,7 +1,7 @@
describe '/ticket/edit-title' do describe '/ticket/edit-title' do
Scripts.logout() Scripts.logout()
Scripts.login(); Scripts.login()
Scripts.createTicket('Valar Morghulis','content of the ticket made by an user') Scripts.createTicket('Valar Morghulis','content of the ticket made by an user')
ticket = $database.getRow('ticket', 'Valar Morghulis', 'title') ticket = $database.getRow('ticket', 'Valar Morghulis', 'title')
ticketNumber = ticket['ticket_number'] ticketNumber = ticket['ticket_number']

View File

@ -80,7 +80,7 @@ describe '/ticket/get-authors/' do
end end
it 'should succed if you try to get a staff' do it 'should succed if you try to get a staff' do
staffauthor = $database.getRow('staff', 'staff@opensupports.com', 'email') staffauthor = $database.getRow('staff', $staff[:email], 'email')
authorsstring = '[{"isStaff":1,"id":' authorsstring = '[{"isStaff":1,"id":'
authorsstring.concat(staffauthor['id'].to_s) authorsstring.concat(staffauthor['id'].to_s)
authorsstring.concat('}]') authorsstring.concat('}]')
@ -98,7 +98,7 @@ describe '/ticket/get-authors/' do
end end
it 'should succed if you try to get a staff and a user' do it 'should succed if you try to get a staff and a user' do
userauthor = $database.getRow('user', 'userauthor@os4.com', 'email') userauthor = $database.getRow('user', 'userauthor@os4.com', 'email')
staffauthor = $database.getRow('staff', 'staff@opensupports.com', 'email') staffauthor = $database.getRow('staff', $staff[:email], 'email')
authorsstring = '[{"isStaff":1,"id":' authorsstring = '[{"isStaff":1,"id":'
authorsstring.concat(staffauthor['id'].to_s) authorsstring.concat(staffauthor['id'].to_s)
authorsstring.concat('},{"isStaff":0,"id":') authorsstring.concat('},{"isStaff":0,"id":')
@ -121,7 +121,7 @@ describe '/ticket/get-authors/' do
end end
it 'should succed if you try to get a author without duplicate' do it 'should succed if you try to get a author without duplicate' do
staffauthor = $database.getRow('staff', 'staff@opensupports.com', 'email') staffauthor = $database.getRow('staff', $staff[:email], 'email')
authorsstring = '[{"isStaff":1,"id":' authorsstring = '[{"isStaff":1,"id":'
authorsstring.concat(staffauthor['id'].to_s) authorsstring.concat(staffauthor['id'].to_s)
authorsstring.concat('},{"isStaff":1,"id":') authorsstring.concat('},{"isStaff":1,"id":')

View File

@ -2,8 +2,8 @@ describe '/user/ban' do
Scripts.logout() Scripts.logout()
result = request('/user/login', { result = request('/user/login', {
email: 'staff@opensupports.com', email: $staff[:email],
password: 'staff', password: $staff[:password],
staff: true staff: true
}) })
(result['status']).should.equal('success') (result['status']).should.equal('success')

View File

@ -7,7 +7,7 @@ describe '/user/delete' do
Scripts.createTicket('Ticket that will be deleted') Scripts.createTicket('Ticket that will be deleted')
Scripts.logout() Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true) Scripts.login($staff[:email], $staff[:password], true)
ticket = $database.getLastRow('ticket') ticket = $database.getLastRow('ticket')
deletable_user = $database.getLastRow('user') deletable_user = $database.getLastRow('user')

View File

@ -1,9 +1,9 @@
describe 'Enable/disable user' do describe 'Enable/disable user' do
user = $database.getRow('user', 'login@os4.com', 'email'); user = $database.getRow('user', 'login@os4.com', 'email')
describe '/user/disable' do describe '/user/disable' do
Scripts.logout(); Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true); Scripts.login($staff[:email], $staff[:password], true)
it 'should disable user' do it 'should disable user' do
result = request('/user/disable', { result = request('/user/disable', {
@ -12,7 +12,7 @@ describe 'Enable/disable user' do
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
}) })
(result['status']).should.equal('success'); (result['status']).should.equal('success')
end end
it 'should not disable user if already disabled' do it 'should not disable user if already disabled' do
@ -22,12 +22,12 @@ describe 'Enable/disable user' do
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
}) })
(result['status']).should.equal('fail'); (result['status']).should.equal('fail')
(result['message']).should.equal('ALREADY_DISABLED') (result['message']).should.equal('ALREADY_DISABLED')
end end
it 'should reject login' do it 'should reject login' do
Scripts.logout(); Scripts.logout()
result = request('/user/login', { result = request('/user/login', {
email: 'login@os4.com', email: 'login@os4.com',
password: 'loginpass' password: 'loginpass'
@ -39,8 +39,8 @@ describe 'Enable/disable user' do
end end
describe '/user/enable' do describe '/user/enable' do
Scripts.logout(); Scripts.logout()
Scripts.login('staff@opensupports.com', 'staff', true); Scripts.login($staff[:email], $staff[:password], true)
it 'should enable user' do it 'should enable user' do
result = request('/user/enable', { result = request('/user/enable', {
@ -49,7 +49,7 @@ describe 'Enable/disable user' do
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
}) })
(result['status']).should.equal('success'); (result['status']).should.equal('success')
end end
it 'should not enable user if already enabled' do it 'should not enable user if already enabled' do
@ -59,7 +59,7 @@ describe 'Enable/disable user' do
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
}) })
(result['status']).should.equal('fail'); (result['status']).should.equal('fail')
(result['message']).should.equal('ALREADY_ENABLED') (result['message']).should.equal('ALREADY_ENABLED')
result = request('/user/enable', { result = request('/user/enable', {
@ -68,7 +68,7 @@ describe 'Enable/disable user' do
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
}) })
(result['status']).should.equal('fail'); (result['status']).should.equal('fail')
(result['message']).should.equal('ALREADY_ENABLED') (result['message']).should.equal('ALREADY_ENABLED')
end end
end end

View File

@ -2,8 +2,8 @@ describe '/user/get-user' do
Scripts.logout() Scripts.logout()
result = request('/user/login', { result = request('/user/login', {
email: 'staff@opensupports.com', email: $staff[:email],
password: 'staff', password: $staff[:password],
staff: true staff: true
}) })

View File

@ -6,8 +6,8 @@ describe '/user/get-users' do
Scripts.createUser('tests3@hotmail.com','passfasfasfws','laeczvwaf') Scripts.createUser('tests3@hotmail.com','passfasfasfws','laeczvwaf')
result = request('/user/login', { result = request('/user/login', {
email: 'staff@opensupports.com', email: $staff[:email],
password: 'staff', password: $staff[:password],
staff: true staff: true
}) })

View File

@ -7,7 +7,7 @@ describe'/user/invite' do
result = request('/user/invite', { result = request('/user/invite', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'i', name: '',
email: 'inviteduser2@opensupports.com' email: 'inviteduser2@opensupports.com'
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('fail')
@ -16,7 +16,7 @@ describe'/user/invite' do
result = request('/user/invite', { result = request('/user/invite', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
csrf_token: $csrf_token, csrf_token: $csrf_token,
name: 'invited userinvited userinvited userinvited userinvited userinvited userinvited userinvited userinvited userinvited user', name: 'invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user invited user',
email: 'inviteduser2@opensupports.com' email: 'inviteduser2@opensupports.com'
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('fail')

View File

@ -22,10 +22,10 @@ describe '/user/signup' do
it 'should fail if name is invalid' do it 'should fail if name is invalid' do
long_text = '' long_text = ''
100.times {long_text << 'a'} 201.times {long_text << 'a'}
result = request('/user/signup', { result = request('/user/signup', {
name: 't', name: '',
email: 'tyrion@outlook.com', email: 'tyrion@outlook.com',
password: 'Lannister' password: 'Lannister'
}) })