2017-01-14 01:58:59 +01:00
|
|
|
describe 'File Upload and Download' do
|
|
|
|
request('/user/logout')
|
|
|
|
Scripts.login('creator@os4.com', 'creator')
|
|
|
|
|
|
|
|
it 'should upload file when creating ticket' do
|
2017-06-20 21:47:27 +02:00
|
|
|
file = File.new('../server/files/upload(3).txt', 'w+')
|
2017-01-14 01:58:59 +01:00
|
|
|
file.puts('file content')
|
|
|
|
file.close
|
|
|
|
|
|
|
|
result = request('/ticket/create', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'title' => 'Ticket with file',
|
|
|
|
'content' => 'this is a ticket that contains a file',
|
|
|
|
'language' => 'en',
|
|
|
|
'departmentId' => 1,
|
2017-06-20 21:47:27 +02:00
|
|
|
'file' => File.open( "../server/files/upload(3).txt")
|
2017-01-14 01:58:59 +01:00
|
|
|
})
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
|
2017-06-20 21:47:27 +02:00
|
|
|
(ticket['file'].include? 'upload_3_.txt').should.equal(true)
|
2018-09-20 19:50:44 +02:00
|
|
|
(ticket['file'].include? ('' + ticket['ticket_number'] + '_')).should.equal(true)
|
2017-01-14 01:58:59 +01:00
|
|
|
(File.exist? ('../server/files/' + ticket['file'])).should.equal(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should download file if author is logged' do
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
file = File.open("../server/files/" + ticket['file'])
|
|
|
|
|
|
|
|
result = plainRequest('/system/download', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'file' => ticket['file']
|
2017-02-15 07:08:48 +01:00
|
|
|
}, 'GET')
|
2017-01-14 01:58:59 +01:00
|
|
|
|
|
|
|
(result.body).should.equal(file.read)
|
|
|
|
end
|
|
|
|
|
2017-06-26 00:03:56 +02:00
|
|
|
it 'should download if department owner is logged' do
|
2017-01-14 01:58:59 +01:00
|
|
|
request('/user/logout')
|
|
|
|
Scripts.login('staff@opensupports.com', 'staff', true)
|
|
|
|
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
file = File.open("../server/files/" + ticket['file'])
|
|
|
|
|
|
|
|
result = plainRequest('/system/download', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'file' => ticket['file']
|
2017-02-15 07:08:48 +01:00
|
|
|
}, 'GET')
|
2017-01-14 01:58:59 +01:00
|
|
|
|
|
|
|
(result.body).should.equal(file.read)
|
|
|
|
end
|
|
|
|
|
2017-02-18 19:55:09 +01:00
|
|
|
it 'should upload profile picture' do
|
|
|
|
file = File.new('../server/files/profile.jpg', 'w+')
|
|
|
|
file.puts('file content')
|
|
|
|
file.close
|
|
|
|
|
|
|
|
request('/staff/edit', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'staffId' => $csrf_userid,
|
|
|
|
'file' => File.open( "../server/files/profile.jpg")
|
|
|
|
})
|
|
|
|
|
|
|
|
user = $database.getRow('staff', $csrf_userid)
|
2018-09-20 19:50:44 +02:00
|
|
|
(user['profile_pic'][0] == 'p').should.equal(true)
|
2017-02-18 19:55:09 +01:00
|
|
|
|
|
|
|
result = plainRequest('/system/download', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'file' => user['profile_pic']
|
|
|
|
}, 'GET')
|
|
|
|
|
|
|
|
(result.body).should.include('file content')
|
|
|
|
end
|
2018-09-20 19:50:44 +02:00
|
|
|
|
|
|
|
it 'should add images to ticket content when creating a new ticket' do
|
|
|
|
request('/user/logout')
|
|
|
|
Scripts.login('creator@os4.com', 'creator')
|
|
|
|
|
|
|
|
file = File.open( "../server/files/profile.jpg")
|
|
|
|
|
|
|
|
result = request('/ticket/create', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'title' => 'Ticket with file',
|
|
|
|
'content' => 'this is a ticket <img src="IMAGE_PATH_0" /> that contains images <img src="IMAGE_PATH_1" />',
|
|
|
|
'language' => 'en',
|
|
|
|
'departmentId' => 1,
|
|
|
|
'images' => 2,
|
|
|
|
'image_0' => File.open( "../server/files/profile.jpg"),
|
|
|
|
'image_1' => File.open( "../server/files/profile.jpg"),
|
|
|
|
})
|
|
|
|
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
|
|
|
|
(ticket['content'].include? '_profile.jpg').should.equal(true)
|
|
|
|
end
|
2017-01-14 01:58:59 +01:00
|
|
|
end
|