opensupports/tests/staff/invite.rb

133 lines
4.4 KiB
Ruby
Raw Normal View History

describe'/staff/invite' do
Scripts.logout()
2016-12-08 07:21:37 +01:00
Scripts.login($staff[:email], $staff[:password], true)
2016-12-08 03:43:32 +01:00
it 'should if data is wrong' do
result = request('/staff/invite', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'Tyrion Lannister',
email: 'tyrion@opensupports.com',
level: 5,
profilePic: '',
departments: '[1]'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_LEVEL')
result = request('/staff/invite', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'Tyrion Lannister',
email: 'tyrion@opensupports.com',
level: 0,
profilePic: '',
departments: '[1]'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_LEVEL')
result = request('/staff/invite', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'Tyrion Lannister',
email: 'tyrion@opensupports.com',
level: 1,
profilePic: '',
departments: '[1,100]'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_DEPARTMENT')
result = request('/staff/invite', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'Tyrion Lannister',
email: 'tyrion@opensupports.com',
level: 1,
profilePic: '',
departments: 'xd'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_DEPARTMENT')
result = request('/staff/invite', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'Tyrion LannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannisterLannister',
email: 'tyrion@opensupports.com',
level: 1,
profilePic: '',
departments: '[1]'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
result = request('/staff/invite', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: '',
email: 'tyrion@opensupports.com',
level: 1,
profilePic: '',
departments: '[1]'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('INVALID_NAME')
end
2016-12-08 07:21:37 +01:00
it 'should add staff member' do
result = request('/staff/invite', {
2016-12-08 07:21:37 +01:00
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'Tyrion Lannister',
email: 'tyrion@opensupports.com',
level: 2,
2017-02-18 19:55:09 +01:00
profilePic: '',
2016-12-08 07:21:37 +01:00
departments: '[1]'
})
(result['status']).should.equal('success')
recoverpassword = $database.getRow('recoverpassword', 'tyrion@opensupports.com', 'email')
request('/user/recover-password', {
email: 'tyrion@opensupports.com',
password: 'testpassword',
token: recoverpassword['token']
})
2016-12-08 07:21:37 +01:00
row = $database.getRow('staff', result['data']['id'], 'id')
(row['name']).should.equal('Tyrion Lannister')
(row['email']).should.equal('tyrion@opensupports.com')
2017-02-18 19:55:09 +01:00
(row['profile_pic']).should.equal('')
2020-05-13 07:51:51 +02:00
(row['level']).should.equal(2)
row = $database.getRow('department', 1, 'id')
2020-05-13 07:51:51 +02:00
(row['owners']).should.equal(4)
2016-12-29 21:25:45 +01:00
lastLog = $database.getLastRow('log')
(lastLog['type']).should.equal('INVITE')
2016-12-29 21:25:45 +01:00
2016-12-08 07:21:37 +01:00
end
it 'should fail if staff member is alrady a staff' do
result = request('/staff/invite', {
2016-12-08 07:21:37 +01:00
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: 'Tyrion Lannister',
email: 'tyrion@opensupports.com',
level: 2,
2017-02-18 19:55:09 +01:00
profilePic: '',
2016-12-08 07:21:37 +01:00
departments: '[1]'
})
(result['status']).should.equal('fail')
(result['message']).should.equal('ALREADY_A_STAFF')
row = $database.getRow('department', 1, 'id')
2020-05-13 07:51:51 +02:00
(row['owners']).should.equal(4)
2016-12-08 07:21:37 +01:00
end
end