[DEV-318] Add edit comment tests (#1194)

* WIP Fix ruby tests

* WIP

* WIP

* Add edit ticket comment test
This commit is contained in:
LautaroCesso 2022-05-04 11:30:37 -03:00 committed by GitHub
parent 04923b0e9d
commit c82aaa001e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 17 deletions

View File

@ -60,14 +60,19 @@ class EditCommentController extends Controller {
$ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
}
$ticketEventArray = $ticketEvent->toArray();
if(!Controller::isStaffLogged() && $user->id !== $ticketEventArray["author"]["id"] && $user->id !== $ticket->authorId) {
throw new RequestException(ERRORS::NO_PERMISSION);
}
if (!$ticketEvent->isNull()) {
if($user->id !== $ticketEventArray["author"]["id"]) {
$ticketEventArray = $ticketEvent->toArray();
$userArray = $user->toArray();
if($user->id !== $ticketEventArray["author"]["id"] && $user->id !== $ticket->authorId) {
throw new RequestException(ERRORS::NO_PERMISSION);
}
if((!!$userArray["isStaff"] === !!$ticketEventArray["author"]["staff"]) && ($user->id !== $ticketEventArray["author"]["id"])) {
throw new RequestException(ERRORS::NO_PERMISSION);
}
if (!!$userArray["isStaff"] !== !!$ticketEventArray["author"]["staff"]) {
throw new RequestException(ERRORS::NO_PERMISSION);
}
} else if ($user->id !== $ticket->authorId) {

View File

@ -1,6 +1,6 @@
<?php
use Respect\Validation\Validator as DataValidator;
/**
* @api {post} /user/get-supervised-tickets Get supervised tickets
* @apiVersion 4.11.0
@ -19,7 +19,7 @@ use Respect\Validation\Validator as DataValidator;
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_SUPERVISED_USERS
* @apiUse PAGESIZE_ERROR
* @apiUse INVALID_PAGE_SIZE
* @apiSuccess {Object} data Information about a tickets and quantity of pages.
* @apiSuccess {[Ticket](#api-Data_Structures-ObjectTicket)[]} data.tickets Array of tickets assigned to the staff of the current page.
@ -46,7 +46,7 @@ class GetSupervisedTicketController extends Controller {
],
'pageSize' => [
'validation' => DataValidator::oneOf(DataValidator::intVal()->between(5, 50),DataValidator::nullType()),
'error' => ERRORS::PAGESIZE_ERROR
'error' => ERRORS::INVALID_PAGE_SIZE
]
]
];
@ -55,6 +55,7 @@ class GetSupervisedTicketController extends Controller {
private $page;
private $showOwnTickets;
private $supervisedUserList;
private $pageSize;
public function handler() {
if(Controller::isStaffLogged()) throw new RequestException(ERRORS::NO_PERMISSION);
@ -79,7 +80,7 @@ class GetSupervisedTicketController extends Controller {
case 'supervisor':
return 1;
case 'pageSize':
return $this->pageSize;
return $this->pageSize*1;
}
return null;

View File

@ -73,7 +73,8 @@ class Staff extends DataStore {
'departments' => $this->sharedDepartmentList->toArray(),
'tickets' => $this->sharedTicketList->toArray(),
'lastLogin' => $this->lastLogin,
'sendEmailOnNewTicket' => $this->sendEmailOnNewTicket
'sendEmailOnNewTicket' => $this->sendEmailOnNewTicket,
'isStaff' => 1
];
}
}

View File

@ -80,7 +80,8 @@ class User extends DataStore {
'disabled' => $this->disabled,
'customfields' => $this->xownCustomfieldvalueList->toArray(),
'notRegistered' => $this->notRegistered,
'supervisedrelation' => $this->supervisedrelation
'supervisedrelation' => $this->supervisedrelation,
'isStaff' => 0
];
}
}

View File

@ -96,11 +96,39 @@ describe '/ticket/edit-comment' do
ticketevent = tickets_comments.to_a.last
(result['status']).should.equal('success')
Scripts.logout()
Scripts.login($staff[:email], $staff[:password], true)
Scripts.commentTicket(ticket['ticket_number'],'com ment of a staff xd')
ticketevent = $database.getRow('ticketevent', 'com ment of a staff xd', 'content')
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
tickets_comments.size.should.equal(4)
tickets_comments.to_a.last['content'].should.equal('com ment of a staff xd')
result = request('/ticket/edit-comment', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
content: 'comment edited by the staff xd',
ticketEventId: ticketevent['id']
})
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
tickets_comments.size.should.equal(4)
tickets_comments.to_a.last['content'].should.equal('comment edited by the staff xd')
ticketevent = tickets_comments.to_a.last
(result['status']).should.equal('success')
Scripts.logout()
Scripts.login()
end
it 'should fail if author is right but ticket has other commets below' do
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
tickets_comments.size.should.equal(3)
tickets_comments.size.should.equal(4)
result = request('/ticket/edit-comment', {
csrf_userid: $csrf_userid,
@ -113,13 +141,18 @@ describe '/ticket/edit-comment' do
(result['message']).should.equal('TICKET_CONTENT_CANNOT_BE_EDITED')
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
tickets_comments.size.should.equal(3)
ticket_comment3 = tickets_comments.to_a.last
tickets_comments.size.should.equal(4)
Scripts.commentTicket(ticket['ticket_number'],'com ment of a user 4')
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
tickets_comments.size.should.equal(4)
tickets_comments.size.should.equal(5)
ticket_comment3 = tickets_comments.to_a.last
Scripts.commentTicket(ticket['ticket_number'],'com ment of a user 5')
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
tickets_comments.size.should.equal(6)
result = request('/ticket/edit-comment', {
csrf_userid: $csrf_userid,