@datadog/mobile-react-native 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/DatadogSDKReactNative.podspec +2 -1
  2. package/android/build.gradle +73 -3
  3. package/android/gradle.properties +1 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +54 -0
  5. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +86 -0
  6. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdLogs.kt +27 -11
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +305 -0
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +280 -0
  9. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkBridgeExt.kt +2 -2
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +29 -0
  11. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkConfigurationExt.kt +2 -4
  12. package/android/src/main/{java → kotlin}/com/datadog/reactnative/DdSdkReactNativePackage.kt +3 -0
  13. package/android/src/main/kotlin/com/datadog/reactnative/DdTrace.kt +86 -0
  14. package/android/src/main/kotlin/com/datadog/reactnative/GlobalState.kt +32 -0
  15. package/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +23 -0
  16. package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +60 -0
  17. package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +170 -0
  18. package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +408 -0
  19. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +1547 -0
  20. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +306 -0
  21. package/android/src/test/kotlin/com/datadog/reactnative/GlobalStateTest.kt +118 -0
  22. package/android/src/test/kotlin/com/datadog/reactnative/ProxyAuthenticatorTest.kt +123 -0
  23. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +33 -0
  24. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +43 -0
  25. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +22 -0
  26. package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +267 -0
  27. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +26 -0
  28. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +33 -0
  29. package/android/src/test/kotlin/com/datadog/tools/unit/forge/PackageInfoForgeryFactory.kt +20 -0
  30. package/android/src/test/kotlin/com/datadog/tools/unit/forge/Throwable.kt +31 -0
  31. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ThrowableForgeryFactory.kt +21 -0
  32. package/android/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +1 -0
  33. package/ios/Sources/AnyEncodable.swift +138 -0
  34. package/ios/Sources/Attributes.swift +101 -0
  35. package/ios/Sources/DdLogs.swift +35 -11
  36. package/ios/Sources/DdRum.m +3 -1
  37. package/ios/Sources/DdRum.swift +184 -22
  38. package/ios/Sources/DdSdk.swift +190 -10
  39. package/ios/Sources/DdSdkConfiguration.swift +51 -0
  40. package/ios/Sources/DdTrace.swift +41 -6
  41. package/ios/Sources/GlobalState.swift +28 -0
  42. package/ios/Sources/QueueHolder.swift +10 -0
  43. package/ios/Sources/RNDdSdkConfiguration.swift +5 -6
  44. package/lib/commonjs/DdSdkReactNative.js +14 -0
  45. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  46. package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -0
  47. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  48. package/lib/commonjs/foundation.js +36 -2
  49. package/lib/commonjs/foundation.js.map +1 -1
  50. package/lib/commonjs/nativeModulesTypes.js +36 -0
  51. package/lib/commonjs/nativeModulesTypes.js.map +1 -0
  52. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +4 -17
  53. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  54. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
  55. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  56. package/lib/commonjs/types.js +26 -1
  57. package/lib/commonjs/types.js.map +1 -1
  58. package/lib/commonjs/version.js +1 -1
  59. package/lib/commonjs/version.js.map +1 -1
  60. package/lib/module/DdSdkReactNative.js +14 -0
  61. package/lib/module/DdSdkReactNative.js.map +1 -1
  62. package/lib/module/DdSdkReactNativeConfiguration.js +24 -0
  63. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  64. package/lib/module/foundation.js +36 -2
  65. package/lib/module/foundation.js.map +1 -1
  66. package/lib/module/nativeModulesTypes.js +26 -0
  67. package/lib/module/nativeModulesTypes.js.map +1 -0
  68. package/lib/module/rum/instrumentation/DdEventsInterceptor.js +2 -14
  69. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
  70. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +3 -4
  71. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  72. package/lib/module/types.js +23 -0
  73. package/lib/module/types.js.map +1 -1
  74. package/lib/module/version.js +1 -1
  75. package/lib/module/version.js.map +1 -1
  76. package/lib/typescript/DdSdkReactNative.d.ts +2 -0
  77. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +20 -0
  78. package/lib/typescript/foundation.d.ts +3 -2
  79. package/lib/typescript/nativeModulesTypes.d.ts +168 -0
  80. package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +0 -15
  81. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +2 -1
  82. package/lib/typescript/types.d.ts +42 -7
  83. package/lib/typescript/version.d.ts +1 -1
  84. package/package.json +3 -3
  85. package/src/DdSdkReactNative.tsx +20 -0
  86. package/src/DdSdkReactNativeConfiguration.tsx +20 -0
  87. package/src/__tests__/DdSdkReactNative.test.tsx +76 -0
  88. package/src/__tests__/foundation.test.ts +79 -0
  89. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +8 -8
  90. package/src/foundation.tsx +40 -11
  91. package/src/nativeModulesTypes.ts +258 -0
  92. package/src/rum/instrumentation/DdEventsInterceptor.tsx +2 -17
  93. package/src/rum/instrumentation/DdRumErrorTracking.tsx +3 -4
  94. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +2 -1
  95. package/src/types.tsx +62 -7
  96. package/src/version.ts +1 -1
  97. package/android/src/main/java/com/datadog/reactnative/DdRum.kt +0 -142
  98. package/android/src/main/java/com/datadog/reactnative/DdSdk.kt +0 -67
  99. package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +0 -51
@@ -0,0 +1,170 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ package com.datadog.reactnative
8
+
9
+ import com.datadog.android.log.Logger
10
+ import com.facebook.react.bridge.Promise
11
+ import com.facebook.react.bridge.ReactApplicationContext
12
+ import com.facebook.react.bridge.ReadableMap
13
+ import com.nhaarman.mockitokotlin2.verify
14
+ import fr.xgouchet.elmyr.annotation.AdvancedForgery
15
+ import fr.xgouchet.elmyr.annotation.MapForgery
16
+ import fr.xgouchet.elmyr.annotation.StringForgery
17
+ import fr.xgouchet.elmyr.annotation.StringForgeryType
18
+ import fr.xgouchet.elmyr.junit5.ForgeExtension
19
+ import org.junit.jupiter.api.AfterEach
20
+ import org.junit.jupiter.api.BeforeEach
21
+ import org.junit.jupiter.api.Test
22
+ import org.junit.jupiter.api.extension.ExtendWith
23
+ import org.junit.jupiter.api.extension.Extensions
24
+ import org.mockito.Mock
25
+ import org.mockito.junit.jupiter.MockitoExtension
26
+ import org.mockito.junit.jupiter.MockitoSettings
27
+ import org.mockito.quality.Strictness
28
+
29
+ @Extensions(
30
+ ExtendWith(MockitoExtension::class),
31
+ ExtendWith(ForgeExtension::class)
32
+ )
33
+ @MockitoSettings(strictness = Strictness.LENIENT)
34
+ internal class DdLogsTest {
35
+
36
+ lateinit var testedLogs: DdLogs
37
+
38
+ @Mock
39
+ lateinit var mockLogger: Logger
40
+
41
+ @StringForgery
42
+ lateinit var fakeMessage: String
43
+
44
+ @Mock
45
+ lateinit var mockPromise: Promise
46
+
47
+ @Mock
48
+ lateinit var mockReactContext: ReactApplicationContext
49
+
50
+ @MapForgery(
51
+ key = AdvancedForgery(string = [StringForgery()]),
52
+ value = AdvancedForgery(string = [StringForgery(StringForgeryType.HEXADECIMAL)])
53
+ )
54
+ lateinit var fakeContext: Map<String, String>
55
+
56
+ @Mock
57
+ lateinit var mockContext: ReadableMap
58
+
59
+ @MapForgery(
60
+ key = AdvancedForgery(string = [StringForgery()]),
61
+ value = AdvancedForgery(string = [StringForgery(StringForgeryType.HEXADECIMAL)])
62
+ )
63
+ lateinit var fakeGlobalState: Map<String, String>
64
+
65
+ @BeforeEach
66
+ fun `set up`() {
67
+ testedLogs = DdLogs(mockReactContext, mockLogger)
68
+ }
69
+
70
+ @AfterEach
71
+ fun `tear down`() {
72
+ GlobalState.globalAttributes.clear()
73
+ }
74
+
75
+ @Test
76
+ fun `M forward debug log W debug()`() {
77
+ // When
78
+ testedLogs.debug(fakeMessage, mockContext, mockPromise)
79
+
80
+ // Then
81
+ verify(mockLogger).d(fakeMessage, attributes = mockContext.toHashMap())
82
+ }
83
+
84
+ @Test
85
+ fun `M forward info log W info()`() {
86
+ // When
87
+ testedLogs.info(fakeMessage, mockContext, mockPromise)
88
+
89
+ // Then
90
+ verify(mockLogger).i(fakeMessage, attributes = mockContext.toHashMap())
91
+ }
92
+
93
+ @Test
94
+ fun `M forward warning log W warn()`() {
95
+ // When
96
+ testedLogs.warn(fakeMessage, mockContext, mockPromise)
97
+
98
+ // Then
99
+ verify(mockLogger).w(fakeMessage, attributes = mockContext.toHashMap())
100
+ }
101
+
102
+ @Test
103
+ fun `M forward error log W error()`() {
104
+ // When
105
+ testedLogs.error(fakeMessage, mockContext, mockPromise)
106
+
107
+ // Then
108
+ verify(mockLogger).e(fakeMessage, attributes = mockContext.toHashMap())
109
+ }
110
+
111
+ @Test
112
+ fun `M forward debug log with global state W debug()`() {
113
+ // Given
114
+ fakeGlobalState.forEach { (k, v) ->
115
+ GlobalState.globalAttributes[k] = v
116
+ }
117
+ val expectedAttributes = mockContext.toHashMap() + fakeGlobalState
118
+
119
+ // When
120
+ testedLogs.debug(fakeMessage, mockContext, mockPromise)
121
+
122
+ // Then
123
+ verify(mockLogger).d(fakeMessage, attributes = expectedAttributes)
124
+ }
125
+
126
+ @Test
127
+ fun `M forward info log with global state W info()`() {
128
+ // Given
129
+ fakeGlobalState.forEach { (k, v) ->
130
+ GlobalState.globalAttributes[k] = v
131
+ }
132
+ val expectedAttributes = mockContext.toHashMap() + fakeGlobalState
133
+
134
+ // When
135
+ testedLogs.info(fakeMessage, mockContext, mockPromise)
136
+
137
+ // Then
138
+ verify(mockLogger).i(fakeMessage, attributes = expectedAttributes)
139
+ }
140
+
141
+ @Test
142
+ fun `M forward warning log with global state W warn()`() {
143
+ // Given
144
+ fakeGlobalState.forEach { (k, v) ->
145
+ GlobalState.globalAttributes[k] = v
146
+ }
147
+ val expectedAttributes = mockContext.toHashMap() + fakeGlobalState
148
+
149
+ // When
150
+ testedLogs.warn(fakeMessage, mockContext, mockPromise)
151
+
152
+ // Then
153
+ verify(mockLogger).w(fakeMessage, attributes = expectedAttributes)
154
+ }
155
+
156
+ @Test
157
+ fun `M forward error log with global state W error()`() {
158
+ // Given
159
+ fakeGlobalState.forEach { (k, v) ->
160
+ GlobalState.globalAttributes[k] = v
161
+ }
162
+ val expectedAttributes = mockContext.toHashMap() + fakeGlobalState
163
+
164
+ // When
165
+ testedLogs.error(fakeMessage, mockContext, mockPromise)
166
+
167
+ // Then
168
+ verify(mockLogger).e(fakeMessage, attributes = expectedAttributes)
169
+ }
170
+ }
@@ -0,0 +1,408 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ package com.datadog.reactnative
8
+
9
+ import com.datadog.android.rum.GlobalRum
10
+ import com.datadog.android.rum.RumActionType
11
+ import com.datadog.android.rum.RumAttributes
12
+ import com.datadog.android.rum.RumErrorSource
13
+ import com.datadog.android.rum.RumMonitor
14
+ import com.datadog.android.rum.RumResourceKind
15
+ import com.datadog.tools.unit.forge.BaseConfigurator
16
+ import com.datadog.tools.unit.getStaticValue
17
+ import com.datadog.tools.unit.setStaticValue
18
+ import com.datadog.tools.unit.toReadableMap
19
+ import com.facebook.react.bridge.Promise
20
+ import com.facebook.react.bridge.ReactApplicationContext
21
+ import com.nhaarman.mockitokotlin2.mock
22
+ import com.nhaarman.mockitokotlin2.verify
23
+ import fr.xgouchet.elmyr.Forge
24
+ import fr.xgouchet.elmyr.annotation.DoubleForgery
25
+ import fr.xgouchet.elmyr.annotation.Forgery
26
+ import fr.xgouchet.elmyr.annotation.IntForgery
27
+ import fr.xgouchet.elmyr.annotation.LongForgery
28
+ import fr.xgouchet.elmyr.annotation.StringForgery
29
+ import fr.xgouchet.elmyr.annotation.StringForgeryType
30
+ import fr.xgouchet.elmyr.junit5.ForgeConfiguration
31
+ import fr.xgouchet.elmyr.junit5.ForgeExtension
32
+ import java.util.Date
33
+ import java.util.concurrent.atomic.AtomicBoolean
34
+ import org.junit.jupiter.api.AfterEach
35
+ import org.junit.jupiter.api.BeforeEach
36
+ import org.junit.jupiter.api.Test
37
+ import org.junit.jupiter.api.extension.ExtendWith
38
+ import org.junit.jupiter.api.extension.Extensions
39
+ import org.mockito.Mock
40
+ import org.mockito.junit.jupiter.MockitoExtension
41
+ import org.mockito.junit.jupiter.MockitoSettings
42
+ import org.mockito.quality.Strictness
43
+
44
+ @Extensions(
45
+ ExtendWith(MockitoExtension::class),
46
+ ExtendWith(ForgeExtension::class)
47
+ )
48
+ @MockitoSettings(strictness = Strictness.LENIENT)
49
+ @ForgeConfiguration(BaseConfigurator::class)
50
+ internal class DdRumTest {
51
+
52
+ // TODO: 14/12/2020 RUMM-925 Add the relevant unit tests after merging the feature/bridge branch
53
+
54
+ lateinit var testedDdRum: DdRum
55
+
56
+ @Mock
57
+ lateinit var mockRumMonitor: RumMonitor
58
+
59
+ @Mock
60
+ lateinit var mockReactContext: ReactApplicationContext
61
+
62
+ @Mock
63
+ lateinit var mockPromise: Promise
64
+
65
+ lateinit var fakeContext: Map<String, Any?>
66
+
67
+ @DoubleForgery(1000000000000.0, 2000000000000.0)
68
+ var fakeTimestamp: Double = 0.0
69
+
70
+ @BeforeEach
71
+ fun `set up`(forge: Forge) {
72
+ GlobalRum.registerIfAbsent(mockRumMonitor)
73
+
74
+ fakeContext = forge.aMap {
75
+ anAlphabeticalString() to aNullable {
76
+ anElementFrom(
77
+ anHexadecimalString(),
78
+ anInt(),
79
+ aLong(),
80
+ getForgery<Date>(),
81
+ getForgery<Throwable>()
82
+ )
83
+ }
84
+ }
85
+
86
+ testedDdRum = DdRum(mockReactContext)
87
+ }
88
+
89
+ @AfterEach
90
+ fun `tear down`() {
91
+ GlobalRum.javaClass.setStaticValue("monitor", mock<RumMonitor>())
92
+ GlobalRum.javaClass.getStaticValue<GlobalRum, AtomicBoolean>("isRegistered").set(false)
93
+ }
94
+
95
+ @Test
96
+ fun `M call startView W startView()`(
97
+ @StringForgery key: String,
98
+ @StringForgery name: String
99
+ ) {
100
+ // Given
101
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
102
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
103
+ }
104
+
105
+ // When
106
+ testedDdRum.startView(key, name, fakeContext.toReadableMap(), fakeTimestamp, mockPromise)
107
+
108
+ // Then
109
+ verify(mockRumMonitor).startView(key, name, updatedContext)
110
+ }
111
+
112
+ @Test
113
+ fun `M call stopView W stopView()`(
114
+ @StringForgery key: String
115
+ ) {
116
+ // Given
117
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
118
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
119
+ }
120
+
121
+ // When
122
+ testedDdRum.stopView(key, fakeContext.toReadableMap(), fakeTimestamp, mockPromise)
123
+
124
+ // Then
125
+ verify(mockRumMonitor).stopView(key, updatedContext)
126
+ }
127
+
128
+ @Test
129
+ fun `M call addAction W addAction()`(
130
+ @StringForgery name: String,
131
+ @Forgery type: RumActionType
132
+ ) {
133
+ // Given
134
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
135
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
136
+ }
137
+
138
+ // When
139
+ testedDdRum.addAction(
140
+ type.name, name, fakeContext.toReadableMap(),
141
+ fakeTimestamp, mockPromise
142
+ )
143
+
144
+ // Then
145
+ verify(mockRumMonitor).addUserAction(type, name, updatedContext)
146
+ }
147
+
148
+ @Test
149
+ fun `M call addAction W addAction() with invalid type`(
150
+ @StringForgery name: String,
151
+ @StringForgery(StringForgeryType.HEXADECIMAL) type: String
152
+ ) {
153
+ // Given
154
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
155
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
156
+ }
157
+
158
+ // When
159
+ testedDdRum.addAction(type, name, fakeContext.toReadableMap(), fakeTimestamp, mockPromise)
160
+
161
+ // Then
162
+ verify(mockRumMonitor).addUserAction(RumActionType.CUSTOM, name, updatedContext)
163
+ }
164
+
165
+ @Test
166
+ fun `M call startAction W startAction()`(
167
+ @Forgery type: RumActionType,
168
+ @StringForgery name: String
169
+ ) {
170
+ // Given
171
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
172
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
173
+ }
174
+
175
+ // When
176
+ testedDdRum.startAction(
177
+ type.name, name, fakeContext.toReadableMap(),
178
+ fakeTimestamp, mockPromise
179
+ )
180
+
181
+ // Then
182
+ verify(mockRumMonitor).startUserAction(type, name, updatedContext)
183
+ }
184
+
185
+ @Test
186
+ fun `M call startAction W startAction() with invalid type`(
187
+ @StringForgery name: String,
188
+ @StringForgery(StringForgeryType.HEXADECIMAL) type: String
189
+ ) {
190
+ // Given
191
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
192
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
193
+ }
194
+
195
+ // When
196
+ testedDdRum.startAction(type, name, fakeContext.toReadableMap(), fakeTimestamp, mockPromise)
197
+
198
+ // Then
199
+ verify(mockRumMonitor).startUserAction(RumActionType.CUSTOM, name, updatedContext)
200
+ }
201
+
202
+ @Test
203
+ fun `M call stopAction W stopAction()`(
204
+ @Forgery type: RumActionType,
205
+ @StringForgery name: String
206
+ ) {
207
+ // Given
208
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
209
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
210
+ }
211
+
212
+ // When
213
+ testedDdRum.stopAction(
214
+ type.name, name, fakeContext.toReadableMap(),
215
+ fakeTimestamp, mockPromise
216
+ )
217
+
218
+ // Then
219
+ verify(mockRumMonitor).stopUserAction(type, name, updatedContext)
220
+ }
221
+
222
+ @Test
223
+ fun `M call stopAction W stopAction() with invalid type`(
224
+ @StringForgery name: String,
225
+ @StringForgery(StringForgeryType.HEXADECIMAL) type: String
226
+ ) {
227
+ // Given
228
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
229
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
230
+ }
231
+
232
+ // When
233
+ testedDdRum.stopAction(type, name, fakeContext.toReadableMap(), fakeTimestamp, mockPromise)
234
+
235
+ // Then
236
+ verify(mockRumMonitor).stopUserAction(RumActionType.CUSTOM, name, updatedContext)
237
+ }
238
+
239
+ @Test
240
+ fun `M call startResource W startResource()`(
241
+ @StringForgery key: String,
242
+ @StringForgery(regex = "GET|POST|DELETE") method: String,
243
+ @StringForgery(regex = "http(s?)://[a-z]+\\.com/\\w+") url: String
244
+ ) {
245
+ // Given
246
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
247
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
248
+ }
249
+
250
+ // When
251
+ testedDdRum.startResource(
252
+ key, method, url, fakeContext.toReadableMap(),
253
+ fakeTimestamp, mockPromise
254
+ )
255
+
256
+ // Then
257
+ verify(mockRumMonitor).startResource(key, method, url, updatedContext)
258
+ }
259
+
260
+ @Test
261
+ fun `M call stopResource W stopResource()`(
262
+ @StringForgery key: String,
263
+ @IntForgery(200, 600) statusCode: Int,
264
+ @DoubleForgery(min = 0.0) resourceSize: Double,
265
+ @Forgery kind: RumResourceKind
266
+ ) {
267
+ // Given
268
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
269
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
270
+ }
271
+
272
+ // When
273
+ testedDdRum.stopResource(
274
+ key,
275
+ statusCode.toDouble(),
276
+ kind.toString(),
277
+ resourceSize,
278
+ fakeContext.toReadableMap(),
279
+ fakeTimestamp,
280
+ mockPromise
281
+ )
282
+
283
+ // Then
284
+ verify(mockRumMonitor).stopResource(key, statusCode, resourceSize.toLong(), kind, updatedContext)
285
+ }
286
+
287
+ @Test
288
+ fun `M call stopResource W stopResource() with invalid kind`(
289
+ @StringForgery key: String,
290
+ @IntForgery(200, 600) statusCode: Int,
291
+ @DoubleForgery(min = 0.0) resourceSize: Double,
292
+ @StringForgery(StringForgeryType.HEXADECIMAL) kind: String
293
+ ) {
294
+ // Given
295
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
296
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
297
+ }
298
+
299
+ // When
300
+ testedDdRum.stopResource(
301
+ key,
302
+ statusCode.toDouble(),
303
+ kind,
304
+ resourceSize,
305
+ fakeContext.toReadableMap(),
306
+ fakeTimestamp,
307
+ mockPromise
308
+ )
309
+
310
+ // Then
311
+ verify(mockRumMonitor).stopResource(
312
+ key,
313
+ statusCode,
314
+ resourceSize.toLong(),
315
+ RumResourceKind.UNKNOWN,
316
+ updatedContext
317
+ )
318
+ }
319
+
320
+ @Test
321
+ fun `M call stopResource W stopResource() with missing resource size`(
322
+ @StringForgery key: String,
323
+ @IntForgery(200, 600) statusCode: Int,
324
+ @StringForgery(StringForgeryType.HEXADECIMAL) kind: String
325
+ ) {
326
+ // Given
327
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
328
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
329
+ }
330
+
331
+ // When
332
+ testedDdRum.stopResource(
333
+ key,
334
+ statusCode.toDouble(),
335
+ kind,
336
+ -1.0,
337
+ fakeContext.toReadableMap(),
338
+ fakeTimestamp,
339
+ mockPromise
340
+ )
341
+
342
+ // Then
343
+ verify(mockRumMonitor).stopResource(
344
+ key,
345
+ statusCode,
346
+ null,
347
+ RumResourceKind.UNKNOWN,
348
+ updatedContext
349
+ )
350
+ }
351
+
352
+ @Test
353
+ fun `M call addError W addError()`(
354
+ @StringForgery message: String,
355
+ @Forgery source: RumErrorSource,
356
+ @StringForgery stackTrace: String
357
+ ) {
358
+ // Given
359
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
360
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
361
+ }
362
+
363
+ // When
364
+ testedDdRum.addError(
365
+ message, source.name, stackTrace, fakeContext.toReadableMap(),
366
+ fakeTimestamp, mockPromise
367
+ )
368
+
369
+ // Then
370
+ verify(mockRumMonitor).addErrorWithStacktrace(message, source, stackTrace, updatedContext)
371
+ }
372
+
373
+ @Test
374
+ fun `M call addError W addError() with invalid source`(
375
+ @StringForgery message: String,
376
+ @StringForgery(StringForgeryType.HEXADECIMAL) source: String,
377
+ @StringForgery stackTrace: String
378
+ ) {
379
+ // Given
380
+ val updatedContext = fakeContext.toReadableMap().toHashMap().toMutableMap().apply {
381
+ put(RumAttributes.INTERNAL_TIMESTAMP, fakeTimestamp.toLong())
382
+ }
383
+
384
+ // When
385
+ testedDdRum.addError(
386
+ message, source, stackTrace, fakeContext.toReadableMap(),
387
+ fakeTimestamp, mockPromise
388
+ )
389
+
390
+ // Then
391
+ verify(mockRumMonitor).addErrorWithStacktrace(
392
+ message,
393
+ RumErrorSource.SOURCE,
394
+ stackTrace,
395
+ updatedContext
396
+ )
397
+ }
398
+
399
+ @Test
400
+ fun `M call addTiming W addTiming()`(@StringForgery timing: String) {
401
+
402
+ // When
403
+ testedDdRum.addTiming(timing, mockPromise)
404
+
405
+ // Then
406
+ verify(mockRumMonitor).addTiming(timing)
407
+ }
408
+ }