2016-05-11 03:35:36 +02:00
|
|
|
class Scripts
|
2016-07-19 22:39:26 +02:00
|
|
|
def self.createUser(email = 'steve@jobs.com', password = 'custompassword', name = 'steve jobs')
|
2016-05-11 03:35:36 +02:00
|
|
|
response = request('/user/signup', {
|
2016-08-04 20:18:29 +02:00
|
|
|
:name => name,
|
|
|
|
:email => email,
|
|
|
|
:password => password
|
2016-05-11 03:35:36 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if response['status'] === 'fail'
|
2016-12-29 06:04:35 +01:00
|
|
|
raise response['message']
|
2016-05-15 01:22:46 +02:00
|
|
|
end
|
2016-12-23 05:27:21 +01:00
|
|
|
userRow = $database.getRow('user', email, 'email')
|
2017-02-25 07:42:10 +01:00
|
|
|
request('/user/verify', {
|
2016-12-23 05:27:21 +01:00
|
|
|
:email => email,
|
|
|
|
:token => userRow['verification_token']
|
|
|
|
})
|
2016-05-11 03:35:36 +02:00
|
|
|
end
|
2016-08-04 20:18:29 +02:00
|
|
|
|
2016-09-25 06:16:10 +02:00
|
|
|
def self.login(email = 'steve@jobs.com', password = 'custompassword', staff = false)
|
2016-08-04 20:18:29 +02:00
|
|
|
request('/user/logout')
|
|
|
|
response = request('/user/login', {
|
|
|
|
:email => email,
|
2016-09-25 06:16:10 +02:00
|
|
|
:password => password,
|
|
|
|
:staff => staff
|
2016-08-04 20:18:29 +02:00
|
|
|
})
|
|
|
|
|
2016-09-09 05:38:58 +02:00
|
|
|
if response['data'].any?
|
|
|
|
$csrf_userid = response['data']['userId']
|
|
|
|
$csrf_token = response['data']['token']
|
|
|
|
end
|
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
response['data']
|
|
|
|
end
|
2016-09-09 05:38:58 +02:00
|
|
|
|
2017-02-25 07:42:10 +01:00
|
|
|
def self.createTicket(title = 'Winter is coming')
|
2016-09-09 05:38:58 +02:00
|
|
|
result = request('/ticket/create', {
|
2017-02-25 07:42:10 +01:00
|
|
|
title: title,
|
2016-09-09 05:38:58 +02:00
|
|
|
content: 'The north remembers',
|
|
|
|
departmentId: 1,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-09-09 05:38:58 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
|
|
|
|
result['data']
|
|
|
|
end
|
2017-01-13 21:06:49 +01:00
|
|
|
|
|
|
|
def self.createAPIKey(name)
|
2017-02-25 07:42:10 +01:00
|
|
|
request('/system/add-api-key', {
|
2017-01-13 21:06:49 +01:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
name: name
|
|
|
|
})
|
|
|
|
end
|
2016-05-11 03:35:36 +02:00
|
|
|
end
|