2016-08-04 22:18:42 +02:00
|
|
|
describe '/ticket/comment/' do
|
2016-09-09 05:38:58 +02:00
|
|
|
Scripts.createUser('commenter@os4.com', 'commenter', 'Commenter')
|
|
|
|
Scripts.login('commenter@os4.com', 'commenter')
|
|
|
|
|
|
|
|
result = Scripts.createTicket
|
|
|
|
|
|
|
|
@ticketNumber = result['ticketNumber']
|
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
it 'should fail if invalid token is passed' do
|
|
|
|
result = request('/ticket/comment', {
|
|
|
|
content: 'some comment content',
|
2016-09-09 05:38:58 +02:00
|
|
|
ticketId: @ticketNumber,
|
2016-08-04 20:18:29 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: 'INVALID_TOKEN'
|
|
|
|
})
|
2016-07-06 01:40:30 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('NO_PERMISSION')
|
2016-08-04 20:18:29 +02:00
|
|
|
end
|
2016-07-06 01:40:30 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
it 'should fail if content is too short' do
|
|
|
|
result = request('/ticket/comment', {
|
|
|
|
content: 'Test',
|
2016-09-09 05:38:58 +02:00
|
|
|
ticketNumber: @ticketNumber,
|
2016-08-04 20:18:29 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-07-06 01:40:30 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_CONTENT')
|
2016-08-04 20:18:29 +02:00
|
|
|
end
|
2016-08-04 06:37:23 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
it 'should fail if content is very long' do
|
|
|
|
long_text = ''
|
2016-12-21 21:07:34 +01:00
|
|
|
6000.times {long_text << 'a'}
|
2016-08-04 06:37:23 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
result = request('/ticket/comment', {
|
|
|
|
content: long_text,
|
2016-09-09 05:38:58 +02:00
|
|
|
ticketNumber: @ticketNumber,
|
2016-08-04 20:18:29 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-07-06 01:40:30 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_CONTENT')
|
2016-07-06 01:40:30 +02:00
|
|
|
end
|
2016-08-04 20:18:29 +02:00
|
|
|
|
|
|
|
it 'should fail if ticket does not exist' do
|
|
|
|
result = request('/ticket/comment', {
|
|
|
|
content: 'some comment content',
|
2016-09-09 05:38:58 +02:00
|
|
|
ticketNumber: 30,
|
2016-08-04 20:18:29 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_TICKET')
|
2016-08-04 20:18:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should add comment to ticket' do
|
|
|
|
result = request('/ticket/comment', {
|
|
|
|
content: 'some comment content',
|
2016-09-09 05:38:58 +02:00
|
|
|
ticketNumber: @ticketNumber,
|
2016-08-04 20:18:29 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
2016-09-09 05:38:58 +02:00
|
|
|
ticket = $database.getRow('ticket', @ticketNumber, 'ticket_number')
|
2016-09-29 19:41:59 +02:00
|
|
|
comment = $database.getRow('ticketevent', ticket['id'], 'ticket_id')
|
2016-08-04 20:18:29 +02:00
|
|
|
(comment['content']).should.equal('some comment content')
|
2016-09-29 19:41:59 +02:00
|
|
|
(comment['type']).should.equal('COMMENT')
|
|
|
|
(comment['author_user_id']).should.equal($csrf_userid)
|
2016-10-21 21:38:08 +02:00
|
|
|
(ticket['unread_staff']).should.equal('1')
|
2016-12-29 21:25:45 +01:00
|
|
|
|
|
|
|
lastLog = $database.getLastRow('log')
|
2017-01-06 22:40:33 +01:00
|
|
|
(lastLog['type']).should.equal('COMMENT')
|
2016-08-04 20:18:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail if user is not the author nor owner' do
|
2016-09-09 05:38:58 +02:00
|
|
|
Scripts.createUser('no_commenter@comment.com', 'no_commenter', 'No Commenter')
|
|
|
|
Scripts.login('no_commenter@comment.com', 'no_commenter')
|
2016-08-04 20:18:29 +02:00
|
|
|
|
|
|
|
result = request('/ticket/comment', {
|
|
|
|
content: 'some comment content',
|
2016-09-09 05:38:58 +02:00
|
|
|
ticketNumber: @ticketNumber,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
2016-08-04 20:18:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('NO_PERMISSION')
|
2016-08-04 20:18:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
#it 'should add comment if logged as ticket owner' do
|
|
|
|
|
|
|
|
#end
|
2016-08-10 03:55:12 +02:00
|
|
|
end
|