Merged in OS-124-departments-paths (pull request #93)

Guillermo -   department parths/ department tests
This commit is contained in:
Ivan Diaz 2016-12-12 17:47:33 -03:00
commit 763e83331b
8 changed files with 164 additions and 0 deletions

View File

@ -1,11 +1,18 @@
<?php
require_once 'system/init-settings.php';
require_once 'system/get-settings.php';
require_once 'system/add-department.php';
require_once 'system/edit-department.php';
require_once 'system/delete-department.php';
$systemControllerGroup = new ControllerGroup();
$systemControllerGroup->setGroupPath('/system');
$systemControllerGroup->addController(new InitSettingsController);
$systemControllerGroup->addController(new GetSettingsController);
$systemControllerGroup->addController(new AddDepartmentController);
$systemControllerGroup->addController(new EditDepartmentController);
$systemControllerGroup->addController(new DeleteDepartmentController);
$systemControllerGroup->finalize();

View File

@ -0,0 +1,34 @@
<?php
use Respect\Validation\Validator as DataValidator;
class AddDepartmentController extends Controller {
const PATH = '/add-department';
public function validations() {
return [
'permission' => '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();
}
}

View File

@ -0,0 +1,27 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class DeleteDepartmentController extends Controller {
const PATH = '/delete-department';
public function validations() {
return [
'permission' => '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();
}
}

View File

@ -0,0 +1,38 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
class EditDepartmentController extends Controller {
const PATH = '/edit-department';
public function validations() {
return [
'permission' => '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();
}
}

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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