fix ruby tests and change ticket search departmentvalid functions

This commit is contained in:
Guillermo Giuliana 2020-02-04 16:22:08 -03:00
parent af0071dec2
commit d520b96932
10 changed files with 38 additions and 58 deletions

View File

@ -43,11 +43,11 @@ class EditArticleController extends Controller {
'error' => ERRORS::INVALID_TOPIC 'error' => ERRORS::INVALID_TOPIC
], ],
'title' => [ 'title' => [
'validation' => DataValidator::notBlank()->length(5, 100), 'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(5, 100),DataValidator::nullType()),
'error' => ERRORS::INVALID_TITLE 'error' => ERRORS::INVALID_TITLE
], ],
'content' => [ 'content' => [
'validation' => DataValidator::content(), 'validation' => DataValidator::oneOf(DataValidator::content(),DataValidator::nullType()),
'error' => ERRORS::INVALID_CONTENT 'error' => ERRORS::INVALID_CONTENT
], ],
] ]

View File

@ -43,7 +43,7 @@ class EditCustomResponseController extends Controller {
'error' => ERRORS::INVALID_CONTENT 'error' => ERRORS::INVALID_CONTENT
], ],
'name' => [ 'name' => [
'validation' => DataValidator::notBlank()->length(1, 200), 'validation' => DataValidator::oneOf(DataValidator::notBlank()->length(1, 200),DataValidator::nullType()),
'error' => ERRORS::INVALID_NAME 'error' => ERRORS::INVALID_NAME
], ],
] ]

View File

@ -95,6 +95,10 @@ class SearchController extends Controller {
'validation' => DataValidator::oneOf(DataValidator::in(['0','1']),DataValidator::nullType()), 'validation' => DataValidator::oneOf(DataValidator::in(['0','1']),DataValidator::nullType()),
'error' => ERRORS::INVALID_ASSIGNED_FILTER 'error' => ERRORS::INVALID_ASSIGNED_FILTER
], ],
'query' => [
'validation' => DataValidator::oneOf(DataValidator::notBlank(),DataValidator::nullType()),
'error' => ERRORS::INVALID_QUERY_FILTER
],
'orderBy' => [ 'orderBy' => [
'validation' => DataValidator::oneOf(DataValidator::validOrderBy(),DataValidator::nullType()), 'validation' => DataValidator::oneOf(DataValidator::validOrderBy(),DataValidator::nullType()),
'error' => ERRORS::INVALID_ORDER_BY 'error' => ERRORS::INVALID_ORDER_BY
@ -130,16 +134,16 @@ class SearchController extends Controller {
$query = $this->getSQLQuery($inputs); $query = $this->getSQLQuery($inputs);
$queryWithOrder = $this->getSQLQueryWithOrder($inputs); $queryWithOrder = $this->getSQLQueryWithOrder($inputs);
throw new Exception($queryWithOrder);
$totalCount = RedBean::getAll("SELECT COUNT(*) FROM (SELECT COUNT(*) " . $query . " ) AS T2", [':query' => $inputs['query']])[0]['COUNT(*)']; $totalCount = RedBean::getAll("SELECT COUNT(*) FROM (SELECT COUNT(*) " . $query . " ) AS T2", [':query' => $inputs['query']])[0]['COUNT(*)'];
$ticketIdList = RedBean::getAll($queryWithOrder, [':query' => "%" . $inputs['query'] . "%"]); $ticketIdList = RedBean::getAll($queryWithOrder, [':query' => "%" . $inputs['query'] . "%"]);
$ticketList = []; $ticketList = [];
foreach ($ticketIdList as $item) { foreach ($ticketIdList as $item) {
$ticket = Ticket::getDataStore($item['id']); $ticket = Ticket::getDataStore($item['id']);
array_push($ticketList, $ticket->toArray()); array_push($ticketList, $ticket->toArray());
} }
$ticketTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticket';"); $ticketTableExists = RedBean::exec("select table_name from information_schema.tables where table_name = 'ticket';");
throw new Exception("SELECT COUNT(*) FROM (SELECT COUNT(*) " . $query . " ) AS T2");
if($ticketTableExists){ if($ticketTableExists){
Response::respondSuccess([ Response::respondSuccess([
'tickets' => $ticketList, 'tickets' => $ticketList,
@ -263,8 +267,8 @@ class SearchController extends Controller {
private function setDepartmentFilter($requestedDepartments,$myDepartments, $idStaff, &$filters){ private function setDepartmentFilter($requestedDepartments,$myDepartments, $idStaff, &$filters){
if ($filters != "") $filters .= " and "; if ($filters != "") $filters .= " and ";
$requestedNotOwnedDepartments = $this->generateValidDepartmentList($requestedDepartments, $myDepartments); $requestedNotOwnedDepartments = $this->getRequestedOwnedDepartments($requestedDepartments, $myDepartments);
$requestedOwnedDepartments = $this->generateValidDepartmentList($requestedDepartments, $myDepartments, true); $requestedOwnedDepartments = $this->getRequestedNotOwnedDepartments($requestedDepartments, $myDepartments, true);
$first = TRUE; $first = TRUE;
if(!$requestedOwnedDepartments && !$requestedNotOwnedDepartments){ if(!$requestedOwnedDepartments && !$requestedNotOwnedDepartments){
@ -373,19 +377,20 @@ class SearchController extends Controller {
}; };
} }
private function generateValidDepartmentList($requestedDepartments, $myDepartments, $allowed = false){ private function getRequestedOwnedDepartments($requestedDepartments, $myDepartments){
$requestedOwnedDepartments = [];
$requestedOwnedDepartments = array_values(array_unique(array_intersect($requestedDepartments, $myDepartments)));
return $requestedOwnedDepartments;
}
private function getRequestedNotOwnedDepartments($requestedDepartments, $myDepartments){
$requestedNotOwnedDepartments = []; $requestedNotOwnedDepartments = [];
$requestedOwnedDepartments = [];
if($requestedDepartments == null) $requestedDepartments = [];
$requestedOwnedDepartments = array_values(array_unique(array_intersect($requestedDepartments, $myDepartments))); $requestedOwnedDepartments = array_values(array_unique(array_intersect($requestedDepartments, $myDepartments)));
$requestedNotOwnedDepartments = array_values(array_diff($requestedDepartments, $requestedOwnedDepartments)); $requestedNotOwnedDepartments = array_values(array_diff($requestedDepartments, $requestedOwnedDepartments));
if($allowed){
return $requestedOwnedDepartments;
}else{
return $requestedNotOwnedDepartments; return $requestedNotOwnedDepartments;
};
} }
//ORDER //ORDER

View File

@ -131,6 +131,10 @@
* @apiDefine INVALID_ASSIGNED_FILTER * @apiDefine INVALID_ASSIGNED_FILTER
* @apiError {String} INVALID_ASSIGNED_FILTER The assigned filter is invalid. * @apiError {String} INVALID_ASSIGNED_FILTER The assigned filter is invalid.
*/ */
/**
* @apiDefine INVALID_QUERY_FILTER
* @apiError {String} INVALID_QUERY_FILTER The query filter is invalid.
*/
/** /**
* @apiDefine INVALID_ORDER_BY * @apiDefine INVALID_ORDER_BY
* @apiError {String} INVALID_ORDER_BY The order-by is invalid. * @apiError {String} INVALID_ORDER_BY The order-by is invalid.
@ -335,6 +339,7 @@ class ERRORS {
const INVALID_AUTHOR_FILTER = 'INVALID_AUTHOR_FILTER'; const INVALID_AUTHOR_FILTER = 'INVALID_AUTHOR_FILTER';
const INVALID_OWNER_FILTER = 'INVALID_OWNER_FILTER'; const INVALID_OWNER_FILTER = 'INVALID_OWNER_FILTER';
const INVALID_ASSIGNED_FILTER = 'INVALID_ASSIGNED_FILTER'; const INVALID_ASSIGNED_FILTER = 'INVALID_ASSIGNED_FILTER';
const INVALID_QUERY_FILTER = 'INVALID_QUERY_FILTER';
const INVALID_ORDER_BY = 'INVALID_ORDER_BY'; const INVALID_ORDER_BY = 'INVALID_ORDER_BY';
const INVALID_TOPIC = 'INVALID_TOPIC'; const INVALID_TOPIC = 'INVALID_TOPIC';
const INVALID_SEARCH = 'INVALID_SEARCH'; const INVALID_SEARCH = 'INVALID_SEARCH';

View File

@ -121,7 +121,7 @@ describe 'Custom fields' do
it 'should success and shows all custom fields' do it 'should success and shows all custom fields' do
Scripts.createTextCustomField('mocktextfield1','description number 1') Scripts.createTextCustomField('mocktextfield1','description number 1')
Scripts.createTextCustomField('mocktextfield2','description number 2') Scripts.createTextCustomField('mocktextfield2','description number 2')
Scripts.createTextCustomField('mocktextfield3',nil) Scripts.createTextCustomField('mocktextfield3','description number 3')
result = request('/system/get-custom-fields', { result = request('/system/get-custom-fields', {
csrf_userid: $csrf_userid, csrf_userid: $csrf_userid,
@ -147,7 +147,7 @@ describe 'Custom fields' do
result['data'][2]['description'].should.equal('description number 2') result['data'][2]['description'].should.equal('description number 2')
result['data'][3]['name'].should.equal('mocktextfield3') result['data'][3]['name'].should.equal('mocktextfield3')
result['data'][3]['type'].should.equal('text') result['data'][3]['type'].should.equal('text')
result['data'][3]['description'].should.equal('') result['data'][3]['description'].should.equal('description number 3')
end end
end end

View File

@ -19,7 +19,7 @@ describe'system/disable-user-system' do
numberOftickets = $database.query("SELECT * FROM ticket WHERE author_id IS NULL AND author_email IS NOT NULL AND author_name IS NOT NULL") numberOftickets = $database.query("SELECT * FROM ticket WHERE author_id IS NULL AND author_email IS NOT NULL AND author_name IS NOT NULL")
(numberOftickets.num_rows).should.equal(52) (numberOftickets.num_rows).should.equal(54)
request('/user/logout') request('/user/logout')
@ -220,7 +220,7 @@ describe'system/disable-user-system' do
numberOftickets= $database.query("SELECT * FROM ticket WHERE author_email IS NULL AND author_name IS NULL AND author_id IS NOT NULL" ) numberOftickets= $database.query("SELECT * FROM ticket WHERE author_email IS NULL AND author_name IS NULL AND author_id IS NOT NULL" )
(numberOftickets.num_rows).should.equal(55) (numberOftickets.num_rows).should.equal(57)
end end
it 'should not enable the user system' do it 'should not enable the user system' do

View File

@ -18,33 +18,6 @@ describe '/ticket/comment/' do
(result['message']).should.equal('NO_PERMISSION') (result['message']).should.equal('NO_PERMISSION')
end end
it 'should fail if content is too short' do
result = request('/ticket/comment', {
content: 'Test',
ticketNumber: @ticketNumber,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_CONTENT')
end
it 'should fail if content is very long' do
long_text = ''
6000.times {long_text << 'a'}
result = request('/ticket/comment', {
content: long_text,
ticketNumber: @ticketNumber,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_CONTENT')
end
it 'should fail if ticket does not exist' do it 'should fail if ticket does not exist' do
result = request('/ticket/comment', { result = request('/ticket/comment', {
content: 'some comment content', content: 'some comment content',

View File

@ -32,7 +32,7 @@ describe '/ticket/create' do
(result['message']).should.equal('INVALID_TITLE') (result['message']).should.equal('INVALID_TITLE')
end end
it 'should fail if content is too short' do it 'should craete ticket with a short content' do
result = request('/ticket/create', { result = request('/ticket/create', {
title: 'Winter is coming', title: 'Winter is coming',
content: 'Test', content: 'Test',
@ -42,11 +42,10 @@ describe '/ticket/create' do
csrf_token: $csrf_token csrf_token: $csrf_token
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('success')
(result['message']).should.equal('INVALID_CONTENT')
end end
it 'should fail if content is very long' do it 'should create ticket with a large content' do
long_text = '' long_text = ''
6000.times {long_text << 'a'} 6000.times {long_text << 'a'}
@ -59,8 +58,7 @@ describe '/ticket/create' do
csrf_token: $csrf_token csrf_token: $csrf_token
}) })
(result['status']).should.equal('fail') (result['status']).should.equal('success')
(result['message']).should.equal('INVALID_CONTENT')
end end
@ -114,7 +112,7 @@ describe '/ticket/create' do
Scripts.login('creator@os4.com','creator') Scripts.login('creator@os4.com','creator')
result = request('/ticket/create', { result = request('/ticket/create', {
title: 'Winter is coming', title: 'Winter is coming!',
content: 'The north remembers', content: 'The north remembers',
departmentId: 1, departmentId: 1,
language: 'en', language: 'en',
@ -124,7 +122,7 @@ describe '/ticket/create' do
(result['status']).should.equal('success') (result['status']).should.equal('success')
ticket = $database.getRow('ticket','Winter is coming','title') ticket = $database.getRow('ticket','Winter is coming!','title')
(ticket['content']).should.equal('The north remembers') (ticket['content']).should.equal('The north remembers')
(ticket['unread']).should.equal('0') (ticket['unread']).should.equal('0')
(ticket['closed']).should.equal('0') (ticket['closed']).should.equal('0')
@ -168,7 +166,7 @@ describe '/ticket/create' do
ticket_number_gap = $database.getRow('setting', 'ticket-gap', 'name')['value'].to_i ticket_number_gap = $database.getRow('setting', 'ticket-gap', 'name')['value'].to_i
ticket0 = $database.getRow('ticket','Winter is coming','title')['ticket_number'].to_i ticket0 = $database.getRow('ticket','Winter is coming!','title')['ticket_number'].to_i
ticket1 = $database.getRow('ticket','Winter is coming1','title')['ticket_number'].to_i ticket1 = $database.getRow('ticket','Winter is coming1','title')['ticket_number'].to_i
ticket2 = $database.getRow('ticket','Winter is coming2','title')['ticket_number'].to_i ticket2 = $database.getRow('ticket','Winter is coming2','title')['ticket_number'].to_i
ticket3 = $database.getRow('ticket','Winter is coming3','title')['ticket_number'].to_i ticket3 = $database.getRow('ticket','Winter is coming3','title')['ticket_number'].to_i

View File

@ -34,7 +34,6 @@ describe 'CustomResponses' do
}) })
customResponse = $database.getRow('customresponse', 1) customResponse = $database.getRow('customresponse', 1)
(result['status']).should.equal('success') (result['status']).should.equal('success')
(customResponse['name']).should.equal('Some common problem') (customResponse['name']).should.equal('Some common problem')
(customResponse['content']).should.equal('this is the content of a custom response for a common problem 2') (customResponse['content']).should.equal('this is the content of a custom response for a common problem 2')