[DEV-199] Can't put a department in private (#1115)
* add correct validation of repeated name use * update department create ruby script * add new edit department ruby tests * change parameter name of create department ruby scripts * verify change of private state while editing department ruby tests
This commit is contained in:
parent
5dd6b7acdc
commit
fe1dd1bd48
|
@ -21,6 +21,7 @@ DataValidator::with('CustomValidations', true);
|
|||
* @apiUse NO_PERMISSION
|
||||
* @apiUse INVALID_NAME
|
||||
* @apiUse INVALID_DEPARTMENT
|
||||
* @apiUse NAME_ALREADY_USED
|
||||
*
|
||||
* @apiSuccess {Object} data Empty object
|
||||
*
|
||||
|
@ -39,10 +40,7 @@ class EditDepartmentController extends Controller {
|
|||
'error' => ERRORS::INVALID_DEPARTMENT
|
||||
],
|
||||
'name' => [
|
||||
'validation' => DataValidator::AllOf(
|
||||
DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
|
||||
DataValidator::ValidDepartmentName()
|
||||
),
|
||||
'validation' => DataValidator::notBlank()->length(LengthConfig::MIN_LENGTH_NAME, LengthConfig::MAX_LENGTH_NAME),
|
||||
'error' => ERRORS::INVALID_NAME
|
||||
],
|
||||
]
|
||||
|
@ -55,6 +53,11 @@ class EditDepartmentController extends Controller {
|
|||
$private = Controller::request('private');
|
||||
|
||||
$departmentInstance = Department::getDataStore($departmentId);
|
||||
$createdDepartment = Department::getDataStore($newName, 'name');
|
||||
|
||||
if(!$createdDepartment->isNull() && $createdDepartment->name !== $departmentInstance->name){
|
||||
throw new RequestException(ERRORS::NAME_ALREADY_USED);
|
||||
}
|
||||
|
||||
if($private && $departmentId == Setting::getSetting('default-department-id')->getValue()){
|
||||
throw new RequestException(ERRORS::DEFAULT_DEPARTMENT_CAN_NOT_BE_PRIVATE);
|
||||
|
|
|
@ -162,11 +162,12 @@ class Scripts
|
|||
})
|
||||
end
|
||||
|
||||
def self.createDepartment(nameDepartment = 'validnameDepartment')
|
||||
def self.createDepartment(nameDepartment, isPrivate = 0)
|
||||
request('/system/add-department', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
name: nameDepartment
|
||||
name: nameDepartment,
|
||||
private: isPrivate
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
@ -44,19 +44,45 @@ describe'system/edit-department' do
|
|||
result['status'].should.equal('fail')
|
||||
result['message'].should.equal('INVALID_NAME')
|
||||
|
||||
end
|
||||
|
||||
it 'should success if you change for the same name' do
|
||||
Scripts.createDepartment('thisisAnewName')
|
||||
|
||||
department = $database.getLastRow('department')
|
||||
(department['private']).should.equal(0)
|
||||
|
||||
|
||||
result = request('/system/edit-department', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
name: department['name'],
|
||||
departmentId: department['id'],
|
||||
private:1
|
||||
})
|
||||
|
||||
row = $database.getRow('department', 'thisisAnewName', 'name')
|
||||
(row['private']).should.equal(1)
|
||||
|
||||
result['status'].should.equal('success')
|
||||
|
||||
end
|
||||
|
||||
it 'shouild fail if you use an used name' do
|
||||
Scripts.createDepartment('thistitleisunique')
|
||||
|
||||
lastDepartment = $database.getLastRow('department')
|
||||
|
||||
result = request('/system/edit-department', {
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token,
|
||||
name: lastDepartment['name'],
|
||||
departmentId: 4
|
||||
name: 'thisisAnewName',
|
||||
departmentId: lastDepartment['id'],
|
||||
private:1
|
||||
})
|
||||
|
||||
|
||||
result['status'].should.equal('fail')
|
||||
result['message'].should.equal('INVALID_NAME')
|
||||
|
||||
result['message'].should.equal('NAME_ALREADY_USED')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue