[DEV-194] Change same department of a ticket bug (#1135)

* add logic into change-departmetn path

* add ruby tests
This commit is contained in:
Guillermo Giuliana 2022-01-28 14:22:07 -03:00 committed by GitHub
parent fbee7275d5
commit 639d40ddb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -59,6 +59,10 @@ class ChangeDepartmentController extends Controller {
if(!$user->canManageTicket($ticket)){
throw new RequestException(ERRORS::NO_PERMISSION);
}
if($ticket->department->id == $department->id){
throw new RequestException(ERRORS::SAME_DEPARTMENT);
}
if($ticket->owner && !$ticket->owner->sharedDepartmentList->includesId($department->id)) {
$unAssignTicketController = new UnAssignStaffController($user);

View File

@ -88,13 +88,15 @@ describe '/ticket/change-department' do
result = request('/ticket/change-department', {
ticketNumber: ticket['ticket_number'],
departmentId: 1,
departmentId: 2,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
ticket = $database.getRow('ticket', 'Stafftitle', 'title')
(result['status']).should.equal('success')
(ticket['department_id']).should.equal(1)
(ticket['department_id']).should.equal(2)
request('/staff/edit', {
csrf_userid: $csrf_userid,
@ -103,6 +105,23 @@ describe '/ticket/change-department' do
staffId: 1
})
end
it 'should fail if tryes to change to the same deparment' do
ticket = $database.getRow('ticket', 'Stafftitle', 'title')
result = request('/ticket/change-department', {
ticketNumber: ticket['ticket_number'],
departmentId: 2,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('SAME_DEPARTMENT')
end
it 'should not unassing ticket if owner has the new ticket department and staff does not have it' do
Scripts.logout()
Scripts.login($staff[:email], $staff[:password], true)