opensupports/tests/article/topic.rb

95 lines
2.9 KiB
Ruby
Raw Normal View History

2016-11-23 02:27:05 +01:00
describe 'Topic paths' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
it 'should add topic correctly' do
result = request('/article/add-topic', {
name: 'Server management',
icon: 'cogs',
iconColor: 'red',
2018-11-08 18:51:04 +01:00
private: 0,
2016-11-23 02:27:05 +01:00
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
topic = $database.getRow('topic', result['data']['topicId'])
(topic['name']).should.equal('Server management')
(topic['icon_color']).should.equal('red')
(topic['icon']).should.equal('cogs')
2018-11-08 18:51:04 +01:00
(topic['private']).should.equal('0')
2016-12-29 21:25:45 +01:00
lastLog = $database.getLastRow('log')
(lastLog['type']).should.equal('ADD_TOPIC')
2016-11-23 02:27:05 +01:00
end
it 'should edit topic correctly' do
result = request('/article/edit-topic', {
topicId: 1,
name: 'Installation issues',
iconColor: 'blue',
2018-11-08 18:51:04 +01:00
private: 1,
2016-11-23 02:27:05 +01:00
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
topic = $database.getRow('topic', 1)
(topic['name']).should.equal('Installation issues')
(topic['icon_color']).should.equal('blue')
(topic['icon']).should.equal('cogs')
2018-11-08 18:51:04 +01:00
(topic['private']).should.equal('1')
2016-11-23 02:27:05 +01:00
end
it 'should delete topic correctly' do
result = request('/article/delete-topic', {
topicId: 1,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('success')
2016-12-29 21:25:45 +01:00
2017-04-19 02:21:16 +02:00
topic = $database.getRow('topic', 1)
(topic).should.equal(nil)
2016-12-29 21:25:45 +01:00
lastLog = $database.getLastRow('log')
(lastLog['type']).should.equal('DELETE_TOPIC')
2016-11-23 02:27:05 +01:00
end
it 'should deny permission if it is not logged as staff' do
request('/user/logout')
Scripts.login('tyrion@opensupports.com', 'tyrionl')
result = request('/article/add-topic', {
name: 'Server management',
icon: 'cogs',
iconColor: 'red',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
result = request('/article/edit-topic', {
topicId: 1,
name: 'Installation issues',
iconColor: 'blue',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
result = request('/article/delete-topic', {
topicId: 1,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
(result['status']).should.equal('fail')
(result['message']).should.equal('NO_PERMISSION')
end
2016-12-29 21:25:45 +01:00
end