samanage 2.1.19 → 2.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +224 -0
- data/Gemfile +12 -7
- data/Gemfile.lock +43 -24
- data/Guardfile +5 -3
- data/changelog.md +92 -19
- data/lib/samanage.rb +33 -30
- data/lib/samanage/api.rb +67 -74
- data/lib/samanage/api/attachments.rb +12 -12
- data/lib/samanage/api/category.rb +9 -7
- data/lib/samanage/api/changes.rb +17 -16
- data/lib/samanage/api/comments.rb +6 -7
- data/lib/samanage/api/contracts.rb +17 -17
- data/lib/samanage/api/custom_fields.rb +6 -6
- data/lib/samanage/api/custom_forms.rb +13 -10
- data/lib/samanage/api/departments.rb +9 -9
- data/lib/samanage/api/groups.rb +21 -20
- data/lib/samanage/api/hardwares.rb +14 -14
- data/lib/samanage/api/incidents.rb +7 -8
- data/lib/samanage/api/mobiles.rb +14 -15
- data/lib/samanage/api/other_assets.rb +14 -14
- data/lib/samanage/api/problems.rb +17 -17
- data/lib/samanage/api/purchase_orders.rb +17 -17
- data/lib/samanage/api/releases.rb +14 -14
- data/lib/samanage/api/requester.rb +4 -2
- data/lib/samanage/api/sites.rb +10 -9
- data/lib/samanage/api/solutions.rb +15 -14
- data/lib/samanage/api/tasks.rb +39 -0
- data/lib/samanage/api/time_tracks.rb +8 -6
- data/lib/samanage/api/users.rb +32 -30
- data/lib/samanage/api/utils.rb +11 -9
- data/lib/samanage/api/vendors.rb +14 -13
- data/lib/samanage/error.rb +5 -4
- data/lib/samanage/language.rb +48 -46
- data/lib/samanage/url_builder.rb +27 -25
- data/lib/samanage/utils.rb +10 -8
- data/lib/samanage/version.rb +1 -1
- data/samanage.gemspec +11 -9
- data/spec/api/samanage_attachment_spec.rb +20 -19
- data/spec/api/samanage_category_spec.rb +12 -10
- data/spec/api/samanage_change_spec.rb +47 -44
- data/spec/api/samanage_comments_spec.rb +12 -10
- data/spec/api/samanage_contract_spec.rb +41 -35
- data/spec/api/samanage_custom_field_spec.rb +7 -5
- data/spec/api/samanage_custom_form_spec.rb +11 -9
- data/spec/api/samanage_department_spec.rb +20 -15
- data/spec/api/samanage_group_spec.rb +30 -28
- data/spec/api/samanage_hardware_spec.rb +44 -38
- data/spec/api/samanage_incident_spec.rb +79 -61
- data/spec/api/samanage_mobile_spec.rb +39 -34
- data/spec/api/samanage_other_asset_spec.rb +50 -44
- data/spec/api/samanage_problem_spec.rb +53 -46
- data/spec/api/samanage_purchase_order_spec.rb +43 -40
- data/spec/api/samanage_release_spec.rb +44 -40
- data/spec/api/samanage_site_spec.rb +18 -16
- data/spec/api/samanage_solution_spec.rb +16 -14
- data/spec/api/samanage_task_spec.rb +68 -0
- data/spec/api/samanage_time_tracks_spec.rb +41 -27
- data/spec/api/samanage_user_spec.rb +51 -46
- data/spec/api/samanage_util_spec.rb +13 -11
- data/spec/api/samanage_vendors_spec.rb +18 -16
- data/spec/samanage_api_spec.rb +27 -23
- data/spec/samanage_category_spec.rb +10 -8
- data/spec/samanage_language_spec.rb +12 -10
- data/spec/samanage_url_builder_spec.rb +11 -9
- data/spec/spec_helper.rb +6 -4
- metadata +5 -2
@@ -1,80 +1,85 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "samanage"
|
2
4
|
|
3
5
|
describe Samanage::Api do
|
4
|
-
context
|
5
|
-
describe
|
6
|
+
context "Mobile" do
|
7
|
+
describe "API Functions" do
|
6
8
|
before(:all) do
|
7
|
-
TOKEN ||= ENV[
|
9
|
+
TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
|
8
10
|
@samanage = Samanage::Api.new(token: TOKEN)
|
9
11
|
@mobiles = @samanage.mobiles
|
10
12
|
end
|
11
|
-
it
|
13
|
+
it "get_mobiles: it returns API call of mobiles" do
|
12
14
|
api_call = @samanage.get_mobiles
|
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
|
20
|
+
it "collect_mobiles: collects array of mobiles" do
|
19
21
|
mobile_count = @samanage.get_mobiles[:total_count]
|
20
22
|
expect(@mobiles).to be_an(Array)
|
21
23
|
expect(@mobiles.size).to eq(mobile_count)
|
22
24
|
end
|
23
|
-
it
|
24
|
-
mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
25
|
-
serial_number = (0...50).map { (
|
25
|
+
it "create_mobile(payload: json): creates a mobile" do
|
26
|
+
mobile_name = "samanage-ruby-#{(rand * 10**10).ceil}"
|
27
|
+
serial_number = (0...50).map { ("a".."z").to_a[rand(26)] }.join
|
26
28
|
json = {
|
27
|
-
:
|
28
|
-
model:
|
29
|
+
mobile: {
|
30
|
+
model: "test",
|
29
31
|
manufacturer: mobile_name,
|
30
32
|
serial_number: serial_number,
|
31
33
|
}
|
32
34
|
}
|
33
35
|
mobile_create = @samanage.create_mobile(payload: json)
|
34
36
|
|
35
|
-
expect(mobile_create[:data][
|
36
|
-
expect(mobile_create[:data][
|
37
|
+
expect(mobile_create[:data]["id"]).to be_an(Integer)
|
38
|
+
expect(mobile_create[:data]["manufacturer"]).to eq(mobile_name)
|
37
39
|
end
|
38
|
-
it
|
39
|
-
mobile_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
40
|
+
it "create_mobile: fails if no serial" do
|
41
|
+
mobile_name = "samanage-ruby-#{(rand * 10**10).ceil}"
|
40
42
|
json = {
|
41
|
-
:
|
42
|
-
model:
|
43
|
+
mobile: {
|
44
|
+
model: "test",
|
43
45
|
manufacturer: mobile_name,
|
44
46
|
}
|
45
47
|
}
|
46
|
-
expect{@samanage.create_mobile(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
48
|
+
expect { @samanage.create_mobile(payload: json) }.to raise_error(Samanage::InvalidRequest)
|
47
49
|
end
|
48
|
-
it
|
49
|
-
sample_id = @mobiles.sample[
|
50
|
+
it "find_mobile: returns a mobile card by known id" do
|
51
|
+
sample_id = @mobiles.sample["id"]
|
50
52
|
mobile = @samanage.find_mobile(id: sample_id)
|
51
53
|
|
52
|
-
expect(mobile[:data][
|
53
|
-
expect(mobile[:data]).to have_key(
|
54
|
-
expect(mobile[:data]).to have_key(
|
55
|
-
expect(mobile[:data]).to have_key(
|
54
|
+
expect(mobile[:data]["id"]).to eq(sample_id) # id should match found mobile
|
55
|
+
expect(mobile[:data]).to have_key("manufacturer")
|
56
|
+
expect(mobile[:data]).to have_key("serial_number")
|
57
|
+
expect(mobile[:data]).to have_key("id")
|
56
58
|
end
|
57
|
-
it
|
59
|
+
it "find_mobile: returns nothing for an invalid id" do
|
58
60
|
sample_id = (0..10).entries.sample
|
59
|
-
|
61
|
+
# id should match found mobile
|
62
|
+
expect {
|
63
|
+
@samanage.find_mobile(id: sample_id)
|
64
|
+
}.to raise_error(Samanage::NotFound)
|
60
65
|
end
|
61
|
-
it
|
62
|
-
sample_id = @mobiles.sample[
|
63
|
-
new_name = (0...50).map {(
|
66
|
+
it "update_mobile: update_mobile by id" do
|
67
|
+
sample_id = @mobiles.sample["id"]
|
68
|
+
new_name = (0...50).map { ("a".."z").to_a[rand(26)] }.join
|
64
69
|
json = {
|
65
|
-
:
|
66
|
-
:
|
70
|
+
mobile: {
|
71
|
+
manufacturer: new_name
|
67
72
|
}
|
68
73
|
}
|
69
74
|
mobile_update = @samanage.update_mobile(payload: json, id: sample_id)
|
70
75
|
expect(mobile_update[:data]["manufacturer"]).to eq(new_name)
|
71
76
|
expect(mobile_update[:code]).to eq(200).or(201)
|
72
77
|
end
|
73
|
-
it
|
74
|
-
sample_mobile_id = @mobiles.sample[
|
78
|
+
it "deletes a valid mobile" do
|
79
|
+
sample_mobile_id = @mobiles.sample["id"]
|
75
80
|
mobile_delete = @samanage.delete_mobile(id: sample_mobile_id)
|
76
81
|
expect(mobile_delete[:code]).to eq(200).or(201)
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
80
|
-
end
|
85
|
+
end
|
@@ -1,84 +1,90 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "samanage"
|
2
4
|
|
3
5
|
describe Samanage::Api do
|
4
|
-
context
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it
|
6
|
+
context "Other Assets" do
|
7
|
+
describe "API Functions" do
|
8
|
+
before(:all) do
|
9
|
+
TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
|
10
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
11
|
+
@other_assets = @samanage.get_other_assets[:data]
|
12
|
+
end
|
13
|
+
it "get_other_assets: it returns API call of other_assets" do
|
12
14
|
api_call = @samanage.get_other_assets
|
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
|
20
|
+
it "collect_other_assets: collects array of other_assets" do
|
19
21
|
expect(@other_assets).to be_an(Array)
|
20
22
|
end
|
21
|
-
it
|
22
|
-
other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
23
|
+
it "create_other_asset(payload: json): creates a other_asset" do
|
24
|
+
other_asset_name = "samanage-ruby-#{(rand * 10**10).ceil}"
|
23
25
|
json = {
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
26
|
+
other_asset: {
|
27
|
+
name: other_asset_name,
|
28
|
+
manufacturer: "Samanage",
|
29
|
+
asset_type: { name: "Asset" },
|
30
|
+
status: { name: "Operational" }
|
29
31
|
}
|
30
32
|
}
|
31
33
|
|
32
34
|
other_asset_create = @samanage.create_other_asset(payload: json)
|
33
|
-
expect(other_asset_create[:data][
|
34
|
-
expect(other_asset_create[:data][
|
35
|
+
expect(other_asset_create[:data]["id"]).to be_an(Integer)
|
36
|
+
expect(other_asset_create[:data]["name"]).to eq(other_asset_name)
|
35
37
|
expect(other_asset_create[:code]).to eq(200).or(201)
|
36
38
|
end
|
37
|
-
it
|
38
|
-
other_asset_name = "samanage-ruby-#{(rand*10**10).ceil}"
|
39
|
+
it "create_other_asset: fails if wrong fields" do
|
40
|
+
other_asset_name = "samanage-ruby-#{(rand * 10**10).ceil}"
|
39
41
|
json = {
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
42
|
+
other_asset: {
|
43
|
+
name: other_asset_name,
|
44
|
+
manufacturer: "Samanage",
|
45
|
+
asset_type: { name: "Asset" },
|
46
|
+
status: { name: "Operational" }
|
45
47
|
}
|
46
48
|
}
|
47
49
|
json[:other_asset].delete(json[:other_asset].keys.sample) # Delete random sample from the examples above
|
48
|
-
expect{
|
50
|
+
expect {
|
51
|
+
@samanage.create_other_asset(payload: json)
|
52
|
+
}.to raise_error(Samanage::InvalidRequest)
|
49
53
|
end
|
50
54
|
|
51
|
-
it
|
52
|
-
sample_id = @other_assets.sample[
|
55
|
+
it "find_other_asset: returns an other_asset card by known id" do
|
56
|
+
sample_id = @other_assets.sample["id"]
|
53
57
|
|
54
58
|
other_asset = @samanage.find_other_asset(id: sample_id)
|
55
59
|
|
56
|
-
expect(other_asset[:data][
|
57
|
-
expect(other_asset[:data]).to have_key(
|
58
|
-
expect(other_asset[:data]).to have_key(
|
59
|
-
expect(other_asset[:data]).to have_key(
|
60
|
+
expect(other_asset[:data]["id"]).to eq(sample_id) # id should match found other_asset
|
61
|
+
expect(other_asset[:data]).to have_key("name")
|
62
|
+
expect(other_asset[:data]).to have_key("serial_number")
|
63
|
+
expect(other_asset[:data]).to have_key("id")
|
60
64
|
end
|
61
|
-
it
|
65
|
+
it "find_other_asset: returns nothing for an invalid id" do
|
62
66
|
sample_id = (0..10).entries.sample
|
63
|
-
expect{
|
67
|
+
expect {
|
68
|
+
@samanage.find_other_asset(id: sample_id)
|
69
|
+
}.to raise_error(Samanage::NotFound) # id should match found other_asset
|
64
70
|
end
|
65
|
-
it
|
66
|
-
sample_id = @other_assets.sample[
|
67
|
-
new_name = (0...50).map { (
|
71
|
+
it "update_other_asset: update_other_asset by id" do
|
72
|
+
sample_id = @other_assets.sample["id"]
|
73
|
+
new_name = (0...50).map { ("a".."z").to_a[rand(26)] }.join
|
68
74
|
json = {
|
69
|
-
:
|
70
|
-
:
|
75
|
+
other_asset: {
|
76
|
+
name: new_name
|
71
77
|
}
|
72
78
|
}
|
73
79
|
other_asset_update = @samanage.update_other_asset(payload: json, id: sample_id)
|
74
80
|
expect(other_asset_update[:data]["name"]).to eq(new_name)
|
75
81
|
expect(other_asset_update[:code]).to eq(200).or(201)
|
76
82
|
end
|
77
|
-
it
|
78
|
-
sample_other_asset_id = @other_assets.sample[
|
83
|
+
it "deletes a valid other_asset" do
|
84
|
+
sample_other_asset_id = @other_assets.sample["id"]
|
79
85
|
other_asset_delete = @samanage.delete_other_asset(id: sample_other_asset_id)
|
80
86
|
expect(other_asset_delete[:code]).to eq(200).or(201)
|
81
|
-
end
|
87
|
+
end
|
82
88
|
end
|
83
89
|
end
|
84
|
-
end
|
90
|
+
end
|
@@ -1,84 +1,91 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "samanage"
|
4
|
+
require "faker"
|
3
5
|
describe Samanage::Api do
|
4
|
-
context
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
it
|
6
|
+
context "problems" do
|
7
|
+
describe "API Functions" do
|
8
|
+
before(:all) do
|
9
|
+
TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
|
10
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
11
|
+
@problems = @samanage.problems
|
12
|
+
@users = @samanage.get_users[:data]
|
13
|
+
end
|
14
|
+
it "get_problems: it returns API call of problems" do
|
13
15
|
api_call = @samanage.get_problems
|
14
16
|
expect(api_call).to be_a(Hash)
|
15
17
|
expect(api_call[:total_count]).to be_an(Integer)
|
16
18
|
expect(api_call).to have_key(:response)
|
17
19
|
expect(api_call).to have_key(:code)
|
18
20
|
end
|
19
|
-
it
|
21
|
+
it "collect_problems: collects array of problems" do
|
20
22
|
problem_count = @samanage.get_problems[:total_count]
|
21
23
|
@problems = @samanage.problems
|
22
24
|
expect(@problems).to be_an(Array)
|
23
25
|
expect(@problems.size).to eq(problem_count)
|
24
26
|
end
|
25
|
-
it
|
26
|
-
users_email = @samanage.collect_users.sample[
|
27
|
+
it "create_problem(payload: json): creates a problem" do
|
28
|
+
users_email = @samanage.collect_users.sample["email"]
|
27
29
|
problem_name = Faker::Book.title
|
28
30
|
json = {
|
29
31
|
problem: {
|
30
|
-
requester: {email: users_email},
|
32
|
+
requester: { email: users_email },
|
31
33
|
name: problem_name,
|
32
|
-
state:
|
33
|
-
priority:
|
34
|
+
state: "Open",
|
35
|
+
priority: "Low",
|
34
36
|
description: "Description"
|
35
37
|
}
|
36
38
|
}
|
37
39
|
problem_create = @samanage.create_problem(payload: json)
|
38
40
|
|
39
|
-
expect(problem_create[:data][
|
40
|
-
expect(problem_create[:data][
|
41
|
+
expect(problem_create[:data]["id"]).to be_an(Integer)
|
42
|
+
expect(problem_create[:data]["name"]).to eq(problem_name)
|
41
43
|
expect(problem_create[:code]).to eq(200).or(201)
|
42
44
|
end
|
43
|
-
it
|
44
|
-
users_email = @users.sample[
|
45
|
+
it "create_problem: fails if no name/title" do
|
46
|
+
users_email = @users.sample["email"]
|
45
47
|
json = {
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
48
|
+
problem: {
|
49
|
+
requester: { email: users_email },
|
50
|
+
description: "Description"
|
49
51
|
}
|
50
52
|
}
|
51
|
-
expect{
|
53
|
+
expect {
|
54
|
+
@samanage.create_problem(payload: json)
|
55
|
+
}.to raise_error(Samanage::InvalidRequest)
|
52
56
|
end
|
53
|
-
it
|
54
|
-
sample_id = @problems.sample[
|
57
|
+
it "find_problem: returns a problem card by known id" do
|
58
|
+
sample_id = @problems.sample["id"]
|
55
59
|
problem = @samanage.find_problem(id: sample_id)
|
56
60
|
|
57
|
-
expect(problem[:data][
|
58
|
-
expect(problem[:data]).to have_key(
|
59
|
-
expect(problem[:data]).to have_key(
|
60
|
-
expect(problem[:data]).to have_key(
|
61
|
+
expect(problem[:data]["id"]).to eq(sample_id) # id should match found problem
|
62
|
+
expect(problem[:data]).to have_key("name")
|
63
|
+
expect(problem[:data]).to have_key("requester")
|
64
|
+
expect(problem[:data]).to have_key("id")
|
61
65
|
end
|
62
|
-
it
|
63
|
-
sample_id = @problems.sample[
|
66
|
+
it "find_problem: returns more keys with layout=long" do
|
67
|
+
sample_id = @problems.sample["id"]
|
64
68
|
layout_regular_problem = @samanage.find_problem(id: sample_id)
|
65
|
-
layout_long_problem = @samanage.find_problem(id: sample_id, options: {layout:
|
69
|
+
layout_long_problem = @samanage.find_problem(id: sample_id, options: { layout: "long" })
|
66
70
|
|
67
|
-
expect(layout_long_problem[:data][
|
71
|
+
expect(layout_long_problem[:data]["id"]).to eq(sample_id) # id should match found problem
|
68
72
|
expect(layout_long_problem[:data].keys.size).to be > (layout_regular_problem.keys.size)
|
69
73
|
expect(layout_long_problem[:data].keys - layout_regular_problem[:data].keys).to_not be([])
|
70
74
|
end
|
71
|
-
it
|
75
|
+
it "find_problem: returns nothing for an invalid id" do
|
72
76
|
sample_id = (0..10).entries.sample
|
73
|
-
|
77
|
+
# id should match found problem
|
78
|
+
expect {
|
79
|
+
@samanage.find_problem(id: sample_id)
|
80
|
+
}.to raise_error(Samanage::NotFound)
|
74
81
|
end
|
75
|
-
it
|
76
|
-
sample_problem = @problems.reject{|i| [
|
77
|
-
sample_id = sample_problem[
|
78
|
-
description = (0...500).map { (
|
82
|
+
it "update_problem: update_problem by id" do
|
83
|
+
sample_problem = @problems.reject { |i| ["Closed", "Resolved"].include? i["state"] }.sample
|
84
|
+
sample_id = sample_problem["id"]
|
85
|
+
description = (0...500).map { ("a".."z").to_a[rand(26)] }.join
|
79
86
|
problem_json = {
|
80
|
-
:
|
81
|
-
:
|
87
|
+
problem: {
|
88
|
+
description: description
|
82
89
|
}
|
83
90
|
}
|
84
91
|
problem_update = @samanage.update_problem(payload: problem_json, id: sample_id)
|
@@ -86,12 +93,12 @@ describe Samanage::Api do
|
|
86
93
|
expect(problem_update[:code]).to eq(200).or(201)
|
87
94
|
end
|
88
95
|
it 'finds more data for option[:layout] = "long"' do
|
89
|
-
full_layout_problem_keys = @samanage.problems(options: {layout:
|
96
|
+
full_layout_problem_keys = @samanage.problems(options: { layout: "long" }).first.keys
|
90
97
|
basic_problem_keys = @samanage.problems.sample.keys
|
91
98
|
expect(basic_problem_keys.size).to be < full_layout_problem_keys.size
|
92
99
|
end
|
93
|
-
it
|
94
|
-
sample_problem_id = @problems.sample[
|
100
|
+
it "deletes a valid problem" do
|
101
|
+
sample_problem_id = @problems.sample["id"]
|
95
102
|
problem_delete = @samanage.delete_problem(id: sample_problem_id)
|
96
103
|
expect(problem_delete[:code]).to eq(200).or(201)
|
97
104
|
end
|
@@ -1,80 +1,83 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "samanage"
|
4
|
+
require "faker"
|
3
5
|
describe Samanage::Api do
|
4
|
-
context
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
it
|
6
|
+
context "purchase_orders" do
|
7
|
+
describe "API Functions" do
|
8
|
+
before(:all) do
|
9
|
+
TOKEN ||= ENV["SAMANAGE_TEST_API_TOKEN"]
|
10
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
11
|
+
@purchase_orders = @samanage.purchase_orders
|
12
|
+
@users = @samanage.users
|
13
|
+
@vendors = @samanage.vendors
|
14
|
+
end
|
15
|
+
it "get_purchase_orders: it returns API call of purchase_orders" do
|
14
16
|
api_call = @samanage.get_purchase_orders
|
15
17
|
expect(api_call).to be_a(Hash)
|
16
18
|
expect(api_call[:total_count]).to be_an(Integer)
|
17
19
|
expect(api_call).to have_key(:response)
|
18
20
|
expect(api_call).to have_key(:code)
|
19
21
|
end
|
20
|
-
it
|
22
|
+
it "collect_purchase_orders: collects array of purchase_orders" do
|
21
23
|
purchase_order_count = @samanage.get_purchase_orders[:total_count]
|
22
24
|
@purchase_orders = @samanage.purchase_orders
|
23
25
|
expect(@purchase_orders).to be_an(Array)
|
24
26
|
expect(@purchase_orders.size).to eq(purchase_order_count)
|
25
27
|
end
|
26
|
-
it
|
27
|
-
users_email = @users.find{|u| u[
|
28
|
+
it "create_purchase_order(payload: json): creates a purchase_order" do
|
29
|
+
users_email = @users.find { |u| u["role"]["name"] == "Administrator" }.to_h["email"]
|
28
30
|
purchase_order_name = Faker::Book.title
|
29
31
|
json = {
|
30
32
|
purchase_order: {
|
31
|
-
buyer: {email: users_email},
|
33
|
+
buyer: { email: users_email },
|
32
34
|
name: purchase_order_name,
|
33
|
-
vendor: {name: @vendors.sample[
|
35
|
+
vendor: { name: @vendors.sample["name"] }
|
34
36
|
}
|
35
37
|
}
|
36
38
|
purchase_order_create = @samanage.create_purchase_order(payload: json)
|
37
|
-
expect(purchase_order_create[:data][
|
38
|
-
expect(purchase_order_create[:data][
|
39
|
+
expect(purchase_order_create[:data]["id"]).to be_an(Integer)
|
40
|
+
expect(purchase_order_create[:data]["name"]).to eq(purchase_order_name)
|
39
41
|
expect(purchase_order_create[:code]).to eq(200).or(201)
|
40
42
|
end
|
41
|
-
it
|
42
|
-
users_email = @users.sample[
|
43
|
+
it "create_purchase_order: fails if no vendor" do
|
44
|
+
users_email = @users.sample["email"]
|
43
45
|
json = {
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
46
|
+
purchase_order: {
|
47
|
+
buyer: { email: users_email },
|
48
|
+
description: "Description"
|
47
49
|
}
|
48
50
|
}
|
49
|
-
expect{@samanage.create_purchase_order(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
51
|
+
expect { @samanage.create_purchase_order(payload: json) }.to raise_error(Samanage::InvalidRequest)
|
50
52
|
end
|
51
|
-
it
|
52
|
-
sample_id = @purchase_orders.sample[
|
53
|
+
it "find_purchase_order: returns a purchase_order card by known id" do
|
54
|
+
sample_id = @purchase_orders.sample["id"]
|
53
55
|
purchase_order = @samanage.find_purchase_order(id: sample_id)
|
54
|
-
expect(purchase_order[:data][
|
55
|
-
expect(purchase_order[:data]).to have_key(
|
56
|
-
expect(purchase_order[:data]).to have_key(
|
56
|
+
expect(purchase_order[:data]["id"]).to eq(sample_id) # id should match found purchase_order
|
57
|
+
expect(purchase_order[:data]).to have_key("name")
|
58
|
+
expect(purchase_order[:data]).to have_key("id")
|
57
59
|
end
|
58
60
|
|
59
|
-
it
|
61
|
+
it "find_purchase_order: returns nothing for an invalid id" do
|
60
62
|
sample_id = (0..10).entries.sample
|
61
|
-
|
63
|
+
# id should match found purchase_order
|
64
|
+
expect { @samanage.find_purchase_order(id: sample_id) }.to raise_error(Samanage::NotFound)
|
62
65
|
end
|
63
|
-
it
|
64
|
-
sample_purchase_order = @purchase_orders.reject{|i| [
|
65
|
-
sample_id = sample_purchase_order[
|
66
|
-
description = (0...500).map { (
|
66
|
+
it "update_purchase_order: update_purchase_order by id" do
|
67
|
+
sample_purchase_order = @purchase_orders.reject { |i| ["Closed", "Resolved"].include? i["state"] }.sample
|
68
|
+
sample_id = sample_purchase_order["id"]
|
69
|
+
description = (0...500).map { ("a".."z").to_a[rand(26)] }.join
|
67
70
|
purchase_order_json = {
|
68
|
-
:
|
69
|
-
:
|
71
|
+
purchase_order: {
|
72
|
+
description: description
|
70
73
|
}
|
71
74
|
}
|
72
75
|
purchase_order_update = @samanage.update_purchase_order(payload: purchase_order_json, id: sample_id)
|
73
76
|
# expect(purchase_order_update[:data]['description']).to eq(description) # purchase_order bug #00044569
|
74
77
|
expect(purchase_order_update[:code]).to eq(200).or(201)
|
75
78
|
end
|
76
|
-
it
|
77
|
-
sample_purchase_order_id = @purchase_orders.sample[
|
79
|
+
it "deletes a valid purchase_order" do
|
80
|
+
sample_purchase_order_id = @purchase_orders.sample["id"]
|
78
81
|
purchase_order_delete = @samanage.delete_purchase_order(id: sample_purchase_order_id)
|
79
82
|
expect(purchase_order_delete[:code]).to eq(200).or(201)
|
80
83
|
end
|