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
@@ -1,84 +1,80 @@
1
1
  require 'samanage'
2
2
 
3
3
  describe Samanage::Api do
4
- context 'Mobile' 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
- @mobiles = @samanage.mobiles
10
- end
11
- it 'get_mobiles: it returns API call of mobiles' do
12
- api_call = @samanage.get_mobiles
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_mobiles: collects array of mobiles' do
19
- mobile_count = @samanage.get_mobiles[:total_count]
20
- expect(@mobiles).to be_an(Array)
21
- expect(@mobiles.size).to eq(mobile_count)
22
- end
23
- it 'create_mobile(payload: json): creates a mobile' do
24
- mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
25
- serial_number = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
26
- json = {
27
- :mobile => {
28
- model: 'test',
29
- manufacturer: mobile_name,
30
- serial_number: serial_number,
31
- }
32
- }
33
- mobile_create = @samanage.create_mobile(payload: json)
4
+ context 'Mobile' 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
+ @mobiles = @samanage.mobiles
10
+ end
11
+ it 'get_mobiles: it returns API call of mobiles' do
12
+ api_call = @samanage.get_mobiles
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_mobiles: collects array of mobiles' do
19
+ mobile_count = @samanage.get_mobiles[:total_count]
20
+ expect(@mobiles).to be_an(Array)
21
+ expect(@mobiles.size).to eq(mobile_count)
22
+ end
23
+ it 'create_mobile(payload: json): creates a mobile' do
24
+ mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
25
+ serial_number = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
26
+ json = {
27
+ :mobile => {
28
+ model: 'test',
29
+ manufacturer: mobile_name,
30
+ serial_number: serial_number,
31
+ }
32
+ }
33
+ mobile_create = @samanage.create_mobile(payload: json)
34
34
 
35
- expect(mobile_create[:data]['id']).to be_an(Integer)
36
- expect(mobile_create[:data]['manufacturer']).to eq(mobile_name)
37
- end
38
- it 'create_mobile: fails if no serial' do
39
- mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
40
- json = {
41
- :mobile => {
42
- model: 'test',
43
- manufacturer: mobile_name,
44
- }
45
- }
46
- expect{@samanage.create_mobile(payload: json)}.to raise_error(Samanage::InvalidRequest)
47
- end
48
- it 'find_mobile: returns a mobile card by known id' do
49
- sample_id = @mobiles.sample['id']
50
- mobile = @samanage.find_mobile(id: sample_id)
35
+ expect(mobile_create[:data]['id']).to be_an(Integer)
36
+ expect(mobile_create[:data]['manufacturer']).to eq(mobile_name)
37
+ end
38
+ it 'create_mobile: fails if no serial' do
39
+ mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
40
+ json = {
41
+ :mobile => {
42
+ model: 'test',
43
+ manufacturer: mobile_name,
44
+ }
45
+ }
46
+ expect{@samanage.create_mobile(payload: json)}.to raise_error(Samanage::InvalidRequest)
47
+ end
48
+ it 'find_mobile: returns a mobile card by known id' do
49
+ sample_id = @mobiles.sample['id']
50
+ mobile = @samanage.find_mobile(id: sample_id)
51
51
 
52
- expect(mobile[:data]['id']).to eq(sample_id) # id should match found mobile
53
- expect(mobile[:data]).to have_key('manufacturer')
54
- expect(mobile[:data]).to have_key('serial_number')
55
- expect(mobile[:data]).to have_key('id')
56
- end
57
- it 'find_mobile: returns nothing for an invalid id' do
58
- sample_id = (0..10).entries.sample
59
- expect{@samanage.find_mobile(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found mobile
60
- end
61
- it 'update_mobile: update_mobile by id' do
62
- sample_id = @mobiles.sample['id']
63
- new_name = (0...50).map {('a'..'z').to_a[rand(26)] }.join
64
- json = {
65
- :mobile => {
66
- :manufacturer => new_name
67
- }
68
- }
69
- mobile_update = @samanage.update_mobile(payload: json, id: sample_id)
70
- expect(mobile_update[:data]["manufacturer"]).to eq(new_name)
71
- expect(mobile_update[:code]).to eq(200).or(201)
72
- end
73
- it 'deletes a valid mobile' do
52
+ expect(mobile[:data]['id']).to eq(sample_id) # id should match found mobile
53
+ expect(mobile[:data]).to have_key('manufacturer')
54
+ expect(mobile[:data]).to have_key('serial_number')
55
+ expect(mobile[:data]).to have_key('id')
56
+ end
57
+ it 'find_mobile: returns nothing for an invalid id' do
58
+ sample_id = (0..10).entries.sample
59
+ expect{@samanage.find_mobile(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found mobile
60
+ end
61
+ it 'update_mobile: update_mobile by id' do
62
+ sample_id = @mobiles.sample['id']
63
+ new_name = (0...50).map {('a'..'z').to_a[rand(26)] }.join
64
+ json = {
65
+ :mobile => {
66
+ :manufacturer => new_name
67
+ }
68
+ }
69
+ mobile_update = @samanage.update_mobile(payload: json, id: sample_id)
70
+ expect(mobile_update[:data]["manufacturer"]).to eq(new_name)
71
+ expect(mobile_update[:code]).to eq(200).or(201)
72
+ end
73
+ it 'deletes a valid mobile' do
74
74
  sample_mobile_id = @mobiles.sample['id']
75
75
  mobile_delete = @samanage.delete_mobile(id: sample_mobile_id)
76
76
  expect(mobile_delete[:code]).to eq(200).or(201)
77
77
  end
78
- it 'fails to delete invalid mobile' do
79
- invalid_mobile_id = 0
80
- # expect{@samanage.delete_mobile(id: invalid_mobile_id)}.to raise_error(Samanage::NotFound)
81
- end
82
- end
83
- end
78
+ end
79
+ end
84
80
  end
@@ -1,88 +1,84 @@
1
1
  require 'samanage'
2
2
 
3
3
  describe Samanage::Api do
4
- context 'Other Assets' 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
- @other_assets = @samanage.get_other_assets[:data]
10
- end
11
- it 'get_other_assets: it returns API call of other_assets' do
12
- api_call = @samanage.get_other_assets
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_other_assets: collects array of other_assets' do
19
- expect(@other_assets).to be_an(Array)
20
- end
21
- it 'create_other_asset(payload: json): creates a other_asset' do
22
- other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
23
- json = {
24
- :other_asset => {
25
- :name => other_asset_name,
26
- :manufacturer => 'Samanage',
27
- :asset_type => {:name => "Asset"},
28
- :status => {:name => "Operational"}
29
- }
30
- }
4
+ context 'Other Assets' 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
+ @other_assets = @samanage.get_other_assets[:data]
10
+ end
11
+ it 'get_other_assets: it returns API call of other_assets' do
12
+ api_call = @samanage.get_other_assets
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_other_assets: collects array of other_assets' do
19
+ expect(@other_assets).to be_an(Array)
20
+ end
21
+ it 'create_other_asset(payload: json): creates a other_asset' do
22
+ other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
23
+ json = {
24
+ :other_asset => {
25
+ :name => other_asset_name,
26
+ :manufacturer => 'Samanage',
27
+ :asset_type => {:name => "Asset"},
28
+ :status => {:name => "Operational"}
29
+ }
30
+ }
31
31
 
32
- other_asset_create = @samanage.create_other_asset(payload: json)
33
- expect(other_asset_create[:data]['id']).to be_an(Integer)
34
- expect(other_asset_create[:data]['name']).to eq(other_asset_name)
35
- expect(other_asset_create[:code]).to eq(200).or(201)
36
- end
37
- it 'create_other_asset: fails if wrong fields' do
38
- other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
39
- json = {
40
- :other_asset => {
41
- :name => other_asset_name,
42
- :manufacturer => 'Samanage',
43
- :asset_type => {:name => "Asset"},
44
- :status => {:name => "Operational"}
45
- }
46
- }
47
- json[:other_asset].delete(json[:other_asset].keys.sample) # Delete random sample from the examples above
48
- expect{@samanage.create_other_asset(payload: json)}.to raise_error(Samanage::InvalidRequest)
49
- end
32
+ other_asset_create = @samanage.create_other_asset(payload: json)
33
+ expect(other_asset_create[:data]['id']).to be_an(Integer)
34
+ expect(other_asset_create[:data]['name']).to eq(other_asset_name)
35
+ expect(other_asset_create[:code]).to eq(200).or(201)
36
+ end
37
+ it 'create_other_asset: fails if wrong fields' do
38
+ other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
39
+ json = {
40
+ :other_asset => {
41
+ :name => other_asset_name,
42
+ :manufacturer => 'Samanage',
43
+ :asset_type => {:name => "Asset"},
44
+ :status => {:name => "Operational"}
45
+ }
46
+ }
47
+ json[:other_asset].delete(json[:other_asset].keys.sample) # Delete random sample from the examples above
48
+ expect{@samanage.create_other_asset(payload: json)}.to raise_error(Samanage::InvalidRequest)
49
+ end
50
50
 
51
- it 'find_other_asset: returns an other_asset card by known id' do
52
- sample_id = @other_assets.sample['id']
51
+ it 'find_other_asset: returns an other_asset card by known id' do
52
+ sample_id = @other_assets.sample['id']
53
53
 
54
- other_asset = @samanage.find_other_asset(id: sample_id)
54
+ other_asset = @samanage.find_other_asset(id: sample_id)
55
55
 
56
- expect(other_asset[:data]['id']).to eq(sample_id) # id should match found other_asset
57
- expect(other_asset[:data]).to have_key('name')
58
- expect(other_asset[:data]).to have_key('serial_number')
59
- expect(other_asset[:data]).to have_key('id')
60
- end
61
- it 'find_other_asset: returns nothing for an invalid id' do
62
- sample_id = (0..10).entries.sample
63
- expect{@samanage.find_other_asset(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found other_asset
64
- end
65
- it 'update_other_asset: update_other_asset by id' do
66
- sample_id = @other_assets.sample['id']
67
- new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
68
- json = {
69
- :other_asset => {
70
- :name => new_name
71
- }
72
- }
73
- other_asset_update = @samanage.update_other_asset(payload: json, id: sample_id)
74
- expect(other_asset_update[:data]["name"]).to eq(new_name)
75
- expect(other_asset_update[:code]).to eq(200).or(201)
76
- end
56
+ expect(other_asset[:data]['id']).to eq(sample_id) # id should match found other_asset
57
+ expect(other_asset[:data]).to have_key('name')
58
+ expect(other_asset[:data]).to have_key('serial_number')
59
+ expect(other_asset[:data]).to have_key('id')
60
+ end
61
+ it 'find_other_asset: returns nothing for an invalid id' do
62
+ sample_id = (0..10).entries.sample
63
+ expect{@samanage.find_other_asset(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found other_asset
64
+ end
65
+ it 'update_other_asset: update_other_asset by id' do
66
+ sample_id = @other_assets.sample['id']
67
+ new_name = (0...50).map { ('a'..'z').to_a[rand(26)] }.join
68
+ json = {
69
+ :other_asset => {
70
+ :name => new_name
71
+ }
72
+ }
73
+ other_asset_update = @samanage.update_other_asset(payload: json, id: sample_id)
74
+ expect(other_asset_update[:data]["name"]).to eq(new_name)
75
+ expect(other_asset_update[:code]).to eq(200).or(201)
76
+ end
77
77
  it 'deletes a valid other_asset' do
78
78
  sample_other_asset_id = @other_assets.sample['id']
79
79
  other_asset_delete = @samanage.delete_other_asset(id: sample_other_asset_id)
80
80
  expect(other_asset_delete[:code]).to eq(200).or(201)
81
- end
82
- it 'fails to delete invalid other_asset' do
83
- invalid_other_asset_id = 0
84
- # expect{@samanage.delete_other_asset(id: invalid_other_asset_id)}.to raise_error(Samanage::NotFound)
85
- end
86
- end
87
- end
81
+ end
82
+ end
83
+ end
88
84
  end
@@ -1,50 +1,50 @@
1
1
  require 'samanage'
2
2
  describe Samanage::Api do
3
- context 'Site' do
4
- before(:all) do
5
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
6
- @samanage = Samanage::Api.new(token: TOKEN)
7
- @sites = @samanage.sites
8
- end
9
- it 'get_users: it returns API call of users' do
10
- api_call = @samanage.get_sites
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 sites' do
17
- sites = @sites
18
- site_count = @samanage.get_sites[:total_count]
19
- expect(sites).to be_an(Array)
20
- expect(sites.size).to eq(site_count)
21
- end
22
- it 'creates a site' do
23
- site_name = "Site ##{(rand*10**4).ceil}"
24
- site_location = "Location #{(rand*10**4).ceil}"
25
- site_description = "Descrption #{(rand*10**4).ceil}"
26
- payload = {
27
- site: {
28
- name: site_name,
29
- location: site_location,
30
- description: site_description
31
- }
32
- }
33
- site_create = @samanage.create_site(payload: payload)
3
+ context 'Site' do
4
+ before(:all) do
5
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
6
+ @samanage = Samanage::Api.new(token: TOKEN)
7
+ @sites = @samanage.sites
8
+ end
9
+ it 'get_users: it returns API call of users' do
10
+ api_call = @samanage.get_sites
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 sites' do
17
+ sites = @sites
18
+ site_count = @samanage.get_sites[:total_count]
19
+ expect(sites).to be_an(Array)
20
+ expect(sites.size).to eq(site_count)
21
+ end
22
+ it 'creates a site' do
23
+ site_name = "Site ##{(rand*10**4).ceil}"
24
+ site_location = "Location #{(rand*10**4).ceil}"
25
+ site_description = "Descrption #{(rand*10**4).ceil}"
26
+ payload = {
27
+ site: {
28
+ name: site_name,
29
+ location: site_location,
30
+ description: site_description
31
+ }
32
+ }
33
+ site_create = @samanage.create_site(payload: payload)
34
34
 
35
- expect(site_create[:data]['id']).to be_an(Integer)
36
- expect(site_create[:data]['name']).to eq(site_name)
37
- expect(site_create[:code]).to eq(201).or(200)
38
- end
39
- it 'deletes a valid site' do
40
- sample_site_id = @sites.sample['id']
41
- site_delete = @samanage.delete_site(id: sample_site_id)
35
+ expect(site_create[:data]['id']).to be_an(Integer)
36
+ expect(site_create[:data]['name']).to eq(site_name)
37
+ expect(site_create[:code]).to eq(201).or(200)
38
+ end
39
+ it 'deletes a valid site' do
40
+ sample_site_id = @sites.sample['id']
41
+ site_delete = @samanage.delete_site(id: sample_site_id)
42
42
 
43
- expect(site_delete[:code]).to eq(200).or(201)
44
- end
45
- it 'fails to delete invalid site' do
46
- invalid_site_id = 0
47
- expect{@samanage.delete_site(id: invalid_site_id)}.to raise_error(Samanage::NotFound)
48
- end
49
- end
43
+ expect(site_delete[:code]).to eq(200).or(201)
44
+ end
45
+ it 'fails to delete invalid site' do
46
+ invalid_site_id = 0
47
+ expect{@samanage.delete_site(id: invalid_site_id)}.to raise_error(Samanage::NotFound)
48
+ end
49
+ end
50
50
  end
@@ -1,119 +1,136 @@
1
1
  require 'samanage'
2
2
 
3
3
  describe Samanage::Api do
4
- context 'Users' do
5
- before(:all) do
6
- TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
7
- @samanage = Samanage::Api.new(token: TOKEN)
8
- @users = @samanage.users
9
- end
10
- describe 'API Functions' do
11
- it 'get_users: it returns API call of users' do
12
- api_call = @samanage.get_users
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_users: collects array of users' do
19
- user_count = @samanage.get_users[:total_count]
20
- expect(@users).to be_an(Array)
21
- expect(@users.size).to eq(user_count)
22
- end
23
- it 'create_user(payload: json): creates a user' do
24
- user_name = "samanage-ruby-#{(rand*10**10).ceil}"
25
- email = user_name + "@samanage.com"
26
- json = {
27
- :user => {
28
- :name => user_name,
29
- :email => email,
30
- }
31
- }
32
- user_create = @samanage.create_user(payload: json)
33
- expect(user_create[:data]['email']).to eq(email)
34
- expect(user_create[:data]['id']).to be_an(Integer)
35
- expect(user_create[:data]['name']).to eq(user_name)
36
- expect(user_create[:code]).to eq(200).or(201)
37
- end
38
- it 'create_user: fails if no email' do
39
- user_name = "samanage-ruby-#{(rand*10**(rand(10))).ceil}"
40
- json = {
41
- :user => {
4
+ context 'Users' do
5
+ before(:all) do
6
+ TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
7
+ @samanage = Samanage::Api.new(token: TOKEN, development_mode: true)
8
+ @users = @samanage.users
9
+ end
10
+ describe 'API Functions' do
11
+ it 'ensures custom field is updated' do
12
+ val ="Random #{(rand*10**4).ceil}"
13
+ field_name = @samanage.custom_forms['user'][0]['custom_form_fields'].sample.dig('custom_field','name')
14
+ payload = {
15
+ user: {
16
+ custom_fields_values:{
17
+ custom_fields_value:[
18
+ { name: field_name, value: val}
19
+ ]
20
+ }
21
+ }
22
+ }
23
+ user_id = @users.sample.dig('id')
24
+ api_call = @samanage.update_user(id: user_id, payload: payload)
25
+ return_val = api_call.dig(:data,'custom_fields_values').select{|i| i['name'] == field_name}.first.to_h.dig('value')
26
+ expect(val).to eq(return_val)
27
+ end
28
+ it 'get_users: it returns API call of users' do
29
+ api_call = @samanage.get_users
30
+ expect(api_call).to be_a(Hash)
31
+ expect(api_call[:total_count]).to be_an(Integer)
32
+ expect(api_call).to have_key(:response)
33
+ expect(api_call).to have_key(:code)
34
+ end
35
+ it 'collect_users: collects array of users' do
36
+ user_count = @samanage.get_users[:total_count]
37
+ expect(@users).to be_an(Array)
38
+ expect(@users.size).to eq(user_count)
39
+ end
40
+ it 'create_user(payload: json): creates a user' do
41
+ user_name = "samanage-ruby-#{(rand*10**10).ceil}"
42
+ email = user_name + "@samanage.com"
43
+ json = {
44
+ :user => {
42
45
  :name => user_name,
43
- }
44
- }
45
- expect{@samanage.create_user(payload: json)}.to raise_error(Samanage::InvalidRequest)
46
- end
47
- it 'find_user: returns a user card by known id' do
48
- sample_id = @users.sample['id']
49
- user = @samanage.find_user(id: sample_id)
50
- expect(user[:data]['id']).to eq(sample_id) # id should match found user
51
- expect(user[:data]).to have_key('email')
52
- expect(user[:data]).to have_key('name')
53
- end
46
+ :email => email,
47
+ }
48
+ }
49
+ user_create = @samanage.create_user(payload: json)
50
+ expect(user_create[:data]['email']).to eq(email)
51
+ expect(user_create[:data]['id']).to be_an(Integer)
52
+ expect(user_create[:data]['name']).to eq(user_name)
53
+ expect(user_create[:code]).to eq(200).or(201)
54
+ end
55
+ it 'create_user: fails if no email' do
56
+ user_name = "samanage-ruby-#{(rand*10**(rand(10))).ceil}"
57
+ json = {
58
+ :user => {
59
+ :name => user_name,
60
+ }
61
+ }
62
+ expect{@samanage.create_user(payload: json)}.to raise_error(Samanage::InvalidRequest)
63
+ end
64
+ it 'find_user: returns a user card by known id' do
65
+ sample_id = @users.sample['id']
66
+ user = @samanage.find_user(id: sample_id)
67
+ expect(user[:data]['id']).to eq(sample_id) # id should match found user
68
+ expect(user[:data]).to have_key('email')
69
+ expect(user[:data]).to have_key('name')
70
+ end
54
71
 
55
72
 
56
- it 'find_user: returns nothing for an invalid id' do
57
- sample_id = (0..10).entries.sample
58
- expect{@samanage.find_user(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found user
59
- end
73
+ it 'find_user: returns nothing for an invalid id' do
74
+ sample_id = (0..10).entries.sample
75
+ expect{@samanage.find_user(id: sample_id)}.to raise_error(Samanage::NotFound) # id should match found user
76
+ end
60
77
 
61
- it 'finds_user_id_by_email' do
62
- sample_user = @users.sample
63
- sample_email = sample_user['email']
64
- sample_id = sample_user['id']
65
- found_id = @samanage.find_user_id_by_email(email: sample_email)
66
- expect(sample_email).not_to be(nil)
67
- expect(sample_id).to eq(found_id)
68
- end
78
+ it 'finds_user_id_by_email' do
79
+ sample_user = @users.sample
80
+ sample_email = sample_user['email']
81
+ sample_id = sample_user['id']
82
+ found_id = @samanage.find_user_id_by_email(email: sample_email)
83
+ expect(sample_email).not_to be(nil)
84
+ expect(sample_id).to eq(found_id)
85
+ end
69
86
 
70
- it 'finds group_id for user' do
71
- sample_user = @users.select{|u| u['role']['name'] == 'Administrator'}.sample
72
- sample_user_email = sample_user['email']
73
- group_ids = sample_user['group_ids']
74
- found_id = nil
87
+ it 'finds group_id for user' do
88
+ sample_user = @users.select{|u| u['role']['name'] == 'Administrator'}.sample
89
+ sample_user_email = sample_user['email']
90
+ group_ids = sample_user['group_ids']
91
+ found_id = nil
75
92
 
76
- group_ids.each do |group_id|
77
- group = @samanage.find_group(id: group_id)
78
- if group[:data]['is_user'] && sample_user_email == group[:data]['email']
79
- found_id ||= group_id
80
- end
81
- end
82
- function_id = @samanage.find_user_group_id_by_email(email: sample_user_email)
93
+ group_ids.each do |group_id|
94
+ group = @samanage.find_group(id: group_id)
95
+ if group[:data]['is_user'] && sample_user_email == group[:data]['email']
96
+ found_id ||= group_id
97
+ end
98
+ end
99
+ function_id = @samanage.find_user_group_id_by_email(email: sample_user_email)
83
100
 
84
- expect(function_id).to eq(found_id)
85
- end
101
+ expect(function_id).to eq(found_id)
102
+ end
86
103
 
87
104
 
88
- it 'returns nil for invalid find_user_group_id_by_email' do
89
- invalid_user_email = 'abc@123.gov'
90
- function_id = @samanage.find_user_group_id_by_email(email: invalid_user_email)
105
+ it 'returns nil for invalid find_user_group_id_by_email' do
106
+ invalid_user_email = 'abc@123.gov'
107
+ function_id = @samanage.find_user_group_id_by_email(email: invalid_user_email)
91
108
 
92
- expect(function_id).to be(nil)
93
- end
109
+ expect(function_id).to be(nil)
110
+ end
94
111
 
95
- it 'returns nil for invalid find_user_id_by_email' do
96
- invalid_user_email = 'abc@123.gov'
97
- function_id = @samanage.find_user_id_by_email(email: invalid_user_email)
112
+ it 'returns nil for invalid find_user_id_by_email' do
113
+ invalid_user_email = 'abc@123.gov'
114
+ function_id = @samanage.find_user_id_by_email(email: invalid_user_email)
98
115
 
99
- expect(function_id).to be(nil)
100
- end
116
+ expect(function_id).to be(nil)
117
+ end
101
118
 
102
119
 
103
120
 
104
- it 'update_user: update_user by id' do
105
- sample_id = @users.sample['id']
106
- new_name = (0...25).map { ('a'..'z').to_a[rand(26)] }.join
107
- json = {
108
- :user => {
109
- :name => new_name
110
- }
111
- }
112
- user_update = @samanage.update_user(payload: json, id: sample_id)
113
- expect(user_update[:data]["name"]).to eq(new_name)
114
- expect(user_update[:code]).to eq(200).or(201)
115
- end
116
- it 'deletes a valid user' do
121
+ it 'update_user: update_user by id' do
122
+ sample_id = @users.sample['id']
123
+ new_name = (0...25).map { ('a'..'z').to_a[rand(26)] }.join
124
+ json = {
125
+ :user => {
126
+ :name => new_name
127
+ }
128
+ }
129
+ user_update = @samanage.update_user(payload: json, id: sample_id)
130
+ expect(user_update[:data]["name"]).to eq(new_name)
131
+ expect(user_update[:code]).to eq(200).or(201)
132
+ end
133
+ it 'deletes a valid user' do
117
134
  sample_user_id = @users.select{|u| !u['last_login']}.sample['id']
118
135
  user_delete = @samanage.delete_user(id: sample_user_id)
119
136
  expect(user_delete[:code]).to eq(200).or(201)
@@ -122,6 +139,6 @@ describe Samanage::Api do
122
139
  invalid_user_id = 0
123
140
  expect{@samanage.delete_user(id: invalid_user_id)}.to raise_error(Samanage::InvalidRequest)
124
141
  end
125
- end
126
- end
142
+ end
143
+ end
127
144
  end