Skip to content

Commit

Permalink
fix(test) added more end to end test for validated all the changeable…
Browse files Browse the repository at this point in the history
… fields in an error callback
  • Loading branch information
YYChen01988 committed Apr 11, 2024
1 parent 1c58306 commit f7ccb2c
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<ID>MagicNumber:StartupCrashFlushScenario.kt$StartupCrashFlushScenario$6000</ID>
<ID>MagicNumber:TestHarnessHooks.kt$&lt;no name provided>$500</ID>
<ID>MagicNumber:TrimmedStacktraceScenario.kt$TrimmedStacktraceScenario$100000</ID>
<ID>MagicNumber:UnhandledExceptionEventDetailChangeScenario.kt$UnhandledExceptionEventDetailChangeScenario$123</ID>
<ID>MagicNumber:UnhandledExceptionEventDetailChangeScenario.kt$UnhandledExceptionEventDetailChangeScenario$123456</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:AnrHelper.kt$&lt;no name provided>$IllegalStateException()</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:BugsnagInitScenario.kt$BugsnagInitScenario$RuntimeException()</ID>
<ID>ThrowingExceptionsWithoutMessageOrCause:CustomPluginNotifierDescriptionScenario.kt$CustomPluginNotifierDescriptionScenario$RuntimeException()</ID>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Any> =
java.util.Collections.singletonMap<String, Any>("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")
}
}
53 changes: 53 additions & 0 deletions features/full_tests/error_callback_alters_fields.feature
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit f7ccb2c

Please sign in to comment.