From 920d7248f5ae78ac3ad456753acc09ff6a6a02f9 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 15 Oct 2016 04:32:38 -0300 Subject: [PATCH] guillermo- path-ticket-change-priority [skip ci] --- server/controllers/ticket.php | 3 + server/controllers/ticket/change-priority.php | 40 ++++++++++++++ server/data/ERRORS.php | 1 + tests/init.rb | 2 + tests/ticket/change-priority.rb | 55 +++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 server/controllers/ticket/change-priority.php create mode 100644 tests/ticket/change-priority.rb diff --git a/server/controllers/ticket.php b/server/controllers/ticket.php index d95c777c..3ac8d015 100644 --- a/server/controllers/ticket.php +++ b/server/controllers/ticket.php @@ -9,6 +9,7 @@ include 'ticket/get-custom-responses.php'; include 'ticket/change-department.php'; include 'ticket/close.php'; include 'ticket/re-open.php'; +include 'ticket/change-priority.php'; $ticketControllers = new ControllerGroup(); $ticketControllers->setGroupPath('/ticket'); @@ -23,4 +24,6 @@ $ticketControllers->addController(new GetCustomResponsesController); $ticketControllers->addController(new ChangeDepartmentController); $ticketControllers->addController(new CloseController); $ticketControllers->addController(new ReOpenController); +$ticketControllers->addController(new ChangePriorityController); + $ticketControllers->finalize(); \ No newline at end of file diff --git a/server/controllers/ticket/change-priority.php b/server/controllers/ticket/change-priority.php new file mode 100644 index 00000000..f00e7812 --- /dev/null +++ b/server/controllers/ticket/change-priority.php @@ -0,0 +1,40 @@ + 'staff_1', + 'requestData' => [ + 'ticketNumber' => [ + 'validation' => DataValidator::validTicketNumber(), + 'error' => ERRORS::INVALID_TICKET + ], + 'priority' => [ + 'validation' => DataValidator::in(['low', 'medium', 'high']), + 'error' => ERRORS::INVALID_PRIORITY + ] + ] + ]; + } + + public function handler() { + $ticketNumber = Controller::request('ticketNumber'); + $priority = Controller::request('priority'); + $ticket = Ticket::getByTicketNumber($ticketNumber); + $user = Controller::getLoggedUser(); + + if($ticket->owner && $user->id === $ticket->owner->id) { + $ticket->priority = $priority; + $ticket->store(); + Response::respondSuccess(); + } else { + Response::respondError(ERRORS::NO_PERMISSION); + } + + } +} + + diff --git a/server/data/ERRORS.php b/server/data/ERRORS.php index 45d4ba1b..c1478b8e 100644 --- a/server/data/ERRORS.php +++ b/server/data/ERRORS.php @@ -18,4 +18,5 @@ class ERRORS { const INVALID_TICKET_EVENT = 'INVALID_TICKET_EVENT'; const INVALID_LANGUAGE = 'INVALID_LANGUAGE'; const TICKET_ALREADY_ASSIGNED = 'TICKET_ALREADY_ASSIGNED'; + const INVALID_PRIORITY = 'INVALID_PRIORITY'; } diff --git a/tests/init.rb b/tests/init.rb index c4da8c53..17e27979 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -29,4 +29,6 @@ require './staff/get.rb' require './staff/assign-ticket.rb' require './staff/un-assign-ticket.rb' require './staff/get-tickets.rb' +require './ticket/change-priority.rb' + diff --git a/tests/ticket/change-priority.rb b/tests/ticket/change-priority.rb new file mode 100644 index 00000000..d33839f9 --- /dev/null +++ b/tests/ticket/change-priority.rb @@ -0,0 +1,55 @@ +describe '/ticket/change-priority' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + #TODO: things that Ivan don't forget + + it 'should change priority to high if everything is okey' do + ticket = $database.getRow('ticket', 1 , 'id') + + result = request('/ticket/change-priority', { + priority:'high', + ticketNumber: ticket['ticket_number'], + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + + ticket = $database.getRow('ticket', 1 , 'id') + (ticket['priority']).should.equal('high') + end + + it 'should change priority to medium if everything is okey' do + ticket = $database.getRow('ticket', 1 , 'id') + + result = request('/ticket/change-priority', { + priority:'medium', + ticketNumber: ticket['ticket_number'], + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + + ticket = $database.getRow('ticket', 1 , 'id') + (ticket['priority']).should.equal('medium') + end + + it 'should change priority to low if everything is okey' do + ticket = $database.getRow('ticket', 1 , 'id') + + result = request('/ticket/change-priority', { + priority:'low', + ticketNumber: ticket['ticket_number'], + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + + ticket = $database.getRow('ticket', 1 , 'id') + (ticket['priority']).should.equal('low') + end + +end \ No newline at end of file