From f7ccb2c0dcefef3ae2b7b0e14172c6ae401b8f12 Mon Sep 17 00:00:00 2001 From: YYChen01988 Date: Thu, 11 Apr 2024 09:21:16 +0100 Subject: [PATCH] fix(test) added more end to end test for validated all the changeable fields in an error callback --- .../jvm-scenarios/detekt-baseline.xml | 2 + ...ndledExceptionEventDetailChangeScenario.kt | 75 +++++++++++++++++++ .../error_callback_alters_fields.feature | 53 +++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 features/fixtures/mazerunner/jvm-scenarios/src/main/java/com/bugsnag/android/mazerunner/scenarios/UnhandledExceptionEventDetailChangeScenario.kt create mode 100644 features/full_tests/error_callback_alters_fields.feature diff --git a/features/fixtures/mazerunner/jvm-scenarios/detekt-baseline.xml b/features/fixtures/mazerunner/jvm-scenarios/detekt-baseline.xml index 1fcda340f9..d18bb02cbd 100644 --- a/features/fixtures/mazerunner/jvm-scenarios/detekt-baseline.xml +++ b/features/fixtures/mazerunner/jvm-scenarios/detekt-baseline.xml @@ -24,6 +24,8 @@ MagicNumber:StartupCrashFlushScenario.kt$StartupCrashFlushScenario$6000 MagicNumber:TestHarnessHooks.kt$<no name provided>$500 MagicNumber:TrimmedStacktraceScenario.kt$TrimmedStacktraceScenario$100000 + MagicNumber:UnhandledExceptionEventDetailChangeScenario.kt$UnhandledExceptionEventDetailChangeScenario$123 + MagicNumber:UnhandledExceptionEventDetailChangeScenario.kt$UnhandledExceptionEventDetailChangeScenario$123456 ThrowingExceptionsWithoutMessageOrCause:AnrHelper.kt$<no name provided>$IllegalStateException() ThrowingExceptionsWithoutMessageOrCause:BugsnagInitScenario.kt$BugsnagInitScenario$RuntimeException() ThrowingExceptionsWithoutMessageOrCause:CustomPluginNotifierDescriptionScenario.kt$CustomPluginNotifierDescriptionScenario$RuntimeException() diff --git a/features/fixtures/mazerunner/jvm-scenarios/src/main/java/com/bugsnag/android/mazerunner/scenarios/UnhandledExceptionEventDetailChangeScenario.kt b/features/fixtures/mazerunner/jvm-scenarios/src/main/java/com/bugsnag/android/mazerunner/scenarios/UnhandledExceptionEventDetailChangeScenario.kt new file mode 100644 index 0000000000..62c880cf63 --- /dev/null +++ b/features/fixtures/mazerunner/jvm-scenarios/src/main/java/com/bugsnag/android/mazerunner/scenarios/UnhandledExceptionEventDetailChangeScenario.kt @@ -0,0 +1,75 @@ +package com.bugsnag.android.mazerunner.scenarios + +import android.content.Context +import com.bugsnag.android.BreadcrumbType +import com.bugsnag.android.Bugsnag +import com.bugsnag.android.Configuration +import com.bugsnag.android.OnErrorCallback +import com.bugsnag.android.Severity + +/** + * Sends an unhandled exception to Bugsnag where the event details are changed in a callback + */ +internal class UnhandledExceptionEventDetailChangeScenario( + config: Configuration, + context: Context, + eventMetadata: String? +) : Scenario(config, context, eventMetadata) { + + init { + + config.addOnError( + OnErrorCallback { event -> + event.apiKey = "0000111122223333aaaabbbbcccc9999" + event.severity = Severity.ERROR + event.groupingHash = "groupingHash1" + event.context = "new-context" + event.setUser("abc", "joe@test.com", "Joe") + event.addMetadata("custom_data", "test_data", "this is test") + event.addFeatureFlag("beta", "a") + event.isUnhandled = false + event.app.binaryArch = "x86" + event.app.id = "12345" + event.app.releaseStage = "custom" + event.app.version = "1.2.3" + event.app.buildUuid = "12345678" + event.app.type = "android_custom" + event.app.versionCode = 123 + event.app.duration = 123456 + event.app.durationInForeground = 123456 + event.app.inForeground = false + event.app.isLaunching = false + + event.device.id = "12345" + event.device.jailbroken = true + event.device.locale = "en-UK" + event.device.totalMemory = 123456 + event.device.runtimeVersions = mutableMapOf("androidApiLevel" to "30") + event.device.freeDisk = 123456 + event.device.freeMemory = 123456 + event.device.orientation = "portrait" + + event.breadcrumbs.removeLast() + event.breadcrumbs.first().type = BreadcrumbType.ERROR + event.breadcrumbs.first().message = "new breadcrumb message" + event.breadcrumbs[1].type = BreadcrumbType.ERROR + event.breadcrumbs[1].message = "Second breadcrumb message" + val map: Map = + java.util.Collections.singletonMap("foo", "data") + event.breadcrumbs.first().setMetadata(map) + + true + } + ) + } + + override fun startScenario() { + super.startScenario() + Bugsnag.leaveBreadcrumb("Hello1") + Bugsnag.leaveBreadcrumb("Hello2") + Bugsnag.leaveBreadcrumb("Hello3") + + Bugsnag.notify(RuntimeException("UnhandledExceptionEventDetailChangeScenario")) + throw NullPointerException("something broke") + } +} diff --git a/features/full_tests/error_callback_alters_fields.feature b/features/full_tests/error_callback_alters_fields.feature new file mode 100644 index 0000000000..3022062947 --- /dev/null +++ b/features/full_tests/error_callback_alters_fields.feature @@ -0,0 +1,53 @@ +Feature: When the api key is altered in an Event the JSON payload reflects this + + Background: + Given I clear all persistent data + + Scenario: Unhandled exception with altered event details + When I run "UnhandledExceptionEventDetailChangeScenario" and relaunch the crashed app + And I configure Bugsnag for "UnhandledExceptionApiKeyChangeScenario" + And I wait to receive an error + And the error payload field "events" is an array with 1 elements + And the exception "message" equals "UnhandledExceptionEventDetailChangeScenario" + And the error payload field "apiKey" equals "0000111122223333aaaabbbbcccc9999" + And the error "Bugsnag-Api-Key" header equals "0000111122223333aaaabbbbcccc9999" + And the event "severity" equals "error" + And the event "context" equals "new-context" + And the event "groupingHash" equals "groupingHash1" + And the event "user.id" equals "abc" + And the event "user.email" equals "joe@test.com" + And the event "user.name" equals "Joe" + And the event "metaData.custom_data.test_data" equals "this is test" + And event 0 contains the feature flag "beta" with variant "a" + + # app fields + And the event "unhandled" is false + And the event "app.binaryArch" equals "x86" + And the event "app.id" equals "12345" + And the event "app.releaseStage" equals "custom" + And the event "app.version" equals "1.2.3" + And the event "app.buildUUID" equals "12345678" + And the event "app.type" equals "android_custom" + And the event "app.versionCode" equals 123 + And the event "app.duration" equals 123456 + And the event "app.durationInForeground" equals 123456 + And the event "app.inForeground" is false + And the event "app.isLaunching" is false + + # device fields + And the event "device.id" equals "12345" + And the event "device.jailbroken" is true + And the event "device.locale" equals "en-UK" + And the event "device.totalMemory" equals 123456 + And the event "device.runtimeVersions.androidApiLevel" equals "30" + And the event "device.freeDisk" equals 123456 + And the event "device.freeMemory" equals 123456 + And the event "device.orientation" equals "portrait" + + # breadcrumbs fields + And the event has 3 breadcrumbs + And the event "breadcrumbs.0.type" equals "error" + And the event "breadcrumbs.0.name" equals "new breadcrumb message" + And the event "breadcrumbs.1.type" equals "error" + And the event "breadcrumbs.1.name" equals "Second breadcrumb message" + And the event "breadcrumbs.0.metaData.foo" equals "data"