opensupports/tests/scripts.rb

101 lines
2.7 KiB
Ruby
Raw Normal View History

class Scripts
def self.createUser(email = 'steve@jobs.com', password = 'custompassword', name = 'steve jobs')
response = request('/user/signup', {
:name => name,
:email => email,
:password => password
})
if response['status'] === 'fail'
raise response['message']
2016-05-15 01:22:46 +02:00
end
userRow = $database.getRow('user', email, 'email')
2017-02-25 07:42:10 +01:00
request('/user/verify', {
:email => email,
:token => userRow['verification_token']
})
end
2018-03-12 23:31:54 +01:00
def self.createStaff(email, password, name, level='1')
departments = request('/system/get-settings', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})['departments']
departments = departments.collect { |x| x.id }
response = request('/staff/add', {
:name => name,
:email => email,
:password => password,
:level => level,
:departments => departments.to_string
})
if response['status'] === 'fail'
raise response['message']
end
end
2018-10-29 23:32:03 +01:00
def self.deleteStaff(staffId)
2018-10-29 15:32:31 +01:00
response = request('/staff/delete', {
2018-10-29 23:32:03 +01:00
staffId: staffId,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
2018-10-29 15:32:31 +01:00
})
if response['status'] === 'fail'
raise response['message']
end
end
2018-03-12 23:31:54 +01:00
def self.login(email = 'steve@jobs.com', password = 'custompassword', staff = false)
request('/user/logout')
response = request('/user/login', {
:email => email,
:password => password,
:staff => staff
})
if response['data'].any?
$csrf_userid = response['data']['userId']
$csrf_token = response['data']['token']
end
response['data']
end
2018-04-18 20:31:17 +02:00
def self.logout()
request('/user/logout')
end
2017-02-25 07:42:10 +01:00
def self.createTicket(title = 'Winter is coming')
result = request('/ticket/create', {
2017-02-25 07:42:10 +01:00
title: title,
content: 'The north remembers',
departmentId: 1,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
result['data']
end
2018-07-12 07:08:37 +02:00
def self.closeTicket(ticketNumber)
result = request('/ticket/close', {
ticketNumber:ticketNumber,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
result['data']
end
def self.createAPIKey(name)
2017-02-25 07:42:10 +01:00
request('/system/add-api-key', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: name
})
end
end