2016-12-12 06:12:17 +01:00
|
|
|
describe'system/edit-department' do
|
2021-11-05 21:06:08 +01:00
|
|
|
Scripts.logout()
|
2016-12-12 06:12:17 +01:00
|
|
|
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')
|
2016-12-29 21:25:45 +01:00
|
|
|
|
|
|
|
lastLog = $database.getLastRow('log')
|
|
|
|
(lastLog['type']).should.equal('EDIT_DEPARTMENT')
|
2016-12-12 06:12:17 +01:00
|
|
|
end
|
2021-11-24 18:21:16 +01:00
|
|
|
|
|
|
|
it 'should fail if name is invalid' do
|
|
|
|
result = request('/system/edit-department', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
name: '',
|
|
|
|
departmentId: 4
|
|
|
|
})
|
|
|
|
result['status'].should.equal('fail')
|
|
|
|
result['message'].should.equal('INVALID_NAME')
|
|
|
|
|
|
|
|
long_name = ''
|
|
|
|
201.times {long_name << 'A'}
|
|
|
|
|
|
|
|
result = request('/system/edit-department', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
name: long_name,
|
|
|
|
departmentId: 4
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
result['status'].should.equal('fail')
|
|
|
|
result['message'].should.equal('INVALID_NAME')
|
|
|
|
|
2021-12-17 18:10:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should success if you change for the same name' do
|
|
|
|
Scripts.createDepartment('thisisAnewName')
|
2021-12-13 13:57:20 +01:00
|
|
|
|
2021-12-17 18:10:57 +01:00
|
|
|
department = $database.getLastRow('department')
|
|
|
|
(department['private']).should.equal(0)
|
|
|
|
|
|
|
|
|
2021-12-13 13:57:20 +01:00
|
|
|
result = request('/system/edit-department', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
2021-12-17 18:10:57 +01:00
|
|
|
name: department['name'],
|
|
|
|
departmentId: department['id'],
|
|
|
|
private:1
|
2021-12-13 13:57:20 +01:00
|
|
|
})
|
2021-11-24 18:21:16 +01:00
|
|
|
|
2021-12-17 18:10:57 +01:00
|
|
|
row = $database.getRow('department', 'thisisAnewName', 'name')
|
|
|
|
(row['private']).should.equal(1)
|
|
|
|
|
|
|
|
result['status'].should.equal('success')
|
2021-12-13 20:32:53 +01:00
|
|
|
|
2021-12-17 18:10:57 +01:00
|
|
|
end
|
2021-12-13 20:32:53 +01:00
|
|
|
|
2021-12-17 18:10:57 +01:00
|
|
|
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: 'thisisAnewName',
|
|
|
|
departmentId: lastDepartment['id'],
|
|
|
|
private:1
|
|
|
|
})
|
|
|
|
|
|
|
|
result['status'].should.equal('fail')
|
|
|
|
result['message'].should.equal('NAME_ALREADY_USED')
|
2021-11-24 18:21:16 +01:00
|
|
|
end
|
|
|
|
|
2016-12-29 21:25:45 +01:00
|
|
|
end
|