samanage 2.1.18 → 2.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/samanage/api.rb +8 -8
- data/lib/samanage/api/attachments.rb +18 -20
- data/lib/samanage/api/incidents.rb +26 -39
- data/lib/samanage/error.rb +1 -1
- data/lib/samanage/version.rb +3 -1
- data/spec/api/samanage_incident_spec.rb +40 -38
- data/spec/api/samanage_user_spec.rb +25 -27
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a13aff3441a2b195624d0ddd7f890f218cecd85949110dc1dd493e67c04b2c90
|
|
4
|
+
data.tar.gz: 279f7937d734914300265dd92d4144135eea997ac9282a721a6c696aaaf5b476
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e91607ebc97987f438434c4c99391bd68ef9c6e96eb7f31b63d9abb66516399ccc872be9d074ce863ba4ad59fe9b1a90773c39252daef27585c1f43a850d9cfd
|
|
7
|
+
data.tar.gz: d2b2f7890fb41e851a24caeb4101945f7bed0c3d933e397d1471eb22b19cbb69cd39309bd0b8b0038a7229f2fd284239a3ad86f74f7ee1cc1e3413832dfcb697
|
data/lib/samanage/api.rb
CHANGED
|
@@ -66,7 +66,7 @@ module Samanage
|
|
|
66
66
|
end
|
|
67
67
|
rescue => e
|
|
68
68
|
puts "Invalid JSON: #{payload.inspect}"
|
|
69
|
-
raise Samanage::Error.new(error: e, response: nil)
|
|
69
|
+
raise Samanage::Error.new(error: e, response: nil, options: options)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
token = token ||= self.token
|
|
@@ -93,7 +93,7 @@ module Samanage
|
|
|
93
93
|
when 'delete'
|
|
94
94
|
api_call = self.class.delete(full_path, body: payload, headers: headers, query: options)
|
|
95
95
|
else
|
|
96
|
-
raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
|
|
96
|
+
raise Samanage::Error.new(response: {response: 'Unknown HTTP method'}, options: options)
|
|
97
97
|
end
|
|
98
98
|
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, Net::ReadTimeout, OpenSSL::SSL::SSLError, Errno::ENETDOWN, Errno::ECONNRESET, Errno::ENOENT, EOFError, Net::HTTPTooManyRequests, SocketError => e
|
|
99
99
|
retries += 1
|
|
@@ -104,7 +104,7 @@ module Samanage
|
|
|
104
104
|
else
|
|
105
105
|
error = e
|
|
106
106
|
response = e.class
|
|
107
|
-
raise Samanage::InvalidRequest.new(error: error, response: response)
|
|
107
|
+
raise Samanage::InvalidRequest.new(error: error, response: response, options: options)
|
|
108
108
|
end
|
|
109
109
|
rescue => e
|
|
110
110
|
retries += 1
|
|
@@ -115,7 +115,7 @@ module Samanage
|
|
|
115
115
|
else
|
|
116
116
|
error = e
|
|
117
117
|
response = e.class
|
|
118
|
-
raise Samanage::InvalidRequest.new(error: error, response: response)
|
|
118
|
+
raise Samanage::InvalidRequest.new(error: error, response: response, options: options)
|
|
119
119
|
end
|
|
120
120
|
end
|
|
121
121
|
|
|
@@ -144,19 +144,19 @@ module Samanage
|
|
|
144
144
|
response[:data] = api_call.body
|
|
145
145
|
error = response[:response]
|
|
146
146
|
self.authorized = false
|
|
147
|
-
raise Samanage::AuthorizationError.new(error: error,response: response)
|
|
147
|
+
raise Samanage::AuthorizationError.new(error: error,response: response, options: options)
|
|
148
148
|
when 404
|
|
149
149
|
response[:data] = api_call.body
|
|
150
150
|
error = response[:response]
|
|
151
|
-
raise Samanage::NotFound.new(error: error, response: response)
|
|
151
|
+
raise Samanage::NotFound.new(error: error, response: response, options: options)
|
|
152
152
|
when 422
|
|
153
153
|
response[:data] = api_call.body
|
|
154
154
|
error = response[:response]
|
|
155
|
-
raise Samanage::InvalidRequest.new(error: error, response: response)
|
|
155
|
+
raise Samanage::InvalidRequest.new(error: error, response: response, options: options)
|
|
156
156
|
else
|
|
157
157
|
response[:data] = api_call.body
|
|
158
158
|
error = response[:response]
|
|
159
|
-
raise Samanage::InvalidRequest.new(error: error, response: response)
|
|
159
|
+
raise Samanage::InvalidRequest.new(error: error, response: response, options: options)
|
|
160
160
|
end
|
|
161
161
|
end
|
|
162
162
|
|
|
@@ -1,45 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Samanage
|
|
2
4
|
class Api
|
|
3
5
|
def download_attachment(attachment: {}, filename: nil, path: nil)
|
|
4
6
|
attachable_type = attachment['attachable_type']
|
|
5
7
|
attachable_id = attachment['attachable_id'].to_s
|
|
6
|
-
filename
|
|
8
|
+
filename ||= attachment['filename']
|
|
7
9
|
url = attachment['url']
|
|
8
|
-
|
|
9
|
-
file_path = path
|
|
10
|
-
unless File.directory?(file_path)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
downloaded_attachment = open(exact_path, "wb+") do |file|
|
|
16
|
-
file << open(url).read
|
|
10
|
+
|
|
11
|
+
file_path = path || File.join(Dir.pwd, attachable_type, attachable_id)
|
|
12
|
+
FileUtils.mkpath(file_path) unless File.directory?(file_path)
|
|
13
|
+
|
|
14
|
+
exact_path = File.join(file_path, filename)
|
|
15
|
+
downloaded_attachment = File.open(exact_path, 'wb+') do |file|
|
|
16
|
+
file << URI.parse(url).read
|
|
17
17
|
end
|
|
18
18
|
downloaded_attachment
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def create_attachment(filepath
|
|
22
|
-
|
|
21
|
+
def create_attachment(filepath:, attachable_type:, attachable_id:)
|
|
22
|
+
unless File.exist?(filepath)
|
|
23
23
|
puts "Cannot find filepath: '#{filepath.inspect}'"
|
|
24
24
|
return
|
|
25
25
|
end
|
|
26
|
-
req =
|
|
26
|
+
req = execute(
|
|
27
27
|
path: 'attachments.json',
|
|
28
28
|
http_method: 'post',
|
|
29
29
|
multipart: true,
|
|
30
30
|
payload: {
|
|
31
|
-
'file[attachable_type]' =>
|
|
32
|
-
'file[attachable_id]' =>
|
|
33
|
-
'file[attachment]' =>
|
|
31
|
+
'file[attachable_type]' => attachable_type,
|
|
32
|
+
'file[attachable_id]' => attachable_id,
|
|
33
|
+
'file[attachment]' => File.open(filepath, 'rb')
|
|
34
34
|
},
|
|
35
35
|
headers: {
|
|
36
36
|
'Content-Type' => 'multipart/form-data',
|
|
37
|
-
'X-Samanage-Authorization' => 'Bearer ' +
|
|
37
|
+
'X-Samanage-Authorization' => 'Bearer ' + token
|
|
38
38
|
}
|
|
39
39
|
)
|
|
40
40
|
req
|
|
41
41
|
end
|
|
42
|
-
|
|
43
|
-
|
|
44
42
|
end
|
|
45
|
-
end
|
|
43
|
+
end
|
|
@@ -1,46 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Samanage
|
|
2
4
|
class Api
|
|
3
|
-
|
|
4
5
|
# Default get incident path
|
|
5
6
|
def get_incidents(path: PATHS[:incident], options: {})
|
|
6
|
-
|
|
7
|
-
path = 'incidents.json?'
|
|
8
|
-
self.execute(path: path,options: options)
|
|
7
|
+
execute(path: path, options: options)
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
#
|
|
13
|
-
# Options:
|
|
10
|
+
# Returns all incidents.
|
|
11
|
+
# Options:
|
|
14
12
|
# - audit_archives: true
|
|
15
13
|
# - layout: 'long'
|
|
16
14
|
def collect_incidents(options: {})
|
|
17
|
-
incidents =
|
|
18
|
-
total_pages =
|
|
19
|
-
puts
|
|
15
|
+
incidents = []
|
|
16
|
+
total_pages = get_incidents(options: options.except(:audit_archives, :audit_archive, :layout))[:total_pages]
|
|
17
|
+
puts 'Requesting Incidents with Audit Archives (this may take a while)' if options[:audit_archives] && options[:verbose]
|
|
20
18
|
1.upto(total_pages) do |page|
|
|
21
19
|
puts "Collecting Incidents page: #{page}/#{total_pages}" if options[:verbose]
|
|
20
|
+
options[:page] = page
|
|
22
21
|
if options[:audit_archives]
|
|
23
|
-
options
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
paginated_incidents = self.execute(path: paginated_path, options: options)[:data]
|
|
22
|
+
params = URI.encode_www_form(options.except(:audit_archives, :audit_archive, :layout)) # layout not needed as audit only on individual record
|
|
23
|
+
paginated_path = 'incidents.json?'
|
|
24
|
+
paginated_incidents = execute(path: paginated_path, options: options)[:data]
|
|
27
25
|
paginated_incidents.map do |incident|
|
|
28
|
-
params =
|
|
26
|
+
params = set_params(options: options.except(:audit_archives, :audit_archive, :layout))
|
|
29
27
|
archive_uri = "incidents/#{incident['id']}.json?layout=long&audit_archive=true"
|
|
30
|
-
incident_with_archive =
|
|
31
|
-
if block_given?
|
|
32
|
-
yield incident_with_archive
|
|
33
|
-
end
|
|
28
|
+
incident_with_archive = execute(path: archive_uri)[:data]
|
|
29
|
+
yield incident_with_archive if block_given?
|
|
34
30
|
incidents.push(incident_with_archive)
|
|
35
31
|
end
|
|
36
32
|
else
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
self.execute(path: path, options: options)[:data].each do |incident|
|
|
41
|
-
if block_given?
|
|
42
|
-
yield incident
|
|
43
|
-
end
|
|
33
|
+
path = 'incidents.json?'
|
|
34
|
+
execute(path: path, options: options)[:data].each do |incident|
|
|
35
|
+
yield incident if block_given?
|
|
44
36
|
incidents.push(incident)
|
|
45
37
|
end
|
|
46
38
|
end
|
|
@@ -48,32 +40,27 @@ module Samanage
|
|
|
48
40
|
incidents
|
|
49
41
|
end
|
|
50
42
|
|
|
51
|
-
|
|
52
43
|
# Create an incident given json
|
|
53
44
|
def create_incident(payload: nil, options: {})
|
|
54
|
-
|
|
45
|
+
execute(path: PATHS[:incident], http_method: 'post', payload: payload, options: options)
|
|
55
46
|
end
|
|
56
47
|
|
|
57
48
|
# Find incident by ID
|
|
58
|
-
def find_incident(id
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
def find_incident(id:, options: {})
|
|
61
50
|
path = "incidents/#{id}.json?"
|
|
62
|
-
|
|
51
|
+
execute(path: path, options: options)
|
|
63
52
|
end
|
|
64
53
|
|
|
65
54
|
# Update an incident given id and json
|
|
66
|
-
def update_incident(payload
|
|
67
|
-
|
|
55
|
+
def update_incident(payload:, id:, options: {})
|
|
68
56
|
path = "incidents/#{id}.json?"
|
|
69
|
-
|
|
57
|
+
execute(path: path, http_method: 'put', payload: payload, options: options)
|
|
70
58
|
end
|
|
71
59
|
|
|
72
|
-
def delete_incident(id
|
|
73
|
-
|
|
60
|
+
def delete_incident(id:, options: {})
|
|
61
|
+
execute(path: "incidents/#{id}.json", http_method: 'delete', options: options)
|
|
74
62
|
end
|
|
75
63
|
|
|
76
|
-
|
|
77
|
-
alias_method :incidents, :collect_incidents
|
|
64
|
+
alias incidents collect_incidents
|
|
78
65
|
end
|
|
79
66
|
end
|
data/lib/samanage/error.rb
CHANGED
data/lib/samanage/version.rb
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'samanage'
|
|
2
4
|
require 'faker'
|
|
3
5
|
describe Samanage::Api do
|
|
4
6
|
context 'Incidents' do
|
|
5
7
|
describe 'API Functions' do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
before(:all) do
|
|
9
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
|
10
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
|
11
|
+
@incidents = @samanage.incidents
|
|
12
|
+
@users = @samanage.users
|
|
13
|
+
@incidents_with_archives = @samanage.incidents(options: { audit_archives: true, layout: 'long', verbose: true })
|
|
14
|
+
end
|
|
13
15
|
it 'get_incidents: it returns API call of incidents' do
|
|
14
16
|
api_call = @samanage.get_incidents
|
|
15
17
|
expect(api_call).to be_a(Hash)
|
|
@@ -25,12 +27,12 @@ describe Samanage::Api do
|
|
|
25
27
|
end
|
|
26
28
|
it 'create_incident(payload: json): creates a incident' do
|
|
27
29
|
users_email = @samanage.collect_users.sample['email']
|
|
28
|
-
incident_name = [Faker::StarWars.specie,Faker::StarWars.planet,Faker::StarWars.droid].shuffle.join(' ')
|
|
30
|
+
incident_name = [Faker::StarWars.specie, Faker::StarWars.planet, Faker::StarWars.droid].shuffle.join(' ')
|
|
29
31
|
json = {
|
|
30
|
-
:
|
|
31
|
-
:
|
|
32
|
-
:
|
|
33
|
-
:
|
|
32
|
+
incident: {
|
|
33
|
+
requester: { email: users_email },
|
|
34
|
+
name: incident_name,
|
|
35
|
+
description: Faker::StarWars.quote
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
incident_create = @samanage.create_incident(payload: json)
|
|
@@ -42,18 +44,18 @@ describe Samanage::Api do
|
|
|
42
44
|
it 'create_incident: fails if no name/title' do
|
|
43
45
|
users_email = @users.sample['email']
|
|
44
46
|
json = {
|
|
45
|
-
:
|
|
46
|
-
:
|
|
47
|
-
:
|
|
47
|
+
incident: {
|
|
48
|
+
requester: { email: users_email },
|
|
49
|
+
description: Faker::StarWars.quote
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
expect{@samanage.create_incident(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
|
52
|
+
expect { @samanage.create_incident(payload: json) }.to raise_error(Samanage::InvalidRequest)
|
|
51
53
|
end
|
|
52
54
|
it 'find_incident: returns a incident card by known id' do
|
|
53
55
|
sample_id = @incidents.sample['id']
|
|
54
56
|
incident = @samanage.find_incident(id: sample_id)
|
|
55
57
|
|
|
56
|
-
expect(incident[:data]['id']).to eq(sample_id)
|
|
58
|
+
expect(incident[:data]['id']).to eq(sample_id) # id should match found incident
|
|
57
59
|
expect(incident[:data]).to have_key('name')
|
|
58
60
|
expect(incident[:data]).to have_key('requester')
|
|
59
61
|
expect(incident[:data]).to have_key('id')
|
|
@@ -61,23 +63,23 @@ describe Samanage::Api do
|
|
|
61
63
|
it 'find_incident: returns more keys with layout=long' do
|
|
62
64
|
sample_id = @incidents.sample['id']
|
|
63
65
|
layout_regular_incident = @samanage.find_incident(id: sample_id)
|
|
64
|
-
layout_long_incident = @samanage.find_incident(id: sample_id, options: {layout: 'long'})
|
|
66
|
+
layout_long_incident = @samanage.find_incident(id: sample_id, options: { layout: 'long' })
|
|
65
67
|
|
|
66
|
-
expect(layout_long_incident[:data]['id']).to eq(sample_id)
|
|
67
|
-
expect(layout_long_incident[:data].keys.size).to be >
|
|
68
|
+
expect(layout_long_incident[:data]['id']).to eq(sample_id) # id should match found incident
|
|
69
|
+
expect(layout_long_incident[:data].keys.size).to be > layout_regular_incident.keys.size
|
|
68
70
|
expect(layout_long_incident[:data].keys - layout_regular_incident[:data].keys).to_not be([])
|
|
69
71
|
end
|
|
70
72
|
it 'find_incident: returns nothing for an invalid id' do
|
|
71
73
|
sample_id = (0..10).entries.sample
|
|
72
|
-
expect{@samanage.find_incident(id: sample_id)}.to raise_error(Samanage::NotFound)
|
|
74
|
+
expect { @samanage.find_incident(id: sample_id) }.to raise_error(Samanage::NotFound) # id should match found incident
|
|
73
75
|
end
|
|
74
76
|
it 'update_incident: update_incident by id' do
|
|
75
|
-
sample_incident = @incidents.reject{|i| [
|
|
77
|
+
sample_incident = @incidents.reject { |i| %w[Closed Resolved].include? i['state'] }.sample
|
|
76
78
|
sample_id = sample_incident['id']
|
|
77
|
-
description = [Faker::String.random,Faker::Seinfeld.quote,Faker::Lorem.paragraph].sample
|
|
79
|
+
description = [Faker::String.random, Faker::Seinfeld.quote, Faker::Lorem.paragraph].sample
|
|
78
80
|
incident_json = {
|
|
79
|
-
:
|
|
80
|
-
:
|
|
81
|
+
incident: {
|
|
82
|
+
description: description
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
incident_update = @samanage.update_incident(payload: incident_json, id: sample_id)
|
|
@@ -85,14 +87,14 @@ describe Samanage::Api do
|
|
|
85
87
|
expect(incident_update[:code]).to eq(200).or(201)
|
|
86
88
|
end
|
|
87
89
|
it 'finds more data for option[:layout] = "long"' do
|
|
88
|
-
full_layout_incident_keys = @samanage.incidents(options: {layout: 'long'}).first.keys
|
|
90
|
+
full_layout_incident_keys = @samanage.incidents(options: { layout: 'long' }).first.keys
|
|
89
91
|
basic_incident_keys = @samanage.incidents.sample.keys
|
|
90
92
|
expect(basic_incident_keys.size).to be < full_layout_incident_keys.size
|
|
91
93
|
end
|
|
92
94
|
it 'finds more audit archives for option[:audit_archives] = true' do
|
|
93
95
|
incident_keys = @incidents_with_archives.sample.keys
|
|
94
96
|
expect(incident_keys).to include
|
|
95
|
-
|
|
97
|
+
'audits'
|
|
96
98
|
end
|
|
97
99
|
it 'finds audit archives for options: {audit_archives: true, layout: "long"}' do
|
|
98
100
|
full_incident_keys = @incidents_with_archives.first.keys
|
|
@@ -107,26 +109,26 @@ describe Samanage::Api do
|
|
|
107
109
|
end
|
|
108
110
|
it 'Sends an email if add_callbacks=true in params' do
|
|
109
111
|
sample_id = @samanage.get_incidents[:data].sample['id']
|
|
110
|
-
audits_req = @samanage.find_incident(id: sample_id, options: {layout: 'long'})
|
|
111
|
-
|
|
112
|
-
initial_email_audits = audits_req.dig(:data,'audits').select{|audit| audit['message'].match(/was sent./) }.count
|
|
112
|
+
audits_req = @samanage.find_incident(id: sample_id, options: { layout: 'long' })
|
|
113
|
+
|
|
114
|
+
initial_email_audits = audits_req.dig(:data, 'audits').select { |audit| audit['message'].match(/was sent./) }.count
|
|
113
115
|
incident_json = {
|
|
114
|
-
:
|
|
116
|
+
incident: {
|
|
115
117
|
state: 'New',
|
|
116
|
-
due_at: Date.new(2019,rand(11)
|
|
117
|
-
assignee: {email: @users.find{|u| u.dig('role','name') == 'Administrator'}.dig('email')}
|
|
118
|
+
due_at: Date.new(2019, rand(1..11), rand(1..27)), # need to configure email notifications for due date change
|
|
119
|
+
assignee: { email: @users.find { |u| u.dig('role', 'name') == 'Administrator' }.dig('email') }
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
|
-
|
|
121
|
-
@samanage.update_incident(payload: incident_json, id: sample_id, options: {add_callbacks: true})
|
|
122
|
+
|
|
123
|
+
@samanage.update_incident(payload: incident_json, id: sample_id, options: { add_callbacks: true })
|
|
122
124
|
sleep 5 # Wait for email to send
|
|
123
|
-
final_audits_req = @samanage.find_incident(id: sample_id, options: {layout: 'long'})
|
|
124
|
-
final_email_audits = final_audits_req.dig(:data,'audits').select{|audit| audit['message'].match(/was sent./) }.count
|
|
125
|
+
final_audits_req = @samanage.find_incident(id: sample_id, options: { layout: 'long' })
|
|
126
|
+
final_email_audits = final_audits_req.dig(:data, 'audits').select { |audit| audit['message'].match(/was sent./) }.count
|
|
125
127
|
expect(initial_email_audits).to be < final_email_audits
|
|
126
128
|
end
|
|
127
129
|
it 'Finds incident origin in v2.0 layout=long header' do
|
|
128
130
|
sample_id = @samanage.get_incidents[:data].sample['id']
|
|
129
|
-
origin_req = @samanage.execute(path: "incidents/#{sample_id}.json", verbose: true, headers: {'Accept' =>
|
|
131
|
+
origin_req = @samanage.execute(path: "incidents/#{sample_id}.json", verbose: true, headers: { 'Accept' => 'application/vnd.samanage.v2.0+json?layout=long' })
|
|
130
132
|
expect(origin_req[:data]).to have_key('origin')
|
|
131
133
|
end
|
|
132
134
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'samanage'
|
|
2
4
|
require 'faker'
|
|
3
5
|
|
|
@@ -12,20 +14,20 @@ describe Samanage::Api do
|
|
|
12
14
|
it 'ensures custom field is updated' do
|
|
13
15
|
val = Faker::Seinfeld.quote
|
|
14
16
|
field_name = @samanage.custom_forms['user'][0]['custom_form_fields']
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
.select { |f| f.dig('custom_field', 'field_type') == 1 } # field_type == 1 is text
|
|
18
|
+
.sample.dig('custom_field', 'name')
|
|
17
19
|
payload = {
|
|
18
20
|
user: {
|
|
19
|
-
custom_fields_values:{
|
|
20
|
-
custom_fields_value:[
|
|
21
|
-
{ name: field_name, value: val}
|
|
21
|
+
custom_fields_values: {
|
|
22
|
+
custom_fields_value: [
|
|
23
|
+
{ name: field_name, value: val }
|
|
22
24
|
]
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
user_id = @users.sample.dig('id')
|
|
27
29
|
api_call = @samanage.update_user(id: user_id, payload: payload)
|
|
28
|
-
return_val = api_call.dig(:data,'custom_fields_values').select{|i| i['name'] == field_name}.first.to_h.dig('value')
|
|
30
|
+
return_val = api_call.dig(:data, 'custom_fields_values').select { |i| i['name'] == field_name }.first.to_h.dig('value')
|
|
29
31
|
expect(val).to eq(return_val)
|
|
30
32
|
end
|
|
31
33
|
it 'get_users: it returns API call of users' do
|
|
@@ -41,12 +43,12 @@ describe Samanage::Api do
|
|
|
41
43
|
expect(@users.size).to eq(user_count)
|
|
42
44
|
end
|
|
43
45
|
it 'create_user(payload: json): creates a user' do
|
|
44
|
-
user_name = [Faker::Simpsons.character,Faker::StarWars.character,Faker::Name.name].sample
|
|
46
|
+
user_name = [Faker::Simpsons.character, Faker::StarWars.character, Faker::Name.name].sample
|
|
45
47
|
email = Faker::Internet.safe_email(user_name)
|
|
46
48
|
json = {
|
|
47
|
-
:
|
|
48
|
-
:
|
|
49
|
-
:
|
|
49
|
+
user: {
|
|
50
|
+
name: user_name,
|
|
51
|
+
email: email
|
|
50
52
|
}
|
|
51
53
|
}
|
|
52
54
|
user_create = @samanage.create_user(payload: json)
|
|
@@ -58,24 +60,23 @@ describe Samanage::Api do
|
|
|
58
60
|
it 'create_user: fails if no email' do
|
|
59
61
|
user_name = Faker::Superhero.name
|
|
60
62
|
json = {
|
|
61
|
-
:
|
|
62
|
-
:
|
|
63
|
+
user: {
|
|
64
|
+
name: user_name
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
expect{@samanage.create_user(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
|
67
|
+
expect { @samanage.create_user(payload: json) }.to raise_error(Samanage::InvalidRequest)
|
|
66
68
|
end
|
|
67
69
|
it 'find_user: returns a user card by known id' do
|
|
68
70
|
sample_id = @users.sample['id']
|
|
69
71
|
user = @samanage.find_user(id: sample_id)
|
|
70
|
-
expect(user[:data]['id']).to eq(sample_id)
|
|
72
|
+
expect(user[:data]['id']).to eq(sample_id) # id should match found user
|
|
71
73
|
expect(user[:data]).to have_key('email')
|
|
72
74
|
expect(user[:data]).to have_key('name')
|
|
73
75
|
end
|
|
74
76
|
|
|
75
|
-
|
|
76
77
|
it 'find_user: returns nothing for an invalid id' do
|
|
77
78
|
sample_id = (0..10).entries.sample
|
|
78
|
-
expect{@samanage.find_user(id: sample_id)}.to raise_error(Samanage::NotFound)
|
|
79
|
+
expect { @samanage.find_user(id: sample_id) }.to raise_error(Samanage::NotFound) # id should match found user
|
|
79
80
|
end
|
|
80
81
|
|
|
81
82
|
it 'finds_user_id_by_email' do
|
|
@@ -88,7 +89,7 @@ describe Samanage::Api do
|
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
it 'finds group_id for user' do
|
|
91
|
-
sample_user = @users.select{|u| u['role']['name'] == 'Administrator'}.sample
|
|
92
|
+
sample_user = @users.select { |u| u['role']['name'] == 'Administrator' }.sample
|
|
92
93
|
sample_user_email = sample_user['email']
|
|
93
94
|
group_ids = sample_user['group_ids']
|
|
94
95
|
found_id = nil
|
|
@@ -104,7 +105,6 @@ describe Samanage::Api do
|
|
|
104
105
|
expect(function_id).to eq(found_id)
|
|
105
106
|
end
|
|
106
107
|
|
|
107
|
-
|
|
108
108
|
it 'returns nil for invalid find_user_group_id_by_email' do
|
|
109
109
|
invalid_user_email = 'abc@123.gov'
|
|
110
110
|
function_id = @samanage.find_user_group_id_by_email(email: invalid_user_email)
|
|
@@ -119,30 +119,28 @@ describe Samanage::Api do
|
|
|
119
119
|
expect(function_id).to be(nil)
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
122
|
it 'update_user: update_user by id' do
|
|
125
123
|
sample_id = @users.sample['id']
|
|
126
|
-
new_name = [Faker::Simpsons.character,Faker::StarWars.character,Faker::Name.name].sample
|
|
124
|
+
new_name = [Faker::Simpsons.character, Faker::StarWars.character, Faker::Name.name].sample
|
|
127
125
|
json = {
|
|
128
|
-
:
|
|
126
|
+
user: {
|
|
129
127
|
name: new_name,
|
|
130
128
|
title: Faker::Job.title
|
|
131
129
|
}
|
|
132
130
|
}
|
|
133
131
|
user_update = @samanage.update_user(payload: json, id: sample_id)
|
|
134
|
-
expect(user_update[:data][
|
|
132
|
+
expect(user_update[:data]['name']).to eq(new_name)
|
|
135
133
|
expect(user_update[:code]).to eq(200).or(201)
|
|
136
134
|
end
|
|
137
135
|
it 'deletes a valid user' do
|
|
138
|
-
sample_user_id = @users.
|
|
136
|
+
sample_user_id = @users.reject { |u| u['last_login'] }.sample['id']
|
|
139
137
|
user_delete = @samanage.delete_user(id: sample_user_id)
|
|
140
138
|
expect(user_delete[:code]).to eq(200).or(201)
|
|
141
139
|
end
|
|
142
|
-
it 'fails to delete invalid user' do
|
|
140
|
+
it 'fails to delete invalid user' do
|
|
143
141
|
invalid_user_id = 0
|
|
144
|
-
expect{@samanage.delete_user(id: invalid_user_id)}.to raise_error(Samanage::InvalidRequest)
|
|
142
|
+
expect { @samanage.delete_user(id: invalid_user_id) }.to raise_error(Samanage::InvalidRequest)
|
|
145
143
|
end
|
|
146
144
|
end
|
|
147
145
|
end
|
|
148
|
-
end
|
|
146
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: samanage
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.19
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Walls
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
130
130
|
version: '0'
|
|
131
131
|
requirements: []
|
|
132
132
|
rubyforge_project:
|
|
133
|
-
rubygems_version: 2.
|
|
133
|
+
rubygems_version: 2.7.7
|
|
134
134
|
signing_key:
|
|
135
135
|
specification_version: 4
|
|
136
136
|
summary: Samanage Ruby Gem
|