opensupports/tests/scripts.rb

182 lines
5.2 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
def self.inviteUser(email, name='genericName')
response = request('/user/invite', {
:name => name,
:email => email,
})
end
def self.inviteStaff(email, name='validName', level=1, profilePic='', departments: '[1]')
response = request('/staff/invite', {
:name => name,
:email => email,
:level => level,
:departments => departments.to_str
})
end
def self.createStaff(email, password, name, level='1') # WARNING: NOT USED ANYWHERE
2018-03-12 23:31:54 +01:00
departments = request('/system/get-settings', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
2019-02-14 23:43:22 +01:00
})['data']['departments']
2018-03-12 23:31:54 +01:00
departments = departments.collect { |x| x.id }
response = request('/staff/invite', {
2018-03-12 23:31:54 +01:00
:name => name,
:email => email,
:level => level,
:departments => departments.to_string
})
recoverpassword = $database.getRow('recoverpassword', email, 'email')
response = request('/user/recover-password', {
email: email,
password: password,
token: recoverpassword['token']
})
2018-03-12 23:31:54 +01:00
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)
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', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
2018-04-18 20:31:17 +02:00
end
def self.createTicket(title = 'Winter is coming',content = 'The north remembers', department = 1)
result = request('/ticket/create', {
2017-02-25 07:42:10 +01:00
title: title,
2019-06-27 03:04:56 +02:00
content: content,
departmentId: department,
language: 'en',
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
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, canCreateUsers=0, canCreateTickets=0, canCheckTickets=0, shouldReturnTicketNumber=0)
2017-02-25 07:42:10 +01:00
request('/system/add-api-key', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
2019-11-16 21:16:53 +01:00
name: name,
canCreateUsers: canCreateUsers,
canCreateTickets: canCreateTickets,
canCheckTickets: canCheckTickets,
shouldReturnTicketNumber: shouldReturnTicketNumber
})
end
2019-02-13 03:37:27 +01:00
def self.createTextCustomField(name,description)
request('/system/add-custom-field', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: name,
type: 'text',
description: description
})
end
2019-02-25 17:34:22 +01:00
def self.createTag(name, color)
request('/ticket/create-tag', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: name,
color: color
})
end
2019-07-02 01:38:34 +02:00
def self.assignTicket(ticketnumber)
request('/staff/assign-ticket', {
ticketNumber: ticketnumber,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
end
2019-06-27 03:04:56 +02:00
def self.commentTicket(ticketnumber,content)
request('/ticket/comment', {
content: content,
ticketNumber: ticketnumber,
csrf_userid: $csrf_userid,
csrf_token: $csrf_token
})
end
def self.createDepartment(nameDepartment, isPrivate = 0)
request('/system/add-department', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
name: nameDepartment,
private: isPrivate
})
end
def self.updateLockedDepartmentSetting(value = 0)
request('/system/edit-settings', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
"default-is-locked" => value
})
end
end