Ivan - Add file upload and download test [skip ci]
This commit is contained in:
parent
012103c2ad
commit
dffe4a87a0
|
@ -42,7 +42,7 @@ class InitSettingsController extends Controller {
|
|||
'title' => 'Support Center',
|
||||
'url' => 'http://www.opensupports.com/support',
|
||||
'registration' => true,
|
||||
'last-stat-day' => '20170101' //TODO: get current date
|
||||
'last-stat-day' => '20170101', //TODO: get current date
|
||||
'ticket-gap' => Hashing::generateRandomPrime(100000, 999999),
|
||||
'file-gap' => Hashing::generateRandomPrime(100000, 999999),
|
||||
'file-first-number' => Hashing::generateRandomNumber(100000, 999999),
|
||||
|
|
|
@ -55,3 +55,4 @@ require './system/recover-mail-template.rb'
|
|||
require './system/disable-registration.rb'
|
||||
require './system/enable-registration.rb'
|
||||
require './system/get-stats.rb'
|
||||
require './system/file-upload-download.rb'
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
$agent = Mechanize.new
|
||||
|
||||
def plainRequest(path, data = {})
|
||||
uri = 'http://localhost:8080' + path
|
||||
response = $agent.post(uri, data)
|
||||
|
||||
return response
|
||||
end
|
||||
|
||||
def request(path, data = {})
|
||||
uri = 'http://localhost:8080' + path
|
||||
response = $agent.post(uri, data)
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
describe 'File Upload and Download' do
|
||||
request('/user/logout')
|
||||
Scripts.login("creator@os4.com", "creator")
|
||||
|
||||
it 'should upload file when creating ticket' do
|
||||
file = File.new('upload.txt', 'w')
|
||||
file.puts('file content')
|
||||
|
||||
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',
|
||||
'file' => file
|
||||
})
|
||||
(result['status']).should.equal('success');
|
||||
|
||||
ticket = $database.getLastRow('ticket');
|
||||
|
||||
(ticket['file'].include? 'upload.txt').should.equal(true)
|
||||
(File.exist?('../server/files' + ticket['file'])).should.equal(true)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,74 @@
|
|||
describe 'File Upload and Download' do
|
||||
request('/user/logout')
|
||||
Scripts.login('creator@os4.com', 'creator')
|
||||
|
||||
it 'should upload file when creating ticket' do
|
||||
file = File.new('../server/files/upload.txt', 'w+')
|
||||
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,
|
||||
'file' => File.open( "../server/files/upload.txt")
|
||||
})
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getLastRow('ticket')
|
||||
|
||||
(ticket['file'].include? 'upload.txt').should.equal(true)
|
||||
(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']
|
||||
})
|
||||
|
||||
(result.body).should.equal(file.read)
|
||||
end
|
||||
|
||||
it 'should not download if author is not logged' do
|
||||
request('/user/logout')
|
||||
Scripts.login('staff@opensupports.com', 'staff', true)
|
||||
|
||||
ticket = $database.getLastRow('ticket')
|
||||
|
||||
result = plainRequest('/system/download', {
|
||||
'csrf_userid' => $csrf_userid,
|
||||
'csrf_token' => $csrf_token,
|
||||
'file' => ticket['file']
|
||||
})
|
||||
|
||||
(result.body).should.equal('')
|
||||
end
|
||||
|
||||
it 'should download if owner is logged' do
|
||||
ticket = $database.getLastRow('ticket')
|
||||
file = File.open("../server/files/" + ticket['file'])
|
||||
|
||||
request('/staff/assign-ticket', {
|
||||
'csrf_userid' => $csrf_userid,
|
||||
'csrf_token' => $csrf_token,
|
||||
'ticketNumber' => ticket['ticket_number']
|
||||
})
|
||||
|
||||
result = plainRequest('/system/download', {
|
||||
'csrf_userid' => $csrf_userid,
|
||||
'csrf_token' => $csrf_token,
|
||||
'file' => ticket['file']
|
||||
})
|
||||
|
||||
(result.body).should.equal(file.read)
|
||||
end
|
||||
|
||||
end
|
|
@ -25,10 +25,10 @@ describe'/system/get-stats' do
|
|||
$database.query("INSERT INTO log VALUES('', 'COMMENT', NULL, " + yesterday3 + ", NULL, NULL);")
|
||||
end
|
||||
for i in 0..8
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
||||
end
|
||||
for i in 0..4
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, NULL, " + yesterday3 + ", NULL, NULL, 1);")
|
||||
end
|
||||
|
||||
#day 2
|
||||
|
@ -45,10 +45,10 @@ describe'/system/get-stats' do
|
|||
$database.query("INSERT INTO log VALUES('', 'COMMENT', NULL, " + yesterday2 + ", NULL, NULL);")
|
||||
end
|
||||
for i in 0..10
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
||||
end
|
||||
for i in 0..2
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, NULL, " + yesterday2 + ", NULL, NULL, 1);")
|
||||
end
|
||||
|
||||
#day 3
|
||||
|
@ -65,10 +65,10 @@ describe'/system/get-stats' do
|
|||
$database.query("INSERT INTO log VALUES('', 'COMMENT', NULL, " + yesterday + ", NULL, NULL);")
|
||||
end
|
||||
for i in 0..3
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, " + yesterday + ", NULL, NULL, 1);")
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'CLOSE', NULL, NULL, " + yesterday + ", NULL, NULL, 1);")
|
||||
end
|
||||
for i in 0..7
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, " + yesterday + ", NULL, NULL, 1);")
|
||||
$database.query("INSERT INTO ticketevent VALUES('', 'ASSIGN', NULL, NULL, " + yesterday + ", NULL, NULL, 1);")
|
||||
end
|
||||
|
||||
@result = request('/system/get-stats', {
|
||||
|
|
Loading…
Reference in New Issue