Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose MiqEvent/EmsEvent group/levels in event stream OPTIONS #1099

Merged
merged 2 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/controllers/api/event_streams_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
module Api
class EventStreamsController < BaseController
def options
render_options(@req.collection, build_additional_fields)
end

private

def build_additional_fields
Fryguy marked this conversation as resolved.
Show resolved Hide resolved
{:timeline_events => EventStream.timeline_options}
end
end
end
20 changes: 20 additions & 0 deletions spec/requests/event_streams_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,24 @@
expect(response).to have_http_status(:forbidden)
end
end

describe 'OPTIONS /api/event_streams' do
it 'returns expected and additional attributes' do
MiqEventDefinitionSet.seed
options(api_event_streams_url)

expect_options_results(:event_streams)

body = response.parsed_body
expect(body["data"].keys).to eq(["timeline_events"])
expect(body["data"]["timeline_events"].keys.sort).to eq(%w[EmsEvent MiqEvent])
expect(body["data"]["timeline_events"]["EmsEvent"].keys.sort).to eq(%w[description group_levels group_names])
expect(body["data"]["timeline_events"]["EmsEvent"]["group_names"].keys.sort).to include("addition", "other")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to test for all of them, just one from the event_handling and the default one "other"

expect(body["data"]["timeline_events"]["EmsEvent"]["group_levels"].keys.sort).to eq(%w[critical detail warning])

expect(body["data"]["timeline_events"]["MiqEvent"].keys.sort).to eq(%w[description group_levels group_names])
expect(body["data"]["timeline_events"]["MiqEvent"]["group_names"].keys.sort).to include("auth_validation", "other")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

expect(body["data"]["timeline_events"]["MiqEvent"]["group_levels"].keys.sort).to eq(%w[detail failure success])
end
end
end
2 changes: 1 addition & 1 deletion spec/requests/querying_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ def create_vms_by_name(names)
describe 'OPTIONS /api/vms' do
it 'returns the options information' do
options(api_vms_url)
expect_options_results(:vms)
expect_options_results(:vms, {})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this method defaulted to {} so we need to change the one caller that wasn't providing a hash and expected it to be defaulted.

end
end

Expand Down
15 changes: 12 additions & 3 deletions spec/support/api/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def expect_tagging_result(tag_results, status = :ok)
end
end

def expect_options_results(type, data = {})
def expect_options_results(type, data = nil)
klass = ::Api::ApiConfig.collections[type].klass.constantize
attributes = select_attributes(klass.attribute_names - klass.virtual_attribute_names)
reflections = (klass.reflections.keys | klass.virtual_reflections.keys.collect(&:to_s)).sort
Expand All @@ -255,9 +255,18 @@ def expect_options_results(type, data = {})
'virtual_attributes' => select_attributes(klass.virtual_attribute_names),
'relationships' => reflections,
'subcollections' => subcollections,
'data' => data
}
expect(response.parsed_body).to eq(expected)

# Data can have complicated structure, so validating it is now optional.
# Basic data structures can be validated here if desired or not provided if
# validating will be done manually.
expected['data'] = data if data

body = response.parsed_body
expected.each_key do |key|
expect(body[key]).to eq(expected[key])
end

expect(response.headers['Access-Control-Allow-Methods']).to include('OPTIONS')
end

Expand Down