forked from ManageIQ/manageiq-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint_spec.rb
106 lines (80 loc) · 3.13 KB
/
entrypoint_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
RSpec.describe "API entrypoint" do
it "returns a :settings hash" do
api_basic_authorize
get api_entrypoint_url
expect(response).to have_http_status(:ok)
expect_result_to_have_keys(%w(settings))
expect(response.parsed_body['settings']).to be_kind_of(Hash)
end
it "returns a locale" do
api_basic_authorize
get api_entrypoint_url
expect(%w(en en_US)).to include(response.parsed_body['settings']['locale'])
end
it "returns users's settings" do
api_basic_authorize
test_settings = {:cartoons => {:saturday => {:tom_jerry => 'n', :bugs_bunny => 'y'}}}
@user.update_attributes!(:settings => test_settings)
get api_entrypoint_url
expect(response.parsed_body).to include("settings" => a_hash_including(test_settings.deep_stringify_keys))
end
it "collection query is sorted" do
api_basic_authorize
get api_entrypoint_url
collection_names = response.parsed_body['collections'].map { |c| c['name'] }
expect(collection_names).to eq(collection_names.sort)
end
it "returns server_info" do
api_basic_authorize
Timecop.freeze(Time.utc(2018, 0o1, 0o1, 0o0, 0o0, 0o0)) do
get api_entrypoint_url
expect(response.parsed_body).to include(
"server_info" => a_hash_including(
"version" => Vmdb::Appliance.VERSION,
"build" => Vmdb::Appliance.BUILD,
"appliance" => MiqServer.my_server.name,
"time" => "2018-01-01T00:00:00Z",
"server_href" => api_server_url(nil, MiqServer.my_server),
"zone_href" => api_zone_url(nil, MiqServer.my_server.zone),
"region_href" => api_region_url(nil, MiqRegion.my_region),
"enterprise_href" => api_enterprise_url(nil, MiqEnterprise.my_enterprise)
)
)
end
end
it "returns product_info" do
api_basic_authorize
get api_entrypoint_url
expect(response.parsed_body).to include(
"product_info" => a_hash_including(
"name" => Vmdb::Appliance.PRODUCT_NAME,
"name_full" => I18n.t("product.name_full"),
"copyright" => I18n.t("product.copyright"),
"support_website" => I18n.t("product.support_website"),
"support_website_text" => I18n.t("product.support_website_text")
)
)
# This test will fail if you have the UI checked out and built with yarn
expect(response.parsed_body['product_info']['branding_info']).to eq({})
end
context 'UI is available' do
it 'product_info contains branding_info' do
api_basic_authorize
expect(ActionController::Base.helpers).to receive(:image_path).at_least(2).times.and_return("foo")
get api_entrypoint_url
expect(response.parsed_body).to include(
"product_info" => a_hash_including(
"branding_info" => a_hash_including(
"brand" => "foo",
"logo" => "foo"
)
)
)
end
end
it "will squeeze consecutive slashes in the path portion of the URI" do
api_basic_authorize
get("http://www.example.com//api")
expect(response).to have_http_status(:ok)
end
end