samanage 1.9.33 → 2.0.03

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +24 -26
  4. data/changelog.md +13 -0
  5. data/lib/samanage.rb +2 -1
  6. data/lib/samanage/api.rb +140 -144
  7. data/lib/samanage/api/attachments.rb +21 -0
  8. data/lib/samanage/api/category.rb +24 -19
  9. data/lib/samanage/api/changes.rb +59 -0
  10. data/lib/samanage/api/comments.rb +13 -13
  11. data/lib/samanage/api/contracts.rb +51 -47
  12. data/lib/samanage/api/custom_fields.rb +23 -19
  13. data/lib/samanage/api/custom_forms.rb +42 -38
  14. data/lib/samanage/api/departments.rb +25 -22
  15. data/lib/samanage/api/groups.rb +43 -39
  16. data/lib/samanage/api/hardwares.rb +57 -53
  17. data/lib/samanage/api/incidents.rb +60 -51
  18. data/lib/samanage/api/mobiles.rb +50 -46
  19. data/lib/samanage/api/other_assets.rb +47 -43
  20. data/lib/samanage/api/requester.rb +7 -7
  21. data/lib/samanage/api/sites.rb +27 -23
  22. data/lib/samanage/api/users.rb +58 -54
  23. data/lib/samanage/api/utils.rb +0 -19
  24. data/lib/samanage/error.rb +20 -20
  25. data/lib/samanage/url_builder.rb +53 -53
  26. data/lib/samanage/version.rb +2 -2
  27. data/samanage.gemspec +2 -2
  28. data/sample_file.txt +1 -0
  29. data/spec/api/samanage_attachment_spec.rb +14 -0
  30. data/spec/api/samanage_category_spec.rb +24 -24
  31. data/spec/api/samanage_change_spec.rb +98 -0
  32. data/spec/api/samanage_comments_spec.rb +25 -32
  33. data/spec/api/samanage_contract_spec.rb +62 -68
  34. data/spec/api/samanage_custom_field_spec.rb +12 -12
  35. data/spec/api/samanage_custom_form_spec.rb +24 -24
  36. data/spec/api/samanage_department_spec.rb +35 -36
  37. data/spec/api/samanage_group_spec.rb +59 -59
  38. data/spec/api/samanage_hardware_spec.rb +80 -85
  39. data/spec/api/samanage_incident_spec.rb +99 -103
  40. data/spec/api/samanage_mobile_spec.rb +70 -74
  41. data/spec/api/samanage_other_asset_spec.rb +72 -76
  42. data/spec/api/samanage_site_spec.rb +45 -45
  43. data/spec/api/samanage_user_spec.rb +117 -100
  44. data/spec/api/samanage_util_spec.rb +4 -9
  45. data/spec/samanage_api_spec.rb +48 -48
  46. data/spec/samanage_category_spec.rb +21 -28
  47. data/spec/samanage_url_builder_spec.rb +15 -15
  48. metadata +15 -11
  49. 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
- 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
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
- 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)
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
- expect(api_call.dig(:data,'body')).to eq(rand_text)
27
- end
28
-
29
- it 'collects all comments' do
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
- @samanage = Samanage::Api.new(token: TOKEN)
9
- @contracts = @samanage.contracts
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
- 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
- manufacturer_name = "samanage-ruby-#{(rand*10**10).ceil}"
25
- random_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
26
- json = {
27
- contract: {
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
- name: random_name,
32
- }
33
- }
34
- contract_create = @samanage.create_contract(payload: json)
30
+ name: random_name,
31
+ }
32
+ }
33
+ contract_create = @samanage.create_contract(payload: json)
35
34
 
36
- expect(contract_create[:data]['id']).to be_an(Integer)
37
- expect(contract_create[:data]['name']).to eq(random_name)
38
- end
39
- it 'create_contract: fails if no status' do
40
- contract_name = "samanage-ruby-#{(rand*10**10).ceil}"
41
- json = {
42
- :contract => {
43
- model: 'test',
44
- manufacturer_name: contract_name,
45
- }
46
- }
47
- expect{@samanage.create_contract(payload: json)}.to raise_error(Samanage::InvalidRequest)
48
- end
49
- it 'find_contract: returns a contract card by known id' do
50
- sample_id = @contracts.sample['id']
51
- contract = @samanage.find_contract(id: sample_id)
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
- expect(contract[:data]['id']).to eq(sample_id) # id should match found contract
54
- expect(contract[:data]).to have_key('manufacturer_name')
55
- expect(contract[:data]).to have_key('name')
56
- expect(contract[:data]).to have_key('id')
57
- end
58
- it 'find_contract: returns nothing for an invalid id' do
59
- sample_id = (0..10).entries.sample
60
- expect{@samanage.find_contract(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found contract
61
- end
62
- it 'update_contract: update_contract by id' do
63
- sample_id = @contracts.sample['id']
64
- new_name = (0...50).map {('a'..'z').to_a[rand(26)] }.join
65
- json = {
66
- contract: {
67
- manufacturer_name: new_name
68
- }
69
- }
70
- contract_update = @samanage.update_contract(payload: json, id: sample_id)
71
- expect(contract_update[:data]["manufacturer_name"]).to eq(new_name)
72
- expect(contract_update[:code]).to eq(200).or(201)
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
- end
87
- it 'deletes a valid contract' do
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
- it 'fails to delete invalid contract' do
93
- invalid_contract_id = 01
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
- 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
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
- 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
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
- 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_location = "Location #{(rand*10**4).ceil}"
24
- department_description = "Location #{(rand*10**4).ceil}"
25
- payload = {
26
- department: {
27
- name: department_name,
28
- description: department_description
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
- expect(department_create[:data]['id']).to be_an(Integer)
34
- expect(department_create[:data]['name']).to eq(department_name)
35
- expect(department_create[:code]).to eq(201).or(200)
36
- end
37
- it 'deletes a valid department' do
38
- sample_department_id = @departments.sample['id']
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
- end
45
+ end
47
46
  end