2016-12-08 07:21:37 +01:00
|
|
|
describe'/staff/edit' do
|
|
|
|
request('/user/logout')
|
|
|
|
Scripts.login($staff[:email], $staff[:password], true)
|
|
|
|
|
|
|
|
it 'should edit another staff member' do
|
2018-10-29 23:32:03 +01:00
|
|
|
staffId = $database.getRow('staff','tyrion@opensupports.com','email')['id']
|
2016-12-08 07:21:37 +01:00
|
|
|
result= request('/staff/edit', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
email: 'LittleLannister@opensupports.com',
|
|
|
|
level: 1,
|
|
|
|
departments: '[1, 2]',
|
2018-10-29 23:32:03 +01:00
|
|
|
staffId: staffId
|
2016-12-08 07:21:37 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
2018-10-29 23:32:03 +01:00
|
|
|
row = $database.getRow('staff', staffId, 'id')
|
2016-12-08 07:21:37 +01:00
|
|
|
|
2018-08-14 20:21:36 +02:00
|
|
|
(row['email']).should.equal('littlelannister@opensupports.com')
|
2016-12-08 07:21:37 +01:00
|
|
|
(row['level']).should.equal('1')
|
|
|
|
|
2018-10-29 23:32:03 +01:00
|
|
|
rows = $database.getRow('department_staff', staffId, 'staff_id')
|
2016-12-08 07:21:37 +01:00
|
|
|
|
|
|
|
(rows['department_id']).should.equal('1')
|
|
|
|
|
2016-12-10 23:06:21 +01:00
|
|
|
row = $database.getRow('department', 1, 'id')
|
2019-10-01 21:40:30 +02:00
|
|
|
(row['owners']).should.equal('4')
|
2016-12-10 23:06:21 +01:00
|
|
|
|
|
|
|
row = $database.getRow('department', 2, 'id')
|
2019-10-01 21:40:30 +02:00
|
|
|
(row['owners']).should.equal('3')
|
2016-12-08 07:21:37 +01:00
|
|
|
end
|
|
|
|
|
2019-10-01 21:40:30 +02:00
|
|
|
it 'should edit own data staff' do
|
2016-12-08 07:21:37 +01:00
|
|
|
request('/staff/add', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
name: 'Arya Stark',
|
|
|
|
password: 'starkpassword',
|
|
|
|
email: 'arya@opensupports.com',
|
2019-10-01 21:40:30 +02:00
|
|
|
level: 1,
|
2017-02-18 19:55:09 +01:00
|
|
|
profilePic: '',
|
2016-12-08 07:21:37 +01:00
|
|
|
departments: '[1]'
|
|
|
|
})
|
2018-04-18 20:31:17 +02:00
|
|
|
|
2018-10-29 23:32:03 +01:00
|
|
|
row = $database.getRow('staff', 'arya@opensupports.com', 'email')
|
2016-12-08 07:21:37 +01:00
|
|
|
|
|
|
|
result = request('/staff/edit', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
2018-04-18 20:31:17 +02:00
|
|
|
staffId: row['id'],
|
|
|
|
email: 'ayra2@opensupports.com',
|
|
|
|
departments: '[1, 2, 3]',
|
2019-10-01 21:40:30 +02:00
|
|
|
sendEmailOnNewTicket: 1,
|
|
|
|
level: 2
|
2016-12-08 07:21:37 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
2018-04-18 20:31:17 +02:00
|
|
|
row = $database.getRow('staff', 'Arya Stark', 'name')
|
2016-12-08 07:21:37 +01:00
|
|
|
|
2018-04-18 20:31:17 +02:00
|
|
|
(row['email']).should.equal('ayra2@opensupports.com')
|
2016-12-08 07:21:37 +01:00
|
|
|
(row['level']).should.equal('2')
|
2018-04-18 20:31:17 +02:00
|
|
|
(row['send_email_on_new_ticket']).should.equal('0')
|
2016-12-08 07:21:37 +01:00
|
|
|
|
2016-12-10 23:06:21 +01:00
|
|
|
row = $database.getRow('department', 1, 'id')
|
2019-10-01 21:40:30 +02:00
|
|
|
(row['owners']).should.equal('5')
|
2016-12-10 23:06:21 +01:00
|
|
|
|
2018-04-18 20:31:17 +02:00
|
|
|
row = $database.getRow('department', 2, 'id')
|
2019-10-01 21:40:30 +02:00
|
|
|
(row['owners']).should.equal('4')
|
2018-04-18 20:31:17 +02:00
|
|
|
|
|
|
|
row = $database.getRow('department', 3, 'id')
|
|
|
|
(row['owners']).should.equal('2')
|
|
|
|
|
|
|
|
Scripts.logout()
|
|
|
|
Scripts.login('ayra2@opensupports.com', 'starkpassword', true)
|
|
|
|
result = request('/staff/edit', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
sendEmailOnNewTicket: 1
|
|
|
|
})
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
row = $database.getRow('staff', 'Arya Stark', 'name')
|
|
|
|
(row['send_email_on_new_ticket']).should.equal('1')
|
2016-12-08 07:21:37 +01:00
|
|
|
end
|
2019-10-01 21:40:30 +02:00
|
|
|
|
|
|
|
it 'should fail if is not staff logged' do
|
|
|
|
|
|
|
|
request('/user/logout')
|
|
|
|
|
|
|
|
result = request('/staff/edit', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
staffId: 1,
|
|
|
|
email: 'stafffalse@opensupports.com',
|
|
|
|
departments: '[1, 2]',
|
|
|
|
sendEmailOnNewTicket: 1
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('fail')
|
|
|
|
(result['message']).should.equal('NO_PERMISSION')
|
|
|
|
|
|
|
|
|
|
|
|
end
|
2018-04-18 20:31:17 +02:00
|
|
|
end
|