samanage 2.1.19 → 2.1.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +224 -0
  3. data/Gemfile +12 -7
  4. data/Gemfile.lock +43 -24
  5. data/Guardfile +5 -3
  6. data/changelog.md +92 -19
  7. data/lib/samanage.rb +33 -30
  8. data/lib/samanage/api.rb +67 -74
  9. data/lib/samanage/api/attachments.rb +12 -12
  10. data/lib/samanage/api/category.rb +9 -7
  11. data/lib/samanage/api/changes.rb +17 -16
  12. data/lib/samanage/api/comments.rb +6 -7
  13. data/lib/samanage/api/contracts.rb +17 -17
  14. data/lib/samanage/api/custom_fields.rb +6 -6
  15. data/lib/samanage/api/custom_forms.rb +13 -10
  16. data/lib/samanage/api/departments.rb +9 -9
  17. data/lib/samanage/api/groups.rb +21 -20
  18. data/lib/samanage/api/hardwares.rb +14 -14
  19. data/lib/samanage/api/incidents.rb +7 -8
  20. data/lib/samanage/api/mobiles.rb +14 -15
  21. data/lib/samanage/api/other_assets.rb +14 -14
  22. data/lib/samanage/api/problems.rb +17 -17
  23. data/lib/samanage/api/purchase_orders.rb +17 -17
  24. data/lib/samanage/api/releases.rb +14 -14
  25. data/lib/samanage/api/requester.rb +4 -2
  26. data/lib/samanage/api/sites.rb +10 -9
  27. data/lib/samanage/api/solutions.rb +15 -14
  28. data/lib/samanage/api/tasks.rb +39 -0
  29. data/lib/samanage/api/time_tracks.rb +8 -6
  30. data/lib/samanage/api/users.rb +32 -30
  31. data/lib/samanage/api/utils.rb +11 -9
  32. data/lib/samanage/api/vendors.rb +14 -13
  33. data/lib/samanage/error.rb +5 -4
  34. data/lib/samanage/language.rb +48 -46
  35. data/lib/samanage/url_builder.rb +27 -25
  36. data/lib/samanage/utils.rb +10 -8
  37. data/lib/samanage/version.rb +1 -1
  38. data/samanage.gemspec +11 -9
  39. data/spec/api/samanage_attachment_spec.rb +20 -19
  40. data/spec/api/samanage_category_spec.rb +12 -10
  41. data/spec/api/samanage_change_spec.rb +47 -44
  42. data/spec/api/samanage_comments_spec.rb +12 -10
  43. data/spec/api/samanage_contract_spec.rb +41 -35
  44. data/spec/api/samanage_custom_field_spec.rb +7 -5
  45. data/spec/api/samanage_custom_form_spec.rb +11 -9
  46. data/spec/api/samanage_department_spec.rb +20 -15
  47. data/spec/api/samanage_group_spec.rb +30 -28
  48. data/spec/api/samanage_hardware_spec.rb +44 -38
  49. data/spec/api/samanage_incident_spec.rb +79 -61
  50. data/spec/api/samanage_mobile_spec.rb +39 -34
  51. data/spec/api/samanage_other_asset_spec.rb +50 -44
  52. data/spec/api/samanage_problem_spec.rb +53 -46
  53. data/spec/api/samanage_purchase_order_spec.rb +43 -40
  54. data/spec/api/samanage_release_spec.rb +44 -40
  55. data/spec/api/samanage_site_spec.rb +18 -16
  56. data/spec/api/samanage_solution_spec.rb +16 -14
  57. data/spec/api/samanage_task_spec.rb +68 -0
  58. data/spec/api/samanage_time_tracks_spec.rb +41 -27
  59. data/spec/api/samanage_user_spec.rb +51 -46
  60. data/spec/api/samanage_util_spec.rb +13 -11
  61. data/spec/api/samanage_vendors_spec.rb +18 -16
  62. data/spec/samanage_api_spec.rb +27 -23
  63. data/spec/samanage_category_spec.rb +10 -8
  64. data/spec/samanage_language_spec.rb +12 -10
  65. data/spec/samanage_url_builder_spec.rb +11 -9
  66. data/spec/spec_helper.rb +6 -4
  67. metadata +5 -2
@@ -1,14 +1,16 @@
1
- require 'samanage'
1
+ # frozen_string_literal: true
2
+
3
+ require "samanage"
2
4
 
3
5
  describe Samanage::Api do
4
- context 'Custom Field' do
5
- describe 'API Functions' do
6
+ context "Custom Field" do
7
+ describe "API Functions" do
6
8
  before(:all) do
7
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
9
+ TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
8
10
  @samanage = Samanage::Api.new(token: TOKEN)
9
11
  @custom_fields = @samanage.custom_fields
10
12
  end
11
- it 'collects all custom fields' do
13
+ it "collects all custom fields" do
12
14
  expect(@custom_fields).to be_a(Array)
13
15
  end
14
16
  end
@@ -1,27 +1,29 @@
1
- require 'samanage'
1
+ # frozen_string_literal: true
2
+
3
+ require "samanage"
2
4
 
3
5
  describe Samanage::Api do
4
- context 'Custom Form' do
5
- describe 'API Functions' do
6
+ context "Custom Form" do
7
+ describe "API Functions" do
6
8
  before(:all) do
7
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
9
+ TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
8
10
  @controller = Samanage::Api.new(token: TOKEN, development_mode: true)
9
11
  @custom_forms = @controller.collect_custom_forms
10
12
  end
11
- it 'collects all custom forms' do
13
+ it "collects all custom forms" do
12
14
  expect(@custom_forms).to be_an(Array)
13
15
  end
14
- it 'Organizes custom forms by module' do
16
+ it "Organizes custom forms by module" do
15
17
  api_call = @controller.organize_forms
16
18
  expect(api_call).to be_a(Hash)
17
19
  expect(api_call.keys).to be_an(Array)
18
20
  # expect(api_call[api_call.keys.sample].sample).to be_a(Hash)
19
21
  end
20
- it 'Finds the forms for an object_type' do
21
- object_types = ['incident', 'user','other_asset','hardware','configuration_item']
22
+ it "Finds the forms for an object_type" do
23
+ object_types = ["incident", "user", "other_asset", "hardware", "configuration_item"]
22
24
  form = @controller.form_for(object_type: object_types.sample)
23
25
  expect(form).to be_an(Array)
24
- expect(form.sample.keys).to include('custom_form_fields')
26
+ expect(form.sample.keys).to include("custom_form_fields")
25
27
  end
26
28
  end
27
29
  end
@@ -1,26 +1,31 @@
1
- require 'samanage'
2
- require 'faker'
1
+ # frozen_string_literal: true
2
+
3
+ require "samanage"
4
+ require "faker"
3
5
  describe Samanage::Api do
4
- context 'department' do
6
+ context "department" do
5
7
  before(:all) do
6
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
7
9
  @samanage = Samanage::Api.new(token: TOKEN)
8
10
  @departments = @samanage.departments
9
11
  end
10
- it 'get_users: it returns API call of departments' do
12
+ it "get_users: it returns API call of departments" do
11
13
  api_call = @samanage.get_departments
12
14
  expect(api_call).to be_a(Hash)
13
15
  expect(api_call[:total_count]).to be_an(Integer)
14
16
  expect(api_call).to have_key(:response)
15
17
  expect(api_call).to have_key(:code)
16
18
  end
17
- it 'collects all departments' do
19
+ it "collects all departments" do
18
20
  department_count = @samanage.get_departments[:total_count]
19
21
  expect(@departments).to be_an(Array)
20
22
  expect(@departments.size).to eq(department_count)
21
23
  end
22
- it 'creates a department' do
23
- department_name = Faker::Book.title
24
+ it "creates a department" do
25
+ department_name = [
26
+ Faker::Internet.username,
27
+ Faker::Internet.domain_word
28
+ ].shuffle.join(' ')
24
29
  department_description = Faker::Book.author
25
30
  payload = {
26
31
  department: {
@@ -30,18 +35,18 @@ describe Samanage::Api do
30
35
  }
31
36
  department_create = @samanage.create_department(payload: payload)
32
37
 
33
- expect(department_create[:data]['id']).to be_an(Integer)
34
- expect(department_create[:data]['name']).to eq(department_name)
38
+ expect(department_create[:data]["id"]).to be_an(Integer)
39
+ expect(department_create[:data]["name"]).to eq(department_name)
35
40
  expect(department_create[:code]).to eq(200).or(201)
36
41
  end
37
- it 'deletes a valid department' do
38
- sample_department_id = @departments.sample.dig('id')
42
+ it "deletes a valid department" do
43
+ sample_department_id = @departments.sample.dig("id")
39
44
  department_delete = @samanage.delete_department(id: sample_department_id)
40
45
  expect(department_delete[:code]).to eq(200).or(201)
41
46
  end
42
- it 'fails to delete invalid department' do
47
+ it "fails to delete invalid department" do
43
48
  invalid_department_id = 0
44
- expect{@samanage.delete_department(id: invalid_department_id)}.to raise_error(Samanage::NotFound)
49
+ expect { @samanage.delete_department(id: invalid_department_id) }.to raise_error(Samanage::NotFound)
45
50
  end
46
51
  end
47
- end
52
+ end
@@ -1,32 +1,34 @@
1
- require 'faker'
2
- require 'samanage'
1
+ # frozen_string_literal: true
2
+
3
+ require "faker"
4
+ require "samanage"
3
5
  describe Samanage::Api do
4
- context 'group' do
6
+ context "group" do
5
7
  before(:all) do
6
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
8
+ TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
7
9
  @samanage = Samanage::Api.new(token: TOKEN)
8
10
  @groups = @samanage.groups
9
11
  @users = @samanage.get_users[:data]
10
12
  end
11
- it 'get_users: it returns API call of users' do
13
+ it "get_users: it returns API call of users" do
12
14
  api_call = @samanage.get_groups
13
15
  expect(api_call).to be_a(Hash)
14
16
  expect(api_call[:total_count]).to be_an(Integer)
15
17
  expect(api_call).to have_key(:response)
16
18
  expect(api_call).to have_key(:code)
17
19
  end
18
- it 'collects all groups' do
20
+ it "collects all groups" do
19
21
  group_count = @samanage.get_groups[:total_count]
20
22
  expect(@groups).to be_an(Array)
21
23
  expect(@groups.size).to eq(group_count)
22
24
  end
23
- it 'find_group: returns a group card by known id' do
24
- sample_id = @groups.sample['id']
25
+ it "find_group: returns a group card by known id" do
26
+ sample_id = @groups.sample["id"]
25
27
  group = @samanage.find_group(id: sample_id)
26
- expect(group[:data]['id']).to eq(sample_id) # id should match found group
27
- expect(group[:data]).to have_key('name')
28
+ expect(group[:data]["id"]).to eq(sample_id) # id should match found group
29
+ expect(group[:data]).to have_key("name")
28
30
  end
29
- it 'creates a group' do
31
+ it "creates a group" do
30
32
  group_name = Faker::BossaNova.artist
31
33
  group_description = Faker::BossaNova.song
32
34
  payload = {
@@ -37,38 +39,38 @@ describe Samanage::Api do
37
39
  }
38
40
  group_create = @samanage.create_group(payload: payload)
39
41
 
40
- expect(group_create[:data]['id']).to be_an(Integer)
41
- expect(group_create[:data]['name']).to eq(group_name)
42
+ expect(group_create[:data]["id"]).to be_an(Integer)
43
+ expect(group_create[:data]["name"]).to eq(group_name)
42
44
  expect(group_create[:code]).to eq(200).or(201)
43
45
  end
44
46
 
45
- it 'finds a group by name' do
47
+ it "finds a group by name" do
46
48
  group = @groups.sample
47
- group_name = group['name']
48
- group_id = group['id']
49
+ group_name = group["name"]
50
+ group_id = group["id"]
49
51
  found_group_id = @samanage.find_group_id_by_name(group: group_name)
50
52
  expect(group_id).to eq(found_group_id)
51
53
  end
52
- it 'returns nil for finding invalid group by name' do
53
- group_name = "Invalid-#{rand(100)*100}"
54
+ it "returns nil for finding invalid group by name" do
55
+ group_name = "Invalid-#{rand(100) * 100}"
54
56
  found_group_id = @samanage.find_group_id_by_name(group: group_name)
55
57
  expect(found_group_id).to be(nil)
56
58
  end
57
- it 'adds member to group' do
58
- random_group_id = @groups.sample['id']
59
- random_user_email = @users.sample['email']
59
+ it "adds member to group" do
60
+ random_group_id = @groups.sample["id"]
61
+ random_user_email = @users.sample["email"]
60
62
 
61
63
  add_user_to_group = @samanage.add_member_to_group(email: random_user_email, group_id: random_group_id)
62
64
  expect(add_user_to_group[:code]).to eq(200).or(201)
63
65
  end
64
- it 'deletes a valid group' do
65
- sample_group_id = @groups.sample['id']
66
+ it "deletes a valid group" do
67
+ sample_group_id = @groups.sample["id"]
66
68
  group_delete = @samanage.delete_group(id: sample_group_id)
67
69
  expect(group_delete[:code]).to eq(200).or(201)
68
70
  end
69
- it 'fails to delete invalid group' do
70
- invalid_group_id = 0
71
- expect{@samanage.delete_group(id: invalid_group_id)}.to raise_error(Samanage::NotFound)
72
- end
71
+ it "fails to delete invalid group" do
72
+ invalid_group_id = 0
73
+ expect { @samanage.delete_group(id: invalid_group_id) }.to raise_error(Samanage::NotFound)
74
+ end
73
75
  end
74
- end
76
+ end
@@ -1,81 +1,87 @@
1
- require 'samanage'
2
- require 'faker'
1
+ # frozen_string_literal: true
2
+
3
+ require "samanage"
4
+ require "faker"
3
5
  describe Samanage::Api do
4
- context 'Hardware' do
5
- describe 'API Functions' do
6
+ context "Hardware" do
7
+ describe "API Functions" do
6
8
  before(:all) do
7
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
9
+ TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
8
10
  @samanage = Samanage::Api.new(token: TOKEN)
9
11
  @hardwares = @samanage.get_hardwares[:data]
10
12
  end
11
- it 'get_hardwares: it returns API call of hardwares' do
13
+ it "get_hardwares: it returns API call of hardwares" do
12
14
  api_call = @samanage.get_hardwares
13
15
  expect(api_call).to be_a(Hash)
14
16
  expect(api_call[:total_count]).to be_an(Integer)
15
17
  expect(api_call).to have_key(:response)
16
18
  expect(api_call).to have_key(:code)
17
19
  end
18
- it 'collect_hardwares: collects array of hardwares' do
20
+ it "collect_hardwares: collects array of hardwares" do
19
21
  hardware_count = @samanage.get_hardwares[:total_count]
20
22
  @hardwares = @samanage.hardwares
21
23
  expect(@hardwares).to be_an(Array)
22
24
  expect(@hardwares.size).to eq(hardware_count)
23
25
  end
24
- it 'create_hardware(payload: payload): creates a hardware' do
26
+ it "create_hardware(payload: payload): creates a hardware" do
25
27
  hardware_name = Faker::Science.scientist
26
28
  serial_number = Faker::Device.serial
27
29
  payload = {
28
- :hardware => {
29
- :name => hardware_name,
30
- :bio => {:ssn => serial_number},
30
+ hardware: {
31
+ name: hardware_name,
32
+ bio: { ssn: serial_number },
31
33
  }
32
34
  }
33
35
  hardware_create = @samanage.create_hardware(payload: payload)
34
36
 
35
- expect(hardware_create[:data]['id']).to be_an(Integer)
36
- expect(hardware_create[:data]['name']).to eq(hardware_name)
37
+ expect(hardware_create[:data]["id"]).to be_an(Integer)
38
+ expect(hardware_create[:data]["name"]).to eq(hardware_name)
37
39
  expect(hardware_create[:code]).to eq(200).or(201)
38
40
  end
39
- it 'create_hardware: fails if no serial' do
40
- hardware_name = "samanage-ruby-#{(rand*10**10).ceil}"
41
+ it "create_hardware: fails if no serial" do
42
+ hardware_name = "samanage-ruby-#{(rand * 10**10).ceil}"
41
43
  payload = {
42
- :hardware => {
43
- :name => hardware_name,
44
+ hardware: {
45
+ name: hardware_name,
44
46
  }
45
47
  }
46
- expect{@samanage.create_hardware(payload: payload)}.to raise_error(Samanage::InvalidRequest)
48
+ expect {
49
+ @samanage.create_hardware(payload: payload)
50
+ }.to raise_error(Samanage::InvalidRequest)
47
51
  end
48
- it 'find_hardware: returns a hardware card by known id' do
49
- sample_id = @hardwares.sample['id']
52
+ it "find_hardware: returns a hardware card by known id" do
53
+ sample_id = @hardwares.sample["id"]
50
54
  hardware = @samanage.find_hardware(id: sample_id)
51
55
 
52
- expect(hardware[:data]['id']).to eq(sample_id) # id should match found hardware
53
- expect(hardware[:data]).to have_key('name')
54
- expect(hardware[:data]).to have_key('serial_number')
55
- expect(hardware[:data]).to have_key('id')
56
+ expect(hardware[:data]["id"]).to eq(sample_id) # id should match found hardware
57
+ expect(hardware[:data]).to have_key("name")
58
+ expect(hardware[:data]).to have_key("serial_number")
59
+ expect(hardware[:data]).to have_key("id")
56
60
  end
57
- it 'find_hardware: returns nothing for an invalid id' do
61
+ it "find_hardware: returns nothing for an invalid id" do
58
62
  sample_id = (0..10).entries.sample
59
- expect{@samanage.find_hardware(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found hardware
63
+ expect {
64
+ @samanage.find_hardware(id: sample_id)
65
+ }.to raise_error(Samanage::NotFound) # id should match found hardware
60
66
  end
61
67
 
62
- it 'finds_hardwares_by_serial' do
68
+ it "finds_hardwares_by_serial" do
63
69
  sample_hardware = @hardwares.sample
64
- sample_serial_number = sample_hardware['serial_number']
70
+ sample_serial_number = sample_hardware["serial_number"]
65
71
  found_assets = @samanage.find_hardwares_by_serial(serial_number: sample_serial_number)
66
72
  found_sample = found_assets[:data].sample
67
73
  expect(sample_serial_number).not_to be(nil)
68
- expect(found_sample['serial_number']).not_to be(nil)
69
- expect(found_sample['serial_number']).to eq(sample_serial_number)
74
+ expect(found_sample["serial_number"]).not_to be(nil)
75
+ expect(found_sample["serial_number"]).to eq(sample_serial_number)
70
76
  # expect(sample_id).to eq(found_assets[:data].first.dig('id'))
71
77
  end
72
- it 'update_hardware: update_hardware by id' do
73
- sample_id = @hardwares.sample['id']
74
- new_name = [Faker::Dune.planet,Faker::ProgrammingLanguage.name].join('-')
78
+ it "update_hardware: update_hardware by id" do
79
+ sample_id = @hardwares.sample["id"]
80
+ new_name = [Faker::Device.manufacturer, Faker::Device.platform].join("-")
75
81
  payload = {
76
- :hardware => {
82
+ hardware: {
77
83
  name: new_name,
78
- tag: Faker::Dune.saying,
84
+ tag: Faker::Books::Dune.saying,
79
85
  asset_id: Faker::Space.moon
80
86
  }
81
87
  }
@@ -83,11 +89,11 @@ describe Samanage::Api do
83
89
  expect(hardware_update[:data]["name"]).to eq(new_name)
84
90
  expect(hardware_update[:code]).to eq(200).or(201)
85
91
  end
86
- it 'deletes a valid hardware' do
87
- sample_hardware_id = @hardwares.sample['id']
92
+ it "deletes a valid hardware" do
93
+ sample_hardware_id = @hardwares.sample["id"]
88
94
  hardware_delete = @samanage.delete_hardware(id: sample_hardware_id)
89
95
  expect(hardware_delete[:code]).to eq(200).or(201)
90
96
  end
91
97
  end
92
98
  end
93
- end
99
+ end
@@ -1,135 +1,153 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'samanage'
4
- require 'faker'
3
+ require "samanage"
4
+ require "faker"
5
5
  describe Samanage::Api do
6
- context 'Incidents' do
7
- describe 'API Functions' do
6
+ context "Incidents" do
7
+ describe "API Functions" do
8
8
  before(:all) do
9
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
9
+ TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
10
10
  @samanage = Samanage::Api.new(token: TOKEN)
11
11
  @incidents = @samanage.incidents
12
12
  @users = @samanage.users
13
- @incidents_with_archives = @samanage.incidents(options: { audit_archives: true, layout: 'long', verbose: true })
13
+ @incidents_with_archives = @samanage.incidents(options: { audit_archives: true, layout: "long", verbose: true })
14
14
  end
15
- it 'get_incidents: it returns API call of incidents' do
15
+ it "get_incidents: it returns API call of incidents" do
16
16
  api_call = @samanage.get_incidents
17
17
  expect(api_call).to be_a(Hash)
18
18
  expect(api_call[:total_count]).to be_an(Integer)
19
19
  expect(api_call).to have_key(:response)
20
20
  expect(api_call).to have_key(:code)
21
21
  end
22
- it 'collect_incidents: collects array of incidents' do
22
+ it "collect_incidents: collects array of incidents" do
23
23
  incident_count = @samanage.get_incidents[:total_count]
24
24
  @incidents = @samanage.incidents
25
25
  expect(@incidents).to be_an(Array)
26
26
  expect(@incidents.size).to eq(incident_count)
27
27
  end
28
- it 'create_incident(payload: json): creates a incident' do
29
- users_email = @samanage.collect_users.sample['email']
30
- incident_name = [Faker::StarWars.specie, Faker::StarWars.planet, Faker::StarWars.droid].shuffle.join(' ')
31
- json = {
32
- incident: {
33
- requester: { email: users_email },
34
- name: incident_name,
35
- description: Faker::StarWars.quote
28
+ it "create_incident(payload: json): creates a incident" do
29
+ 3.times {
30
+ users_email = @samanage.collect_users.sample["email"]
31
+ incident_name = [
32
+ Faker::Movies::StarWars.specie,
33
+ Faker::Movies::StarWars.planet,
34
+ Faker::Movies::StarWars.droid
35
+ ].shuffle.join(" ")
36
+ json = {
37
+ incident: {
38
+ requester: { email: users_email },
39
+ name: incident_name,
40
+ description: Faker::Movies::StarWars.quote
41
+ }
36
42
  }
37
- }
38
- incident_create = @samanage.create_incident(payload: json)
43
+ incident_create = @samanage.create_incident(payload: json)
39
44
 
40
- expect(incident_create[:data]['id']).to be_an(Integer)
41
- expect(incident_create[:data]['name']).to eq(incident_name)
42
- expect(incident_create[:code]).to eq(200).or(201)
45
+ expect(incident_create[:data]["id"]).to be_an(Integer)
46
+ expect(incident_create[:data]["name"]).to eq(incident_name)
47
+ expect(incident_create[:code]).to eq(200).or(201)
48
+ }
43
49
  end
44
- it 'create_incident: fails if no name/title' do
45
- users_email = @users.sample['email']
50
+ it "create_incident: fails if no name/title" do
51
+ users_email = @users.sample["email"]
46
52
  json = {
47
53
  incident: {
48
54
  requester: { email: users_email },
49
- description: Faker::StarWars.quote
55
+ description: Faker::Movies::StarWars.quote
50
56
  }
51
57
  }
52
58
  expect { @samanage.create_incident(payload: json) }.to raise_error(Samanage::InvalidRequest)
53
59
  end
54
- it 'find_incident: returns a incident card by known id' do
55
- sample_id = @incidents.sample['id']
60
+ it "find_incident: returns a incident card by known id" do
61
+ sample_id = @incidents.sample["id"]
56
62
  incident = @samanage.find_incident(id: sample_id)
57
63
 
58
- expect(incident[:data]['id']).to eq(sample_id) # id should match found incident
59
- expect(incident[:data]).to have_key('name')
60
- expect(incident[:data]).to have_key('requester')
61
- expect(incident[:data]).to have_key('id')
64
+ expect(incident[:data]["id"]).to eq(sample_id) # id should match found incident
65
+ expect(incident[:data]).to have_key("name")
66
+ expect(incident[:data]).to have_key("requester")
67
+ expect(incident[:data]).to have_key("id")
62
68
  end
63
- it 'find_incident: returns more keys with layout=long' do
64
- sample_id = @incidents.sample['id']
69
+ it "find_incident: returns more keys with layout=long" do
70
+ sample_id = @incidents.sample["id"]
65
71
  layout_regular_incident = @samanage.find_incident(id: sample_id)
66
- layout_long_incident = @samanage.find_incident(id: sample_id, options: { layout: 'long' })
72
+ layout_long_incident = @samanage.find_incident(id: sample_id, options: { layout: "long" })
67
73
 
68
- expect(layout_long_incident[:data]['id']).to eq(sample_id) # id should match found incident
74
+ expect(layout_long_incident[:data]["id"]).to eq(sample_id) # id should match found incident
69
75
  expect(layout_long_incident[:data].keys.size).to be > layout_regular_incident.keys.size
70
76
  expect(layout_long_incident[:data].keys - layout_regular_incident[:data].keys).to_not be([])
71
77
  end
72
- it 'find_incident: returns nothing for an invalid id' do
78
+ it "find_incident: returns nothing for an invalid id" do
73
79
  sample_id = (0..10).entries.sample
74
- expect { @samanage.find_incident(id: sample_id) }.to raise_error(Samanage::NotFound) # id should match found incident
80
+ # id should match found incident
81
+ expect {
82
+ @samanage.find_incident(id: sample_id)
83
+ }.to raise_error(Samanage::NotFound)
75
84
  end
76
- it 'update_incident: update_incident by id' do
77
- sample_incident = @incidents.reject { |i| %w[Closed Resolved].include? i['state'] }.sample
78
- sample_id = sample_incident['id']
79
- description = [Faker::String.random, Faker::Seinfeld.quote, Faker::Lorem.paragraph].sample
85
+ it "update_incident: update_incident by id" do
86
+ sample_incident = @incidents.reject { |i| %w[Closed Resolved].include? i["state"] }.sample
87
+ sample_id = sample_incident["id"]
88
+ description = [Faker::String.random, Faker::TvShows::Seinfeld.quote, Faker::Lorem.paragraph].sample
80
89
  incident_json = {
81
90
  incident: {
82
91
  description: description
83
92
  }
84
93
  }
85
94
  incident_update = @samanage.update_incident(payload: incident_json, id: sample_id)
86
- expect(incident_update[:data]['description']).to eq(description)
95
+ expect(incident_update[:data]["description"]).to eq(description)
87
96
  expect(incident_update[:code]).to eq(200).or(201)
88
97
  end
89
98
  it 'finds more data for option[:layout] = "long"' do
90
- full_layout_incident_keys = @samanage.incidents(options: { layout: 'long' }).first.keys
99
+ full_layout_incident_keys = @samanage.incidents(options: { layout: "long" }).first.keys
91
100
  basic_incident_keys = @samanage.incidents.sample.keys
92
101
  expect(basic_incident_keys.size).to be < full_layout_incident_keys.size
93
102
  end
94
- it 'finds more audit archives for option[:audit_archives] = true' do
103
+ it "finds more audit archives for option[:audit_archives] = true" do
95
104
  incident_keys = @incidents_with_archives.sample.keys
96
105
  expect(incident_keys).to include
97
- 'audits'
106
+ "audits"
98
107
  end
99
108
  it 'finds audit archives for options: {audit_archives: true, layout: "long"}' do
100
109
  full_incident_keys = @incidents_with_archives.first.keys
101
110
  basic_incident_keys = @incidents.sample.keys
102
111
  expect(basic_incident_keys.size).to be < full_incident_keys.size
103
- expect(full_incident_keys).to include('audits')
112
+ expect(full_incident_keys).to include("audits")
104
113
  end
105
- it 'deletes a valid incident' do
106
- sample_incident_id = @incidents.sample['id']
114
+ it "deletes a valid incident" do
115
+ sample_incident_id = @incidents.sample["id"]
107
116
  incident_delete = @samanage.delete_incident(id: sample_incident_id)
108
117
  expect(incident_delete[:code]).to eq(200).or(201)
109
118
  end
110
- it 'Sends an email if add_callbacks=true in params' do
111
- sample_id = @samanage.get_incidents[:data].sample['id']
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
119
+ it "Sends an email if add_callbacks=true in params" do
120
+ sample_id = @samanage.get_incidents[:data].sample["id"]
121
+ audits_req = @samanage.find_incident(id: sample_id, options: { layout: "long" })
122
+ user_email = @users.find { |u| u.dig("role", "name") == "Administrator" }.dig("email")
123
+ initial_email_audits = audits_req.dig(:data, "audits")
124
+ .select { |audit| audit["message"].match(/was sent./) }
125
+ .count
115
126
  incident_json = {
116
127
  incident: {
117
- state: 'New',
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') }
128
+ state: "New",
129
+ # Must to configure email notifications for due date change
130
+ due_at: Date.new(2019, rand(1..11), rand(1..27)),
131
+ assignee: { email: user_email }
120
132
  }
121
133
  }
122
134
 
123
135
  @samanage.update_incident(payload: incident_json, id: sample_id, options: { add_callbacks: true })
124
136
  sleep 5 # Wait for email to send
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
137
+ final_audits_req = @samanage.find_incident(id: sample_id, options: { layout: "long" })
138
+ final_email_audits = final_audits_req.dig(:data, "audits")
139
+ .select { |audit| audit["message"].match(/was sent./) }
140
+ .count
127
141
  expect(initial_email_audits).to be < final_email_audits
128
142
  end
129
- it 'Finds incident origin in v2.0 layout=long header' do
130
- sample_id = @samanage.get_incidents[:data].sample['id']
131
- origin_req = @samanage.execute(path: "incidents/#{sample_id}.json", verbose: true, headers: { 'Accept' => 'application/vnd.samanage.v2.0+json?layout=long' })
132
- expect(origin_req[:data]).to have_key('origin')
143
+ it "Finds incident origin in v2.0 layout=long header" do
144
+ sample_id = @samanage.get_incidents[:data].sample["id"]
145
+ origin_req = @samanage.execute(
146
+ path: "incidents/#{sample_id}.json",
147
+ verbose: true,
148
+ headers: { "Accept" => "application/vnd.samanage.v2.0+json?layout=long" }
149
+ )
150
+ expect(origin_req[:data]).to have_key("origin")
133
151
  end
134
152
  end
135
153
  end