2016-07-04 20:57:00 +02:00
|
|
|
describe '/ticket/create' do
|
2016-08-04 06:37:23 +02:00
|
|
|
request('/user/logout')
|
2016-09-09 05:38:58 +02:00
|
|
|
Scripts.createUser('creator@os4.com','creator','Creator')
|
|
|
|
Scripts.login('creator@os4.com','creator')
|
2016-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
it 'should fail if invalid token is passed' do
|
|
|
|
result = request('/ticket/create', {
|
|
|
|
title: 'GG',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-04 20:18:29 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: 'INVALID_TOKEN'
|
|
|
|
})
|
|
|
|
|
|
|
|
(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-08-04 06:37:23 +02:00
|
|
|
it 'should fail if title is too short' do
|
|
|
|
result = request('/ticket/create', {
|
|
|
|
title: 'GG',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-04 06:37:23 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_TITLE')
|
2016-08-04 06:37:23 +02:00
|
|
|
end
|
2016-06-22 01:16:43 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
it 'should fail if title is very long' do
|
2016-11-04 23:10:32 +01:00
|
|
|
long_text = ''
|
|
|
|
300.times {long_text << 'a'}
|
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
result = request('/ticket/create',{
|
2016-11-04 23:10:32 +01:00
|
|
|
title: long_text,
|
2016-08-04 06:37:23 +02:00
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-04 06:37:23 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_TITLE')
|
2016-08-04 06:37:23 +02:00
|
|
|
end
|
2016-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
it 'should fail if content is too short' do
|
|
|
|
result = request('/ticket/create', {
|
|
|
|
title: 'Winter is coming',
|
|
|
|
content: 'Test',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-04 06:37:23 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-06-22 01:16:43 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_CONTENT')
|
2016-08-04 06:37:23 +02:00
|
|
|
end
|
2016-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 06:37:23 +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-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
result = request('/ticket/create',{
|
|
|
|
title: 'Winter is coming',
|
|
|
|
content: long_text,
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-04 06:37:23 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-06-22 01:16:43 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
(result['status']).should.equal('fail')
|
2016-10-04 23:42:47 +02:00
|
|
|
(result['message']).should.equal('INVALID_CONTENT')
|
2016-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
end
|
2016-06-17 23:43:10 +02:00
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
it 'should fail if departmentId is invalid' do
|
2016-09-09 05:38:58 +02:00
|
|
|
result = request('/ticket/create', {
|
2016-08-04 20:18:29 +02:00
|
|
|
title: 'Winter is coming',
|
|
|
|
content: 'The north remembers',
|
|
|
|
departmentId: 30,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
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_DEPARTMENT')
|
2016-08-04 20:18:29 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
it 'should create ticket if pass data is valid' do
|
2016-09-09 05:38:58 +02:00
|
|
|
result = request('/ticket/create', {
|
2016-08-04 06:37:23 +02:00
|
|
|
title: 'Winter is coming',
|
|
|
|
content: 'The north remembers',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-04 06:37:23 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2016-06-22 01:16:43 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
(result['status']).should.equal('success')
|
2016-08-04 20:18:29 +02:00
|
|
|
|
2016-08-04 06:37:23 +02:00
|
|
|
ticket = $database.getRow('ticket','Winter is coming','title')
|
|
|
|
(ticket['content']).should.equal('The north remembers')
|
2016-08-04 20:18:29 +02:00
|
|
|
(ticket['unread']).should.equal('0')
|
|
|
|
(ticket['closed']).should.equal('0')
|
2016-09-29 22:09:34 +02:00
|
|
|
(ticket['priority']).should.equal('low')
|
2016-08-04 20:18:29 +02:00
|
|
|
(ticket['department_id']).should.equal('1')
|
2016-08-10 03:55:12 +02:00
|
|
|
(ticket['author_id']).should.equal($csrf_userid)
|
2016-08-21 02:16:07 +02:00
|
|
|
(ticket['ticket_number'].size).should.equal(6)
|
2016-08-04 20:18:29 +02:00
|
|
|
|
2016-09-09 05:38:58 +02:00
|
|
|
ticket_user_relation = $database.getRow('ticket_user', ticket['id'],'ticket_id')
|
2016-08-10 03:55:12 +02:00
|
|
|
(ticket_user_relation['user_id']).should.equal($csrf_userid)
|
2016-12-29 21:25:45 +01:00
|
|
|
|
|
|
|
lastLog = $database.getLastRow('log')
|
|
|
|
(lastLog['type']).should.equal('CREATE_TICKET')
|
2016-08-04 06:37:23 +02:00
|
|
|
end
|
2016-08-21 02:16:07 +02:00
|
|
|
|
|
|
|
it 'should set correct ticket number' do
|
|
|
|
result = request('/ticket/create',{
|
|
|
|
title: 'Winter is coming1',
|
|
|
|
content: 'The north remembers',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-21 02:16:07 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
result = request('/ticket/create',{
|
|
|
|
title: 'Winter is coming2',
|
|
|
|
content: 'The north remembers',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-21 02:16:07 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
result = request('/ticket/create',{
|
|
|
|
title: 'Winter is coming3',
|
|
|
|
content: 'The north remembers',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-08-21 02:16:07 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
|
2017-01-12 20:45:01 +01:00
|
|
|
ticket_number_gap = $database.getRow('setting', 'ticket-gap', 'name')['value'].to_i
|
|
|
|
|
2016-08-21 02:16:07 +02:00
|
|
|
ticket0 = $database.getRow('ticket','Winter is coming','title')['ticket_number'].to_i
|
|
|
|
ticket1 = $database.getRow('ticket','Winter is coming1','title')['ticket_number'].to_i
|
|
|
|
ticket2 = $database.getRow('ticket','Winter is coming2','title')['ticket_number'].to_i
|
|
|
|
ticket3 = $database.getRow('ticket','Winter is coming3','title')['ticket_number'].to_i
|
|
|
|
|
2017-01-12 20:45:01 +01:00
|
|
|
(ticket1).should.equal((ticket0 - 100000 + 1 * ticket_number_gap) % 900000 + 100000)
|
|
|
|
(ticket2).should.equal((ticket0 - 100000 + 2 * ticket_number_gap) % 900000 + 100000)
|
|
|
|
(ticket3).should.equal((ticket0 - 100000 + 3 * ticket_number_gap) % 900000 + 100000)
|
2016-08-21 02:16:07 +02:00
|
|
|
end
|
2016-08-10 03:55:12 +02:00
|
|
|
end
|