From 496dc9d9395ad79c62e35d85c748ea8cd6339bf4 Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Mon, 12 Dec 2016 02:12:17 -0300 Subject: [PATCH] Guillermo - department parths/ department tests[skip ci] --- server/controllers/system.php | 7 ++++ server/controllers/system/add-department.php | 34 +++++++++++++++++ .../controllers/system/delete-department.php | 27 +++++++++++++ server/controllers/system/edit-department.php | 38 +++++++++++++++++++ tests/init.rb | 3 ++ tests/system/add-department.rb | 18 +++++++++ tests/system/delete-department.rb | 18 +++++++++ tests/system/edit-department.rb | 19 ++++++++++ 8 files changed, 164 insertions(+) create mode 100644 server/controllers/system/add-department.php create mode 100644 server/controllers/system/delete-department.php create mode 100644 server/controllers/system/edit-department.php create mode 100644 tests/system/add-department.rb create mode 100644 tests/system/delete-department.rb create mode 100644 tests/system/edit-department.rb diff --git a/server/controllers/system.php b/server/controllers/system.php index 38e7db29..9dd1c3bf 100644 --- a/server/controllers/system.php +++ b/server/controllers/system.php @@ -1,11 +1,18 @@ setGroupPath('/system'); $systemControllerGroup->addController(new InitSettingsController); $systemControllerGroup->addController(new GetSettingsController); +$systemControllerGroup->addController(new AddDepartmentController); +$systemControllerGroup->addController(new EditDepartmentController); +$systemControllerGroup->addController(new DeleteDepartmentController); + $systemControllerGroup->finalize(); \ No newline at end of file diff --git a/server/controllers/system/add-department.php b/server/controllers/system/add-department.php new file mode 100644 index 00000000..b8ca5d4d --- /dev/null +++ b/server/controllers/system/add-department.php @@ -0,0 +1,34 @@ + 'staff_3', + 'requestData' => [ + 'name' => [ + 'validation' => DataValidator::alnum(), + 'error' => ERRORS::INVALID_NAME + ] + ] + ]; + } + + public function handler() { + $name = Controller::request('name'); + + $departmentInstance = new Department(); + + $departmentInstance->setProperties([ + 'name' => $name, + + ]); + + $departmentInstance->store(); + + Response::respondSuccess(); + + } +} \ No newline at end of file diff --git a/server/controllers/system/delete-department.php b/server/controllers/system/delete-department.php new file mode 100644 index 00000000..c57fb97b --- /dev/null +++ b/server/controllers/system/delete-department.php @@ -0,0 +1,27 @@ + 'staff_3', + 'requestData' => [ + 'departmentId' => [ + 'validation' => DataValidator::dataStoreId('department'), + 'error' => ERRORS::INVALID_DEPARTMENT + ], + ] + ]; + } + + public function handler() { + + $departmentId = Controller::request('departmentId'); + $departmentInstance = Department::getDataStore($departmentId); + $departmentInstance->delete(); + Response::respondSuccess(); + } +} \ No newline at end of file diff --git a/server/controllers/system/edit-department.php b/server/controllers/system/edit-department.php new file mode 100644 index 00000000..e6d420b1 --- /dev/null +++ b/server/controllers/system/edit-department.php @@ -0,0 +1,38 @@ + 'staff_3', + 'requestData' => [ + 'name' => [ + 'validation' => DataValidator::alnum(), + 'error' => ERRORS::INVALID_NAME + ], + 'departmentId' => [ + 'validation' => DataValidator::dataStoreId('department'), + 'error' => ERRORS::INVALID_DEPARTMENT + ] + ] + ]; + } + + public function handler() { + $newname = Controller::request('name'); + $departmentId = Controller::request('departmentId'); + + $departmentInstance = Department::getDataStore($departmentId); + + $departmentInstance->name = $newname ; + + $departmentInstance->store(); + + Response::respondSuccess(); + + } +} \ No newline at end of file diff --git a/tests/init.rb b/tests/init.rb index 0af3e81a..39acfcba 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -43,5 +43,8 @@ require './user/ban.rb' require './user/get-users-test.rb' require './user/delete.rb' require './staff/get-all.rb' +require './system/add-department.rb' +require './system/edit-department.rb' +require './system/delete-department.rb' diff --git a/tests/system/add-department.rb b/tests/system/add-department.rb new file mode 100644 index 00000000..5da0e1ad --- /dev/null +++ b/tests/system/add-department.rb @@ -0,0 +1,18 @@ +describe'system/add-department' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + it 'should add department' do + result= request('/system/add-department', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + name: 'new department' + }) + + (result['status']).should.equal('success') + + row = $database.getRow('department', 4, 'id') + + (row['name']).should.equal('new department') + end +end \ No newline at end of file diff --git a/tests/system/delete-department.rb b/tests/system/delete-department.rb new file mode 100644 index 00000000..0b596af9 --- /dev/null +++ b/tests/system/delete-department.rb @@ -0,0 +1,18 @@ +describe'system/delete-department' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + it 'should delete department' do + result= request('/system/delete-department', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + departmentId: 4 + }) + + (result['status']).should.equal('success') + + row = $database.getRow('department', 4, 'id') + + (row).should.equal(nil) + end +end \ No newline at end of file diff --git a/tests/system/edit-department.rb b/tests/system/edit-department.rb new file mode 100644 index 00000000..e7620b6d --- /dev/null +++ b/tests/system/edit-department.rb @@ -0,0 +1,19 @@ +describe'system/edit-department' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + it 'should edit department' do + result= request('/system/edit-department', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + name: 'second name', + departmentId: 4 + }) + + (result['status']).should.equal('success') + + row = $database.getRow('department', 4, 'id') + + (row['name']).should.equal('second name') + end +end \ No newline at end of file