From 639d40ddb0f110602c7722062845ddc93e9b360d Mon Sep 17 00:00:00 2001 From: Guillermo Giuliana Date: Fri, 28 Jan 2022 14:22:07 -0300 Subject: [PATCH] [DEV-194] Change same department of a ticket bug (#1135) * add logic into change-departmetn path * add ruby tests --- .../controllers/ticket/change-department.php | 4 ++++ tests/ticket/change-department.rb | 23 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/server/controllers/ticket/change-department.php b/server/controllers/ticket/change-department.php index 639634ac..b8c71c81 100755 --- a/server/controllers/ticket/change-department.php +++ b/server/controllers/ticket/change-department.php @@ -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); diff --git a/tests/ticket/change-department.rb b/tests/ticket/change-department.rb index adaa1664..c9550313 100644 --- a/tests/ticket/change-department.rb +++ b/tests/ticket/change-department.rb @@ -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)