From 67304ce8c936880d394dab09577016d43c14614b Mon Sep 17 00:00:00 2001 From: Alex Moinet Date: Wed, 18 Sep 2024 16:55:29 +0100 Subject: [PATCH] Update to use simplified steps --- Gemfile | 2 +- features/support/env.rb | 60 +++++------------------------------------ 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/Gemfile b/Gemfile index 8a58451..9951dc1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' -gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'dynamic-validation/config-changes' \ No newline at end of file +gem "bugsnag-maze-runner", git: 'https://github.com/bugsnag/maze-runner', branch: 'validation/extra-capabilities' \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index 110cc01..3235071 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -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