mirror of
https://github.com/opensupports/opensupports.git
synced 2025-09-25 19:08:57 +02:00
[DEV-318] Add edit comment tests (#1194)
* WIP Fix ruby tests * WIP * WIP * Add edit ticket comment test
This commit is contained in:
parent
04923b0e9d
commit
c82aaa001e
@ -60,14 +60,19 @@ class EditCommentController extends Controller {
|
|||||||
$ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
|
$ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$ticketEvent->isNull()) {
|
||||||
$ticketEventArray = $ticketEvent->toArray();
|
$ticketEventArray = $ticketEvent->toArray();
|
||||||
|
$userArray = $user->toArray();
|
||||||
|
|
||||||
if(!Controller::isStaffLogged() && $user->id !== $ticketEventArray["author"]["id"] && $user->id !== $ticket->authorId) {
|
if($user->id !== $ticketEventArray["author"]["id"] && $user->id !== $ticket->authorId) {
|
||||||
throw new RequestException(ERRORS::NO_PERMISSION);
|
throw new RequestException(ERRORS::NO_PERMISSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$ticketEvent->isNull()) {
|
if((!!$userArray["isStaff"] === !!$ticketEventArray["author"]["staff"]) && ($user->id !== $ticketEventArray["author"]["id"])) {
|
||||||
if($user->id !== $ticketEventArray["author"]["id"]) {
|
throw new RequestException(ERRORS::NO_PERMISSION);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!!$userArray["isStaff"] !== !!$ticketEventArray["author"]["staff"]) {
|
||||||
throw new RequestException(ERRORS::NO_PERMISSION);
|
throw new RequestException(ERRORS::NO_PERMISSION);
|
||||||
}
|
}
|
||||||
} else if ($user->id !== $ticket->authorId) {
|
} else if ($user->id !== $ticket->authorId) {
|
||||||
|
@ -19,7 +19,7 @@ use Respect\Validation\Validator as DataValidator;
|
|||||||
*
|
*
|
||||||
* @apiUse NO_PERMISSION
|
* @apiUse NO_PERMISSION
|
||||||
* @apiUse INVALID_SUPERVISED_USERS
|
* @apiUse INVALID_SUPERVISED_USERS
|
||||||
* @apiUse PAGESIZE_ERROR
|
* @apiUse INVALID_PAGE_SIZE
|
||||||
|
|
||||||
* @apiSuccess {Object} data Information about a tickets and quantity of pages.
|
* @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.
|
* @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' => [
|
'pageSize' => [
|
||||||
'validation' => DataValidator::oneOf(DataValidator::intVal()->between(5, 50),DataValidator::nullType()),
|
'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 $page;
|
||||||
private $showOwnTickets;
|
private $showOwnTickets;
|
||||||
private $supervisedUserList;
|
private $supervisedUserList;
|
||||||
|
private $pageSize;
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
if(Controller::isStaffLogged()) throw new RequestException(ERRORS::NO_PERMISSION);
|
if(Controller::isStaffLogged()) throw new RequestException(ERRORS::NO_PERMISSION);
|
||||||
@ -79,7 +80,7 @@ class GetSupervisedTicketController extends Controller {
|
|||||||
case 'supervisor':
|
case 'supervisor':
|
||||||
return 1;
|
return 1;
|
||||||
case 'pageSize':
|
case 'pageSize':
|
||||||
return $this->pageSize;
|
return $this->pageSize*1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -73,7 +73,8 @@ class Staff extends DataStore {
|
|||||||
'departments' => $this->sharedDepartmentList->toArray(),
|
'departments' => $this->sharedDepartmentList->toArray(),
|
||||||
'tickets' => $this->sharedTicketList->toArray(),
|
'tickets' => $this->sharedTicketList->toArray(),
|
||||||
'lastLogin' => $this->lastLogin,
|
'lastLogin' => $this->lastLogin,
|
||||||
'sendEmailOnNewTicket' => $this->sendEmailOnNewTicket
|
'sendEmailOnNewTicket' => $this->sendEmailOnNewTicket,
|
||||||
|
'isStaff' => 1
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,8 @@ class User extends DataStore {
|
|||||||
'disabled' => $this->disabled,
|
'disabled' => $this->disabled,
|
||||||
'customfields' => $this->xownCustomfieldvalueList->toArray(),
|
'customfields' => $this->xownCustomfieldvalueList->toArray(),
|
||||||
'notRegistered' => $this->notRegistered,
|
'notRegistered' => $this->notRegistered,
|
||||||
'supervisedrelation' => $this->supervisedrelation
|
'supervisedrelation' => $this->supervisedrelation,
|
||||||
|
'isStaff' => 0
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,11 +96,39 @@ describe '/ticket/edit-comment' do
|
|||||||
ticketevent = tickets_comments.to_a.last
|
ticketevent = tickets_comments.to_a.last
|
||||||
|
|
||||||
(result['status']).should.equal('success')
|
(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
|
end
|
||||||
|
|
||||||
it 'should fail if author is right but ticket has other commets below' do
|
it 'should fail if author is right but ticket has other commets below' do
|
||||||
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
|
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
|
||||||
tickets_comments.size.should.equal(3)
|
tickets_comments.size.should.equal(4)
|
||||||
|
|
||||||
result = request('/ticket/edit-comment', {
|
result = request('/ticket/edit-comment', {
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
@ -113,13 +141,18 @@ describe '/ticket/edit-comment' do
|
|||||||
(result['message']).should.equal('TICKET_CONTENT_CANNOT_BE_EDITED')
|
(result['message']).should.equal('TICKET_CONTENT_CANNOT_BE_EDITED')
|
||||||
|
|
||||||
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
|
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
|
||||||
tickets_comments.size.should.equal(3)
|
tickets_comments.size.should.equal(4)
|
||||||
ticket_comment3 = tickets_comments.to_a.last
|
|
||||||
|
|
||||||
Scripts.commentTicket(ticket['ticket_number'],'com ment of a user 4')
|
Scripts.commentTicket(ticket['ticket_number'],'com ment of a user 4')
|
||||||
|
|
||||||
tickets_comments = $database.query(getTicketEventsCommentsQuery(ticket['id']))
|
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', {
|
result = request('/ticket/edit-comment', {
|
||||||
csrf_userid: $csrf_userid,
|
csrf_userid: $csrf_userid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user