samanage 1.9.33 → 2.0.03
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +24 -26
- data/changelog.md +13 -0
- data/lib/samanage.rb +2 -1
- data/lib/samanage/api.rb +140 -144
- data/lib/samanage/api/attachments.rb +21 -0
- data/lib/samanage/api/category.rb +24 -19
- data/lib/samanage/api/changes.rb +59 -0
- data/lib/samanage/api/comments.rb +13 -13
- data/lib/samanage/api/contracts.rb +51 -47
- data/lib/samanage/api/custom_fields.rb +23 -19
- data/lib/samanage/api/custom_forms.rb +42 -38
- data/lib/samanage/api/departments.rb +25 -22
- data/lib/samanage/api/groups.rb +43 -39
- data/lib/samanage/api/hardwares.rb +57 -53
- data/lib/samanage/api/incidents.rb +60 -51
- data/lib/samanage/api/mobiles.rb +50 -46
- data/lib/samanage/api/other_assets.rb +47 -43
- data/lib/samanage/api/requester.rb +7 -7
- data/lib/samanage/api/sites.rb +27 -23
- data/lib/samanage/api/users.rb +58 -54
- data/lib/samanage/api/utils.rb +0 -19
- data/lib/samanage/error.rb +20 -20
- data/lib/samanage/url_builder.rb +53 -53
- data/lib/samanage/version.rb +2 -2
- data/samanage.gemspec +2 -2
- data/sample_file.txt +1 -0
- data/spec/api/samanage_attachment_spec.rb +14 -0
- data/spec/api/samanage_category_spec.rb +24 -24
- data/spec/api/samanage_change_spec.rb +98 -0
- data/spec/api/samanage_comments_spec.rb +25 -32
- data/spec/api/samanage_contract_spec.rb +62 -68
- data/spec/api/samanage_custom_field_spec.rb +12 -12
- data/spec/api/samanage_custom_form_spec.rb +24 -24
- data/spec/api/samanage_department_spec.rb +35 -36
- data/spec/api/samanage_group_spec.rb +59 -59
- data/spec/api/samanage_hardware_spec.rb +80 -85
- data/spec/api/samanage_incident_spec.rb +99 -103
- data/spec/api/samanage_mobile_spec.rb +70 -74
- data/spec/api/samanage_other_asset_spec.rb +72 -76
- data/spec/api/samanage_site_spec.rb +45 -45
- data/spec/api/samanage_user_spec.rb +117 -100
- data/spec/api/samanage_util_spec.rb +4 -9
- data/spec/samanage_api_spec.rb +48 -48
- data/spec/samanage_category_spec.rb +21 -28
- data/spec/samanage_url_builder_spec.rb +15 -15
- metadata +15 -11
- data/lib/data/gd-class2-root.crt +0 -24
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'samanage'
|
2
|
+
describe Samanage::Api do
|
3
|
+
context 'changes' do
|
4
|
+
describe 'API Functions' do
|
5
|
+
before(:all) do
|
6
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
7
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
8
|
+
@changes = @samanage.changes
|
9
|
+
@users = @samanage.users
|
10
|
+
end
|
11
|
+
it 'get_changes: it returns API call of changes' do
|
12
|
+
api_call = @samanage.get_changes
|
13
|
+
expect(api_call).to be_a(Hash)
|
14
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
15
|
+
expect(api_call).to have_key(:response)
|
16
|
+
expect(api_call).to have_key(:code)
|
17
|
+
end
|
18
|
+
it 'collect_changes: collects array of changes' do
|
19
|
+
change_count = @samanage.get_changes[:total_count]
|
20
|
+
@changes = @samanage.changes
|
21
|
+
expect(@changes).to be_an(Array)
|
22
|
+
expect(@changes.size).to eq(change_count)
|
23
|
+
end
|
24
|
+
it 'create_change(payload: json): creates a change' do
|
25
|
+
users_email = @samanage.collect_users.sample['email']
|
26
|
+
change_name = "Samanage Ruby change"
|
27
|
+
json = {
|
28
|
+
change: {
|
29
|
+
requester: {email: users_email},
|
30
|
+
name: change_name,
|
31
|
+
priority: 'Low',
|
32
|
+
description: "Description"
|
33
|
+
}
|
34
|
+
}
|
35
|
+
change_create = @samanage.create_change(payload: json)
|
36
|
+
|
37
|
+
expect(change_create[:data]['id']).to be_an(Integer)
|
38
|
+
expect(change_create[:data]['name']).to eq(change_name)
|
39
|
+
expect(change_create[:code]).to eq(200).or(201)
|
40
|
+
end
|
41
|
+
it 'create_change: fails if no name/title' do
|
42
|
+
users_email = @users.sample['email']
|
43
|
+
json = {
|
44
|
+
:change => {
|
45
|
+
:requester => {:email => users_email},
|
46
|
+
:description => "Description"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
expect{@samanage.create_change(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
50
|
+
end
|
51
|
+
it 'find_change: returns a change card by known id' do
|
52
|
+
sample_id = @changes.sample['id']
|
53
|
+
change = @samanage.find_change(id: sample_id)
|
54
|
+
|
55
|
+
expect(change[:data]['id']).to eq(sample_id) # id should match found change
|
56
|
+
expect(change[:data]).to have_key('name')
|
57
|
+
expect(change[:data]).to have_key('requester')
|
58
|
+
expect(change[:data]).to have_key('id')
|
59
|
+
end
|
60
|
+
it 'find_change: returns more keys with layout=long' do
|
61
|
+
sample_id = @changes.sample['id']
|
62
|
+
layout_regular_change = @samanage.find_change(id: sample_id)
|
63
|
+
layout_long_change = @samanage.find_change(id: sample_id, options: {layout: 'long'})
|
64
|
+
|
65
|
+
expect(layout_long_change[:data]['id']).to eq(sample_id) # id should match found change
|
66
|
+
expect(layout_long_change[:data].keys.size).to be > (layout_regular_change.keys.size)
|
67
|
+
expect(layout_long_change[:data].keys - layout_regular_change[:data].keys).to_not be([])
|
68
|
+
end
|
69
|
+
it 'find_change: returns nothing for an invalid id' do
|
70
|
+
sample_id = (0..10).entries.sample
|
71
|
+
expect{@samanage.find_change(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found change
|
72
|
+
end
|
73
|
+
it 'update_change: update_change by id' do
|
74
|
+
sample_change = @changes.reject{|i| ['Closed','Resolved'].include? i['state']}.sample
|
75
|
+
sample_id = sample_change['id']
|
76
|
+
description = (0...500).map { ('a'..'z').to_a[rand(26)] }.join
|
77
|
+
change_json = {
|
78
|
+
:change => {
|
79
|
+
:description => description
|
80
|
+
}
|
81
|
+
}
|
82
|
+
change_update = @samanage.update_change(payload: change_json, id: sample_id)
|
83
|
+
expect(change_update[:data]['description']).to eq(description)
|
84
|
+
expect(change_update[:code]).to eq(200).or(201)
|
85
|
+
end
|
86
|
+
it 'finds more data for option[:layout] = "long"' do
|
87
|
+
full_layout_change_keys = @samanage.changes(options: {layout: 'long'}).first.keys
|
88
|
+
basic_change_keys = @samanage.changes.sample.keys
|
89
|
+
expect(basic_change_keys.size).to be < full_layout_change_keys.size
|
90
|
+
end
|
91
|
+
it 'deletes a valid change' do
|
92
|
+
sample_change_id = @changes.sample['id']
|
93
|
+
change_delete = @samanage.delete_change(id: sample_change_id)
|
94
|
+
expect(change_delete[:code]).to eq(200).or(201)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -1,37 +1,30 @@
|
|
1
1
|
require 'samanage'
|
2
2
|
describe Samanage::Api do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
context 'Comments' do
|
4
|
+
before(:all) do
|
5
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
7
|
+
@incidents = @samanage.get_incidents[:data]
|
8
|
+
end
|
9
|
+
describe 'API Functions' do
|
10
|
+
it 'gets comments' do
|
11
|
+
incident_id = @incidents.sample.dig('id')
|
12
|
+
comments = @samanage.get_comments(incident_id: incident_id)
|
13
|
+
expect(comments).to be_a(Hash)
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
it 'creates a comment' do
|
17
|
+
incident_id = @incidents.sample.dig('id')
|
18
|
+
rand_text = ('a'..'z').to_a.shuffle[0,8].join
|
19
|
+
comment = {
|
20
|
+
comment: {
|
21
|
+
body: rand_text,
|
22
|
+
}
|
23
|
+
}
|
24
|
+
api_call = @samanage.create_comment(incident_id: incident_id, comment: comment)
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
incident_id = @incidents.sample.dig('id')
|
31
|
-
comments = @samanage.comments(incident_id: incident_id)
|
32
|
-
# Total count bug
|
33
|
-
# expect(comments).to be(Array)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
26
|
+
expect(api_call.dig(:data,'body')).to eq(rand_text)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
37
30
|
end
|
@@ -5,71 +5,70 @@ describe Samanage::Api do
|
|
5
5
|
describe 'API Fucntions' do
|
6
6
|
before(:all) do
|
7
7
|
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
8
|
-
|
9
|
-
|
8
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
9
|
+
@contracts = @samanage.contracts
|
10
10
|
end
|
11
11
|
it 'get_contracts: it returns API call of contracts' do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
type: 'SoftwareLicense',
|
12
|
+
api_call = @samanage.get_contracts
|
13
|
+
expect(api_call).to be_a(Hash)
|
14
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
15
|
+
expect(api_call).to have_key(:response)
|
16
|
+
expect(api_call).to have_key(:code)
|
17
|
+
end
|
18
|
+
it 'collect_contracts: collects array of contracts' do
|
19
|
+
contract_count = @samanage.get_contracts[:total_count]
|
20
|
+
expect(@contracts).to be_an(Array)
|
21
|
+
expect(@contracts.size).to eq(contract_count)
|
22
|
+
end
|
23
|
+
it 'create_contract(payload: json): creates a contract' do
|
24
|
+
random_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
|
25
|
+
json = {
|
26
|
+
contract: {
|
27
|
+
type: 'SoftwareLicense',
|
29
28
|
manufacturer_name: 'Adobe',
|
30
29
|
status: 'Active',
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
name: random_name,
|
31
|
+
}
|
32
|
+
}
|
33
|
+
contract_create = @samanage.create_contract(payload: json)
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
35
|
+
expect(contract_create[:data]['id']).to be_an(Integer)
|
36
|
+
expect(contract_create[:data]['name']).to eq(random_name)
|
37
|
+
end
|
38
|
+
it 'create_contract: fails if no status' do
|
39
|
+
contract_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
40
|
+
json = {
|
41
|
+
:contract => {
|
42
|
+
model: 'test',
|
43
|
+
manufacturer_name: contract_name,
|
44
|
+
}
|
45
|
+
}
|
46
|
+
expect{@samanage.create_contract(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
47
|
+
end
|
48
|
+
it 'find_contract: returns a contract card by known id' do
|
49
|
+
sample_id = @contracts.sample['id']
|
50
|
+
contract = @samanage.find_contract(id: sample_id)
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
52
|
+
expect(contract[:data]['id']).to eq(sample_id) # id should match found contract
|
53
|
+
expect(contract[:data]).to have_key('manufacturer_name')
|
54
|
+
expect(contract[:data]).to have_key('name')
|
55
|
+
expect(contract[:data]).to have_key('id')
|
56
|
+
end
|
57
|
+
it 'find_contract: returns nothing for an invalid id' do
|
58
|
+
sample_id = (0..10).entries.sample
|
59
|
+
expect{@samanage.find_contract(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found contract
|
60
|
+
end
|
61
|
+
it 'update_contract: update_contract by id' do
|
62
|
+
sample_id = @contracts.sample['id']
|
63
|
+
new_name = (0...50).map {('a'..'z').to_a[rand(26)] }.join
|
64
|
+
json = {
|
65
|
+
contract: {
|
66
|
+
manufacturer_name: new_name
|
67
|
+
}
|
68
|
+
}
|
69
|
+
contract_update = @samanage.update_contract(payload: json, id: sample_id)
|
70
|
+
expect(contract_update[:data]["manufacturer_name"]).to eq(new_name)
|
71
|
+
expect(contract_update[:code]).to eq(200).or(201)
|
73
72
|
end
|
74
73
|
it 'adds an item to a contract by id' do
|
75
74
|
sample_id = @contracts.sample['id']
|
@@ -83,17 +82,12 @@ describe Samanage::Api do
|
|
83
82
|
}
|
84
83
|
add_item = @samanage.add_item_to_contract(id: sample_id, payload: item)
|
85
84
|
expect(add_item[:code]).to eq(200).or(201)
|
86
|
-
|
87
|
-
|
85
|
+
end
|
86
|
+
it 'deletes a valid contract' do
|
88
87
|
sample_contract_id = @contracts.sample['id']
|
89
88
|
contract_delete = @samanage.delete_contract(id: sample_contract_id)
|
90
89
|
expect(contract_delete[:code]).to eq(200).or(201)
|
91
90
|
end
|
92
|
-
|
93
|
-
|
94
|
-
abc = @samanage.delete_contract(id: invalid_contract_id)
|
95
|
-
# expect{@samanage.delete_contract(id: invalid_contract_id)}.to raise_error(Samanage::NotFound)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
91
|
+
end
|
92
|
+
end
|
99
93
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'samanage'
|
2
2
|
|
3
3
|
describe Samanage::Api do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
context 'Custom Field' do
|
5
|
+
describe 'API Functions' do
|
6
|
+
before(:all) do
|
7
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
8
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
9
|
+
@custom_fields = @samanage.custom_fields
|
10
|
+
end
|
11
|
+
it 'collects all custom fields' do
|
12
|
+
expect(@custom_fields).to be_a(Array)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
16
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'samanage'
|
2
2
|
|
3
3
|
describe Samanage::Api do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
4
|
+
context 'Custom Form' do
|
5
|
+
describe 'API Functions' do
|
6
|
+
before(:all) do
|
7
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
8
|
+
@controller = Samanage::Api.new(token: TOKEN, development_mode: true)
|
9
|
+
@custom_forms = @controller.collect_custom_forms
|
10
|
+
end
|
11
|
+
it 'collects all custom forms' do
|
12
|
+
expect(@custom_forms).to be_a(Array)
|
13
|
+
end
|
14
|
+
it 'Organizes custom forms by module' do
|
15
|
+
api_call = @controller.organize_forms
|
16
|
+
expect(api_call).to be_a(Hash)
|
17
|
+
expect(api_call.keys).to be_an(Array)
|
18
|
+
# expect(api_call[api_call.keys.sample].sample).to be_a(Hash)
|
19
|
+
end
|
20
|
+
it 'Finds the forms for an object_type' do
|
21
|
+
object_types = ['incident', 'user','other_asset','hardware','configuration_item']
|
22
|
+
form = @controller.form_for(object_type: object_types.sample)
|
23
|
+
expect(form).to be_an(Array)
|
24
|
+
expect(form.sample.keys).to include('custom_form_fields')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
28
|
end
|
@@ -1,41 +1,40 @@
|
|
1
1
|
require 'samanage'
|
2
2
|
describe Samanage::Api do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
department_create = @samanage.create_department(payload: payload)
|
3
|
+
context 'department' do
|
4
|
+
before(:all) do
|
5
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
6
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
7
|
+
@departments = @samanage.departments
|
8
|
+
end
|
9
|
+
it 'get_users: it returns API call of departments' do
|
10
|
+
api_call = @samanage.get_departments
|
11
|
+
expect(api_call).to be_a(Hash)
|
12
|
+
expect(api_call[:total_count]).to be_an(Integer)
|
13
|
+
expect(api_call).to have_key(:response)
|
14
|
+
expect(api_call).to have_key(:code)
|
15
|
+
end
|
16
|
+
it 'collects all departments' do
|
17
|
+
department_count = @samanage.get_departments[:total_count]
|
18
|
+
expect(@departments).to be_an(Array)
|
19
|
+
expect(@departments.size).to eq(department_count)
|
20
|
+
end
|
21
|
+
it 'creates a department' do
|
22
|
+
department_name = "department ##{(rand*10**4).ceil}"
|
23
|
+
department_description = "Location #{(rand*10**4).ceil}"
|
24
|
+
payload = {
|
25
|
+
department: {
|
26
|
+
name: department_name,
|
27
|
+
description: department_description
|
28
|
+
}
|
29
|
+
}
|
30
|
+
department_create = @samanage.create_department(payload: payload)
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
sample_department_id = @departments.sample
|
32
|
+
expect(department_create[:data]['id']).to be_an(Integer)
|
33
|
+
expect(department_create[:data]['name']).to eq(department_name)
|
34
|
+
expect(department_create[:code]).to eq(201).or(200)
|
35
|
+
end
|
36
|
+
it 'deletes a valid department' do
|
37
|
+
sample_department_id = @departments.sample.dig('id')
|
39
38
|
department_delete = @samanage.delete_department(id: sample_department_id)
|
40
39
|
expect(department_delete[:code]).to eq(200).or(201)
|
41
40
|
end
|
@@ -43,5 +42,5 @@ describe Samanage::Api do
|
|
43
42
|
invalid_department_id = 0
|
44
43
|
expect{@samanage.delete_department(id: invalid_department_id)}.to raise_error(Samanage::NotFound)
|
45
44
|
end
|
46
|
-
|
45
|
+
end
|
47
46
|
end
|