Skip to content

Commit

Permalink
Update to use simplified steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Cawllec committed Sep 18, 2024
1 parent 61ef8f3 commit 67304ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'

gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'dynamic-validation/config-changes'
gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'validation/extra-capabilities'
60 changes: 7 additions & 53 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,65 +11,19 @@
validator.validate_header('bugsnag-api-key') { |value| value.eql?($api_key) }
validator.validate_header('content-type') { |value| value.eql?('application/json') }
validator.validate_header('bugsnag-payload-version') { |value| value.eql?('4') }
validator.validate_header('bugsnag-sent-at') do |value|
begin
Date.iso8601(value)
rescue Date::Error
validator.success = false
validator.errors << "bugsnag-sent-at header was expected to be an ISO 8601 date, but was '#{value}'"
end
end
validator.validate_header('bugsnag-sent-at') { |value| Date.iso8601(value) }

notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name')
if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go')
validator.success = false
validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'"
end

['notifier.url', 'notifier.version', 'events'].each do |element_key|
element = Maze::Helper.read_key_path(validator.body, element_key)
if element.nil? || (element.is_a?(Array) && element.empty?)
validator.success = false
validator.errors << "Required error element #{element_key} was not present"
end
end

events = Maze::Helper.read_key_path(validator.body, 'events')
events.each_with_index do |event, index|
['severity', 'severityReason.type', 'unhandled', 'exceptions'].each do |element_key|
element = Maze::Helper.read_key_path(event, element_key)
if element.nil? || (element.is_a?(Array) && element.empty?)
validator.success = false
validator.errors << "Required event element #{element_key} was not present in event #{index}"
end
end
end
validator.element_has_value('notifier.name', 'Bugsnag Go')
validator.each_element_exists(['notifier.url', 'notifier.version', 'events'])
validator.each_event_contains_each(['severity', 'severityReason.type', 'unhandled', 'exceptions'])
end

Maze.config.add_validator('session') do |validator|
validator.validate_header('bugsnag-api-key') { |value| value.eql?($api_key) }
validator.validate_header('content-type') { |value| value.eql?('application/json') }
validator.validate_header('bugsnag-payload-version') { |value| value.eql?('1.0') }
validator.validate_header('bugsnag-sent-at') do |value|
begin
Date.iso8601(value)
rescue Date::Error
validator.success = false
validator.errors << "bugsnag-sent-at header was expected to be an ISO 8601 date, but was '#{value}'"
end
end

notifier_name = Maze::Helper.read_key_path(validator.body, 'notifier.name')
if notifier_name.nil? || !notifier_name.eql?('Bugsnag Go')
validator.success = false
validator.errors << "Notifier name in body was expected to be 'Bugsnag Go', but was '#{notifier_name}'"
end
validator.validate_header('bugsnag-sent-at') { |value| Date.iso8601(value) }

['notifier.url', 'notifier.version', 'app', 'device'].each do |element_key|
element = Maze::Helper.read_key_path(validator.body, element_key)
if element.nil? || (element.is_a?(Array) && element.empty?)
validator.success = false
validator.errors << "Required session element #{element_key} was not present"
end
end
validator.element_has_value('notifier.name', 'Bugsnag Go')
validator.each_element_exists(['notifier.url', 'notifier.version', 'app', 'device'])
end

0 comments on commit 67304ce

Please sign in to comment.