2018-09-28 00:46:30 +02:00
|
|
|
describe 'Enable/disable user' do
|
2021-11-11 21:17:39 +01:00
|
|
|
user = $database.getRow('user', 'login@os4.com', 'email')
|
2018-09-28 00:46:30 +02:00
|
|
|
|
|
|
|
describe '/user/disable' do
|
2021-11-11 21:17:39 +01:00
|
|
|
Scripts.logout()
|
|
|
|
Scripts.login($staff[:email], $staff[:password], true)
|
2018-09-28 00:46:30 +02:00
|
|
|
|
|
|
|
it 'should disable user' do
|
|
|
|
result = request('/user/disable', {
|
|
|
|
userId: user['id'],
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
})
|
|
|
|
|
2021-11-11 21:17:39 +01:00
|
|
|
(result['status']).should.equal('success')
|
2018-09-28 00:46:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not disable user if already disabled' do
|
|
|
|
result = request('/user/disable', {
|
|
|
|
userId: user['id'],
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
})
|
|
|
|
|
2021-11-11 21:17:39 +01:00
|
|
|
(result['status']).should.equal('fail')
|
2018-09-28 00:46:30 +02:00
|
|
|
(result['message']).should.equal('ALREADY_DISABLED')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should reject login' do
|
2021-11-11 21:17:39 +01:00
|
|
|
Scripts.logout()
|
2018-09-28 00:46:30 +02:00
|
|
|
result = request('/user/login', {
|
|
|
|
email: 'login@os4.com',
|
|
|
|
password: 'loginpass'
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('fail')
|
|
|
|
(result['message']).should.equal('USER_DISABLED')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '/user/enable' do
|
2021-11-11 21:17:39 +01:00
|
|
|
Scripts.logout()
|
|
|
|
Scripts.login($staff[:email], $staff[:password], true)
|
2018-09-28 00:46:30 +02:00
|
|
|
|
|
|
|
it 'should enable user' do
|
|
|
|
result = request('/user/enable', {
|
|
|
|
userId: user['id'],
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
})
|
|
|
|
|
2021-11-11 21:17:39 +01:00
|
|
|
(result['status']).should.equal('success')
|
2018-09-28 00:46:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not enable user if already enabled' do
|
|
|
|
result = request('/user/enable', {
|
|
|
|
userId: user['id'],
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
})
|
|
|
|
|
2021-11-11 21:17:39 +01:00
|
|
|
(result['status']).should.equal('fail')
|
2018-09-28 00:46:30 +02:00
|
|
|
(result['message']).should.equal('ALREADY_ENABLED')
|
|
|
|
|
|
|
|
result = request('/user/enable', {
|
|
|
|
userId: 1,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
})
|
|
|
|
|
2021-11-11 21:17:39 +01:00
|
|
|
(result['status']).should.equal('fail')
|
2018-09-28 00:46:30 +02:00
|
|
|
(result['message']).should.equal('ALREADY_ENABLED')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|