@snowplow/react-native-tracker 1.3.0 → 2.0.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 (240) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintignore +6 -0
  3. package/.gitattributes +3 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. package/.github/actions/setup/action.yml +28 -0
  7. package/.github/workflows/build.yml +150 -0
  8. package/.github/workflows/deploy.yml +98 -0
  9. package/.github/workflows/e2e-android.yml +121 -0
  10. package/.github/workflows/e2e-ios.yml +90 -0
  11. package/.github/workflows/snyk.yml +21 -0
  12. package/.gitignore +70 -0
  13. package/.npmignore +60 -0
  14. package/.nvmrc +1 -0
  15. package/.watchmanconfig +1 -0
  16. package/.yarnrc +3 -0
  17. package/CHANGELOG +166 -0
  18. package/CONTRIBUTING.md +80 -0
  19. package/LICENSE +1 -1
  20. package/README.md +24 -111
  21. package/android/build.gradle +93 -37
  22. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  23. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  24. package/android/gradle.properties +5 -2
  25. package/android/gradlew +172 -110
  26. package/android/gradlew.bat +24 -19
  27. package/android/src/main/AndroidManifest.xml +1 -3
  28. package/android/src/main/AndroidManifestNew.xml +2 -0
  29. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +704 -0
  30. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerPackage.kt +17 -0
  31. package/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +271 -0
  32. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +213 -0
  33. package/android/src/main/java/com/snowplow/reactnativetracker/util/TrackerVersion.kt +5 -0
  34. package/babel.config.js +3 -0
  35. package/example/.watchmanconfig +1 -0
  36. package/example/Gemfile +6 -0
  37. package/example/android/app/build.gradle +129 -0
  38. package/example/android/app/debug.keystore +0 -0
  39. package/example/android/app/proguard-rules.pro +10 -0
  40. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTest.java +36 -0
  41. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTestAppJUnitRunner.java +21 -0
  42. package/example/android/app/src/debug/AndroidManifest.xml +13 -0
  43. package/example/android/app/src/debug/java/com/reactnativetrackerexample/ReactNativeFlipper.java +75 -0
  44. package/example/android/app/src/main/AndroidManifest.xml +26 -0
  45. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainActivity.java +32 -0
  46. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainApplication.java +62 -0
  47. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  48. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  49. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  50. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  51. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  52. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  54. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  55. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  56. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  57. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  58. package/example/android/app/src/main/res/values/strings.xml +3 -0
  59. package/example/android/app/src/main/res/values/styles.xml +9 -0
  60. package/example/android/app/src/release/java/com/reactnativetrackerexample/ReactNativeFlipper.java +20 -0
  61. package/example/android/build.gradle +31 -0
  62. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  63. package/example/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  64. package/example/android/gradle.properties +44 -0
  65. package/example/android/gradlew +244 -0
  66. package/example/android/gradlew.bat +92 -0
  67. package/example/android/settings.gradle +4 -0
  68. package/example/app.json +4 -0
  69. package/example/babel.config.js +17 -0
  70. package/example/detox.config.js +92 -0
  71. package/example/e2e/config.json +10 -0
  72. package/example/e2e/emitEvents.e2e.detox.js +108 -0
  73. package/example/e2e/environment.js +23 -0
  74. package/example/e2e/helpers/microCommands.js +153 -0
  75. package/example/e2e/helpers/microHelpers.js +346 -0
  76. package/example/e2e/helpers/microHelpers.test.js +308 -0
  77. package/example/e2e/helpers/schemas.js +62 -0
  78. package/example/e2e/jest.config.js +16 -0
  79. package/example/e2e/setup.js +4 -0
  80. package/example/e2e/testEvents.micro.test.js +300 -0
  81. package/example/index.js +5 -0
  82. package/example/ios/.xcode.env +11 -0
  83. package/example/ios/Podfile +64 -0
  84. package/example/ios/Podfile.lock +737 -0
  85. package/example/ios/ReactNativeTrackerExample/AppDelegate.h +6 -0
  86. package/example/ios/ReactNativeTrackerExample/AppDelegate.mm +26 -0
  87. package/example/ios/ReactNativeTrackerExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  88. package/example/ios/ReactNativeTrackerExample/Images.xcassets/Contents.json +6 -0
  89. package/example/ios/ReactNativeTrackerExample/Info.plist +55 -0
  90. package/example/ios/ReactNativeTrackerExample/LaunchScreen.storyboard +47 -0
  91. package/example/ios/ReactNativeTrackerExample/main.m +10 -0
  92. package/example/ios/ReactNativeTrackerExample-Bridging-Header.h +3 -0
  93. package/example/ios/ReactNativeTrackerExample.xcodeproj/project.pbxproj +722 -0
  94. package/{ios/RNSnowplowTracker.xcodeproj/xcshareddata/xcschemes/RNSnowplowTracker.xcscheme → example/ios/ReactNativeTrackerExample.xcodeproj/xcshareddata/xcschemes/ReactNativeTrackerExample.xcscheme} +29 -21
  95. package/example/ios/ReactNativeTrackerExample.xcworkspace/contents.xcworkspacedata +10 -0
  96. package/example/ios/ReactNativeTrackerExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  97. package/example/ios/ReactNativeTrackerExampleTests/Info.plist +24 -0
  98. package/example/ios/ReactNativeTrackerExampleTests/ReactNativeTrackerExampleTests.m +66 -0
  99. package/example/metro.config.js +45 -0
  100. package/example/package.json +54 -0
  101. package/example/react-native.config.js +10 -0
  102. package/example/src/App.js +557 -0
  103. package/example/tsconfig.json +5 -0
  104. package/example/yarn.lock +7379 -0
  105. package/ios/ReactNativeTracker-Bridging-Header.h +2 -0
  106. package/ios/ReactNativeTracker.mm +165 -0
  107. package/ios/ReactNativeTracker.swift +757 -0
  108. package/ios/{RNSnowplowTracker.xcodeproj → ReactNativeTracker.xcodeproj}/project.pbxproj +55 -79
  109. package/ios/Util/ConfigUtils.swift +206 -0
  110. package/ios/Util/TrackerVersion.swift +3 -0
  111. package/ios/Util/Utilities.swift +37 -0
  112. package/lefthook.yml +11 -0
  113. package/lib/commonjs/api.js +475 -0
  114. package/lib/commonjs/api.js.map +1 -0
  115. package/lib/commonjs/configurations.js +209 -0
  116. package/lib/commonjs/configurations.js.map +1 -0
  117. package/lib/commonjs/constants.js +85 -0
  118. package/lib/commonjs/constants.js.map +1 -0
  119. package/lib/commonjs/events.js +256 -0
  120. package/lib/commonjs/events.js.map +1 -0
  121. package/lib/commonjs/index.js +141 -0
  122. package/lib/commonjs/index.js.map +1 -0
  123. package/lib/commonjs/jsCore.js +393 -0
  124. package/lib/commonjs/jsCore.js.map +1 -0
  125. package/lib/commonjs/native.js +29 -0
  126. package/lib/commonjs/native.js.map +1 -0
  127. package/lib/commonjs/subject.js +248 -0
  128. package/lib/commonjs/subject.js.map +1 -0
  129. package/lib/commonjs/tracker.js +221 -0
  130. package/lib/commonjs/tracker.js.map +1 -0
  131. package/lib/commonjs/types.js +2 -0
  132. package/lib/commonjs/types.js.map +1 -0
  133. package/lib/commonjs/utils.js +85 -0
  134. package/lib/commonjs/utils.js.map +1 -0
  135. package/lib/commonjs/webViewInterface.js +79 -0
  136. package/lib/commonjs/webViewInterface.js.map +1 -0
  137. package/lib/module/api.js +439 -0
  138. package/lib/module/api.js.map +1 -0
  139. package/lib/module/configurations.js +197 -0
  140. package/lib/module/configurations.js.map +1 -0
  141. package/lib/module/constants.js +80 -0
  142. package/lib/module/constants.js.map +1 -0
  143. package/lib/module/events.js +240 -0
  144. package/lib/module/events.js.map +1 -0
  145. package/lib/module/index.js +129 -0
  146. package/lib/module/index.js.map +1 -0
  147. package/lib/module/jsCore.js +390 -0
  148. package/lib/module/jsCore.js.map +1 -0
  149. package/lib/module/native.js +25 -0
  150. package/lib/module/native.js.map +1 -0
  151. package/lib/module/subject.js +235 -0
  152. package/lib/module/subject.js.map +1 -0
  153. package/lib/module/tracker.js +209 -0
  154. package/lib/module/tracker.js.map +1 -0
  155. package/lib/module/types.js +2 -0
  156. package/lib/module/types.js.map +1 -0
  157. package/lib/module/utils.js +79 -0
  158. package/lib/module/utils.js.map +1 -0
  159. package/lib/module/webViewInterface.js +75 -0
  160. package/lib/module/webViewInterface.js.map +1 -0
  161. package/lib/typescript/__tests__/api.test.d.ts +2 -0
  162. package/lib/typescript/__tests__/api.test.d.ts.map +1 -0
  163. package/lib/typescript/__tests__/configurations.test.d.ts +2 -0
  164. package/lib/typescript/__tests__/configurations.test.d.ts.map +1 -0
  165. package/lib/typescript/__tests__/events.test.d.ts +2 -0
  166. package/lib/typescript/__tests__/events.test.d.ts.map +1 -0
  167. package/lib/typescript/__tests__/index.test.d.ts +2 -0
  168. package/lib/typescript/__tests__/index.test.d.ts.map +1 -0
  169. package/lib/typescript/__tests__/jsCore.test.d.ts +2 -0
  170. package/lib/typescript/__tests__/jsCore.test.d.ts.map +1 -0
  171. package/lib/typescript/__tests__/utils.test.d.ts +2 -0
  172. package/lib/typescript/__tests__/utils.test.d.ts.map +1 -0
  173. package/lib/typescript/api.d.ts +226 -0
  174. package/lib/typescript/api.d.ts.map +1 -0
  175. package/lib/typescript/configurations.d.ts +73 -0
  176. package/lib/typescript/configurations.d.ts.map +1 -0
  177. package/lib/typescript/constants.d.ts +59 -0
  178. package/lib/typescript/constants.d.ts.map +1 -0
  179. package/lib/typescript/events.d.ts +101 -0
  180. package/lib/typescript/events.d.ts.map +1 -0
  181. package/lib/typescript/index.d.ts +27 -0
  182. package/lib/typescript/index.d.ts.map +1 -0
  183. package/lib/typescript/jsCore.d.ts +140 -0
  184. package/lib/typescript/jsCore.d.ts.map +1 -0
  185. package/lib/typescript/native.d.ts +4 -0
  186. package/lib/typescript/native.d.ts.map +1 -0
  187. package/lib/typescript/subject.d.ts +91 -0
  188. package/lib/typescript/subject.d.ts.map +1 -0
  189. package/lib/typescript/tracker.d.ts +93 -0
  190. package/lib/typescript/tracker.d.ts.map +1 -0
  191. package/{dist/index.d.ts → lib/typescript/types.d.ts} +188 -75
  192. package/lib/typescript/types.d.ts.map +1 -0
  193. package/lib/typescript/utils.d.ts +35 -0
  194. package/lib/typescript/utils.d.ts.map +1 -0
  195. package/lib/typescript/webViewInterface.d.ts +15 -0
  196. package/lib/typescript/webViewInterface.d.ts.map +1 -0
  197. package/package.json +138 -51
  198. package/scripts/bootstrap.js +29 -0
  199. package/snowplow-react-native-tracker.podspec +42 -0
  200. package/src/__mocks__/react-native.js +7 -0
  201. package/src/__tests__/api.test.ts +34 -0
  202. package/src/__tests__/configurations.test.ts +620 -0
  203. package/src/__tests__/events.test.ts +749 -0
  204. package/src/__tests__/index.test.ts +27 -0
  205. package/src/__tests__/jsCore.test.ts +169 -0
  206. package/src/__tests__/utils.test.ts +23 -0
  207. package/src/api.ts +535 -0
  208. package/src/configurations.ts +337 -0
  209. package/src/constants.ts +102 -0
  210. package/src/events.ts +330 -0
  211. package/src/index.ts +189 -0
  212. package/src/jsCore.ts +553 -0
  213. package/src/native.ts +34 -0
  214. package/src/subject.ts +315 -0
  215. package/src/tracker.ts +330 -0
  216. package/src/types.ts +1087 -0
  217. package/src/utils.ts +78 -0
  218. package/src/webViewInterface.ts +105 -0
  219. package/tsconfig.build.json +5 -0
  220. package/tsconfig.json +28 -0
  221. package/turbo.json +34 -0
  222. package/yarn.lock +9333 -0
  223. package/RNSnowplowTracker.podspec +0 -24
  224. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java +0 -750
  225. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerPackage.java +0 -29
  226. package/android/src/main/java/com/snowplowanalytics/react/util/ConfigUtil.java +0 -351
  227. package/android/src/main/java/com/snowplowanalytics/react/util/EventUtil.java +0 -339
  228. package/android/src/main/java/com/snowplowanalytics/react/util/TrackerVersion.java +0 -7
  229. package/dist/index.js +0 -1650
  230. package/dist/index.js.map +0 -1
  231. package/ios/RNSnowplowTracker.h +0 -34
  232. package/ios/RNSnowplowTracker.m +0 -911
  233. package/ios/Util/NSDictionary+RNSP_TypeMethods.h +0 -33
  234. package/ios/Util/NSDictionary+RNSP_TypeMethods.m +0 -40
  235. package/ios/Util/RNConfigUtils.h +0 -44
  236. package/ios/Util/RNConfigUtils.m +0 -209
  237. package/ios/Util/RNTrackerVersion.h +0 -27
  238. package/ios/Util/RNTrackerVersion.m +0 -27
  239. package/ios/Util/RNUtilities.h +0 -32
  240. package/ios/Util/RNUtilities.m +0 -68
@@ -0,0 +1,620 @@
1
+ /*
2
+ * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
+ *
4
+ * This program is licensed to you under the Apache License Version 2.0,
5
+ * and you may not use this file except in compliance with the Apache License Version 2.0.
6
+ * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
+ *
8
+ * Unless required by applicable law or agreed to in writing,
9
+ * software distributed under the Apache License Version 2.0 is distributed on an
10
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
+ */
13
+
14
+ import * as c from '../configurations';
15
+ import { logMessages } from '../constants';
16
+
17
+ /**
18
+ * initValidate
19
+ */
20
+ describe('test initValidate rejects', () => {
21
+ test('test missing namespace', async () => {
22
+ const testConfig = {
23
+ networkConfig: { endpoint: 'test' },
24
+ };
25
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
26
+ logMessages.namespace
27
+ );
28
+ });
29
+
30
+ test('test invalid namespace', async () => {
31
+ const testConfig = {
32
+ namespace: '',
33
+ networkConfig: { endpoint: 'test' },
34
+ };
35
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
36
+ logMessages.namespace
37
+ );
38
+ });
39
+
40
+ test('test missing endpoint', async () => {
41
+ const testConfig = {
42
+ namespace: 'sp1',
43
+ networkConfig: { method: 'get' },
44
+ };
45
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
46
+ logMessages.network
47
+ );
48
+ });
49
+
50
+ test('test invalid endpoint', async () => {
51
+ const testConfig = {
52
+ namespace: 'sp1',
53
+ networkConfig: { endpoint: '', method: 'get' },
54
+ };
55
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
56
+ logMessages.network
57
+ );
58
+ });
59
+
60
+ test('test invalid networkConfig', async () => {
61
+ const testConfig = {
62
+ namespace: 'sp1',
63
+ networkConfig: { endpoint: 'test', invalid: true },
64
+ };
65
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
66
+ logMessages.network
67
+ );
68
+ });
69
+
70
+ test('test invalid trackerConfig', async () => {
71
+ const testConfig = {
72
+ namespace: 'sp1',
73
+ networkConfig: { endpoint: 'test' },
74
+ trackerConfig: { invalid: true },
75
+ };
76
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
77
+ logMessages.tracker
78
+ );
79
+ });
80
+
81
+ test('test invalid sessionConfig', async () => {
82
+ const testConfig = {
83
+ namespace: 'sp1',
84
+ networkConfig: { endpoint: 'test' },
85
+ sessionConfig: { invalid: true },
86
+ };
87
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
88
+ logMessages.session
89
+ );
90
+ });
91
+
92
+ test('test invalid emitterConfig', async () => {
93
+ const testConfig = {
94
+ namespace: 'sp1',
95
+ networkConfig: { endpoint: 'test' },
96
+ emitterConfig: { invalid: true },
97
+ };
98
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
99
+ logMessages.emitter
100
+ );
101
+ });
102
+
103
+ test('test invalid subjectConfig', async () => {
104
+ const testConfig = {
105
+ namespace: 'sp1',
106
+ networkConfig: { endpoint: 'test' },
107
+ subjectConfig: { userId: 'tester', invalid: true },
108
+ };
109
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
110
+ logMessages.subject
111
+ );
112
+ });
113
+
114
+ test('test invalid gdprConfig - extra', async () => {
115
+ const testConfig = {
116
+ namespace: 'sp1',
117
+ networkConfig: { endpoint: 'test' },
118
+ gdprConfig: {
119
+ basisForProcessing: 'consent',
120
+ documentId: '12345',
121
+ documentVersion: '1.0.0',
122
+ documentDescription: 'gdpr document description',
123
+ invalid: true,
124
+ },
125
+ };
126
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
127
+ logMessages.gdpr
128
+ );
129
+ });
130
+
131
+ test('test invalid gdprConfig - missing', async () => {
132
+ const testConfig = {
133
+ namespace: 'sp1',
134
+ networkConfig: { endpoint: 'test' },
135
+ gdprConfig: {
136
+ basisForProcessing: 'consent',
137
+ documentId: '12345',
138
+ documentVersion: '1.0.0',
139
+ },
140
+ };
141
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
142
+ logMessages.gdpr
143
+ );
144
+ });
145
+
146
+ test('test invalid gdprConfig - basis', async () => {
147
+ const testConfig = {
148
+ namespace: 'sp1',
149
+ networkConfig: { endpoint: 'test' },
150
+ gdprConfig: {
151
+ basisForProcessing: 'invalid',
152
+ documentId: '12345',
153
+ documentVersion: '1.0.0',
154
+ documentDescription: 'gdpr document description',
155
+ },
156
+ };
157
+ await expect(c.initValidate(testConfig as any)).rejects.toThrow(
158
+ logMessages.gdpr
159
+ );
160
+ });
161
+ });
162
+
163
+ // when initValidate resolves
164
+ describe('test initValidate resolves', () => {
165
+ test('test minimal required', async () => {
166
+ const testConfig = {
167
+ namespace: 'sp1',
168
+ networkConfig: { endpoint: 'test' },
169
+ };
170
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
171
+ });
172
+
173
+ test('test valid networkConfig', async () => {
174
+ const testConfig = {
175
+ namespace: 'sp1',
176
+ networkConfig: {
177
+ endpoint: 'test',
178
+ method: 'get',
179
+ customPostPath: 'custom/path',
180
+ requestHeaders: { the: 'header' },
181
+ },
182
+ };
183
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
184
+ });
185
+
186
+ test('test valid trackerConfig', async () => {
187
+ const testConfig = {
188
+ namespace: 'sp1',
189
+ networkConfig: { endpoint: 'test' },
190
+ trackerConfig: { base64Encoding: false },
191
+ };
192
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
193
+ });
194
+
195
+ test('test valid sessionConfig', async () => {
196
+ const testConfig = {
197
+ namespace: 'sp1',
198
+ networkConfig: { endpoint: 'test' },
199
+ sessionConfig: { foregroundTimeout: 100, backgroundTimeout: 100 },
200
+ };
201
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
202
+ });
203
+
204
+ test('test valid emitterConfig', async () => {
205
+ const testConfig = {
206
+ namespace: 'sp1',
207
+ networkConfig: { endpoint: 'test' },
208
+ emitterConfig: { byteLimitPost: 20000 },
209
+ };
210
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
211
+ });
212
+
213
+ test('test valid subjectConfig', async () => {
214
+ const testConfig = {
215
+ namespace: 'sp1',
216
+ networkConfig: { endpoint: 'test' },
217
+ subjectConfig: { userId: 'tester', language: 'javascript' },
218
+ };
219
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
220
+ });
221
+
222
+ test('test valid gdprConfig', async () => {
223
+ const testConfig = {
224
+ namespace: 'sp1',
225
+ networkConfig: { endpoint: 'test' },
226
+ gdprConfig: {
227
+ basisForProcessing: 'consent',
228
+ documentId: '12345',
229
+ documentVersion: '1.0.0',
230
+ documentDescription: 'gdpr document description',
231
+ },
232
+ };
233
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
234
+ });
235
+
236
+ test('test with all defaults', async () => {
237
+ const testConfig = {
238
+ namespace: 'sp1',
239
+ networkConfig: {
240
+ endpoint: 'test',
241
+ method: 'post',
242
+ customPostPath: 'com.snowplowanalytics.snowplow/tp2',
243
+ },
244
+ trackerConfig: {
245
+ devicePlatform: 'mob',
246
+ base64Encoding: true,
247
+ logLevel: 'off',
248
+ applicationContext: true,
249
+ platformContext: true,
250
+ geoLocationContext: false,
251
+ sessionContext: true,
252
+ deepLinkContext: true,
253
+ screenContext: true,
254
+ screenViewAutotracking: false,
255
+ lifecycleAutotracking: false,
256
+ installAutotracking: true,
257
+ exceptionAutotracking: true,
258
+ diagnosticAutotracking: false,
259
+ userAnonymisation: false,
260
+ },
261
+ sessionConfig: {
262
+ foregroundTimeout: 30,
263
+ backgroundTimeout: 30,
264
+ },
265
+ emitterConfig: {
266
+ bufferOption: 'single',
267
+ emitRange: 150,
268
+ threadPoolSize: 15,
269
+ byteLimitPost: 40000,
270
+ byteLimitGet: 40000,
271
+ serverAnonymisation: false,
272
+ },
273
+ };
274
+ await expect(c.initValidate(testConfig as any)).resolves.toBe(true);
275
+ });
276
+ });
277
+
278
+ describe('test isValidNetworkConf', () => {
279
+ test('invalid - type', () => {
280
+ const testConf = undefined as any;
281
+ expect(c.isValidNetworkConf(testConf)).toBe(false);
282
+ });
283
+
284
+ test('invalid - invalid props', () => {
285
+ const testConf = {
286
+ endpoint: 'test',
287
+ invalid: true,
288
+ } as any;
289
+ expect(c.isValidNetworkConf(testConf)).toBe(false);
290
+ });
291
+
292
+ test('invalid - missing endpoint', () => {
293
+ const testConf = {
294
+ method: 'get',
295
+ } as any;
296
+ expect(c.isValidNetworkConf(testConf)).toBe(false);
297
+ });
298
+
299
+ test('invalid - empty endpoint', () => {
300
+ const testConf = {
301
+ endpoint: '',
302
+ method: 'get',
303
+ } as any;
304
+ expect(c.isValidNetworkConf(testConf)).toBe(false);
305
+ });
306
+
307
+ test('valid', () => {
308
+ const testConf = {
309
+ endpoint: '0.0.0.0:9090',
310
+ method: 'post',
311
+ customPostPath: 'com.snowplowanalytics.snowplow/tp2',
312
+ } as any;
313
+ expect(c.isValidNetworkConf(testConf)).toBe(true);
314
+ });
315
+ });
316
+
317
+ describe('test isValidTrackerConf', () => {
318
+ test('invalid - type', () => {
319
+ const testConf = undefined as any;
320
+ expect(c.isValidTrackerConf(testConf)).toBe(false);
321
+ });
322
+
323
+ test('invalid - invalid props', () => {
324
+ const testConf = {
325
+ appId: 'test',
326
+ invalid: true,
327
+ } as any;
328
+ expect(c.isValidTrackerConf(testConf)).toBe(false);
329
+ });
330
+
331
+ test('valid', () => {
332
+ const testConf = {
333
+ appId: 'test',
334
+ applicationContext: true,
335
+ base64Encoding: true,
336
+ devicePlatform: 'mob',
337
+ diagnosticAutotracking: false,
338
+ exceptionAutotracking: true,
339
+ geoLocationContext: false,
340
+ installAutotracking: true,
341
+ lifecycleAutotracking: false,
342
+ logLevel: 'off',
343
+ platformContext: true,
344
+ screenContext: true,
345
+ screenViewAutotracking: false,
346
+ sessionContext: true,
347
+ deepLinkContext: true,
348
+ userAnonymisation: false,
349
+ } as any;
350
+ expect(c.isValidTrackerConf(testConf)).toBe(true);
351
+ });
352
+ });
353
+
354
+ describe('test isValidSessionConf', () => {
355
+ test('invalid - type', () => {
356
+ const testConf = undefined as any;
357
+ expect(c.isValidSessionConf(testConf)).toBe(false);
358
+ });
359
+
360
+ test('invalid - invalid props', () => {
361
+ const testConf = {
362
+ backgroundTimeout: 30,
363
+ invalid: true,
364
+ } as any;
365
+ expect(c.isValidSessionConf(testConf)).toBe(false);
366
+ });
367
+
368
+ test('invalid - missing props', () => {
369
+ const testConf = {
370
+ backgroundTimeout: 30,
371
+ } as any;
372
+ expect(c.isValidSessionConf(testConf)).toBe(false);
373
+ });
374
+
375
+ test('valid', () => {
376
+ const testConf = {
377
+ foregroundTimeout: 30,
378
+ backgroundTimeout: 30,
379
+ };
380
+ expect(c.isValidSessionConf(testConf)).toBe(true);
381
+ });
382
+ });
383
+
384
+ describe('test isValidEmitterConf', () => {
385
+ test('invalid - type', () => {
386
+ const testConf = undefined as any;
387
+ expect(c.isValidEmitterConf(testConf)).toBe(false);
388
+ });
389
+
390
+ test('invalid - invalid props', () => {
391
+ const testConf = {
392
+ bufferOption: 'default',
393
+ invalid: true,
394
+ } as any;
395
+ expect(c.isValidEmitterConf(testConf)).toBe(false);
396
+ });
397
+
398
+ test('valid', () => {
399
+ const testConf = {
400
+ bufferOption: 'single',
401
+ byteLimitGet: 40000,
402
+ byteLimitPost: 40000,
403
+ emitRange: 150,
404
+ threadPoolSize: 15,
405
+ } as any;
406
+ expect(c.isValidEmitterConf(testConf)).toBe(true);
407
+ });
408
+ });
409
+
410
+ describe('test isScreenSize', () => {
411
+ test('invalid - type', () => {
412
+ const testSize = 'invalid' as any;
413
+ expect(c.isScreenSize(testSize)).toBe(false);
414
+ });
415
+
416
+ test('invalid - array size', () => {
417
+ const testSizeA = [] as any;
418
+ const testSizeB = [0, 1, 2] as any;
419
+ expect(c.isScreenSize(testSizeA)).toBe(false);
420
+ expect(c.isScreenSize(testSizeB)).toBe(false);
421
+ });
422
+
423
+ test('invalid - array elements not numbers', () => {
424
+ const testSize = ['a', 'b'] as any;
425
+ expect(c.isScreenSize(testSize)).toBe(false);
426
+ });
427
+
428
+ test('valid', () => {
429
+ const testSize = [10, 20] as any;
430
+ expect(c.isScreenSize(testSize)).toBe(true);
431
+ });
432
+ });
433
+
434
+ describe('test isValidSubjectConf', () => {
435
+ test('invalid - type', () => {
436
+ const testConf = null as any;
437
+ expect(c.isValidSubjectConf(testConf)).toBe(false);
438
+ });
439
+
440
+ test('invalid - invalid props', () => {
441
+ const testConf = {
442
+ userId: 'tester',
443
+ invalid: true,
444
+ } as any;
445
+ expect(c.isValidSubjectConf(testConf)).toBe(false);
446
+ });
447
+
448
+ test('invalid - invalid screenResolution', () => {
449
+ const testConf = {
450
+ userId: 'tester',
451
+ screenResolution: 10,
452
+ } as any;
453
+ expect(c.isValidSubjectConf(testConf)).toBe(false);
454
+ });
455
+
456
+ test('invalid - invalid screenViewport', () => {
457
+ const testConf = {
458
+ userId: 'tester',
459
+ screenViewport: [10, 20, 30],
460
+ } as any;
461
+ expect(c.isValidSubjectConf(testConf)).toBe(false);
462
+ });
463
+
464
+ test('valid screenViewport and screenResolution', () => {
465
+ const testConf = {
466
+ screenViewport: [10, 20],
467
+ screenResolution: [30, 40],
468
+ } as any;
469
+ expect(c.isValidSubjectConf(testConf)).toBe(true);
470
+ });
471
+
472
+ test('valid', () => {
473
+ const testConf = {
474
+ userId: 'tester',
475
+ networkUserId: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
476
+ domainUserId: '5d79770b-015b-4af8-8c91-b2ed6faf4b1e',
477
+ useragent: 'agent string',
478
+ ipAddress: '0.0.0.0',
479
+ timezone: 'Europe/London',
480
+ language: 'en',
481
+ screenResolution: [123, 456],
482
+ screenViewport: [12, 34],
483
+ colorDepth: 0,
484
+ } as any;
485
+ expect(c.isValidSubjectConf(testConf)).toBe(true);
486
+ });
487
+ });
488
+
489
+ describe('test isValidGdprConf', () => {
490
+ test('invalid - type', () => {
491
+ const testConf = 'invalid' as any;
492
+ expect(c.isValidGdprConf(testConf)).toBe(false);
493
+ });
494
+
495
+ test('invalid prop', () => {
496
+ const testConf = {
497
+ basisForProcessing: 'consent',
498
+ documentId: '12345',
499
+ documentVersion: '1.0.0',
500
+ documentDescription: 'gdpr document description',
501
+ invalid: true,
502
+ } as any;
503
+ expect(c.isValidGdprConf(testConf)).toBe(false);
504
+ });
505
+
506
+ test('invalid prop - invalid basis', () => {
507
+ const testConf = {
508
+ basisForProcessing: 'invalid',
509
+ documentId: '12345',
510
+ documentVersion: '1.0.0',
511
+ documentDescription: 'gdpr document description',
512
+ } as any;
513
+ expect(c.isValidGdprConf(testConf)).toBe(false);
514
+ });
515
+
516
+ test('invalid - missing prop', () => {
517
+ const testConf = {
518
+ basisForProcessing: 'consent',
519
+ documentId: '12345',
520
+ documentVersion: '1.0.0',
521
+ } as any;
522
+ expect(c.isValidGdprConf(testConf)).toBe(false);
523
+ });
524
+
525
+ test('valid', () => {
526
+ const testConf = {
527
+ basisForProcessing: 'consent',
528
+ documentId: '12345',
529
+ documentVersion: '1.0.0',
530
+ documentDescription: 'gdpr document description',
531
+ } as any;
532
+ expect(c.isValidGdprConf(testConf)).toBe(true);
533
+ });
534
+ });
535
+
536
+ describe('test isValidGCConf', () => {
537
+ test('invalid - type', () => {
538
+ const testConf = { tag: 'invalid' } as any;
539
+ expect(c.isValidGCConf(testConf)).toBe(false);
540
+ });
541
+
542
+ test('valid - empty array', () => {
543
+ const testConf = [] as any;
544
+ expect(c.isValidGCConf(testConf)).toBe(true);
545
+ });
546
+
547
+ test('invalid prop - invalid tag', () => {
548
+ const testConf = [
549
+ {
550
+ tag: undefined,
551
+ globalContexts: [
552
+ {
553
+ schema: 'testSchema',
554
+ data: { test: 'data' },
555
+ },
556
+ ],
557
+ },
558
+ ] as any;
559
+ expect(c.isValidGCConf(testConf)).toBe(false);
560
+ });
561
+
562
+ test('invalid prop - invalid globalContexts type', () => {
563
+ const testConf = [
564
+ {
565
+ tag: undefined,
566
+ globalContexts: {
567
+ schema: 'testSchema',
568
+ data: { test: 'data' },
569
+ },
570
+ },
571
+ ] as any;
572
+ expect(c.isValidGCConf(testConf)).toBe(false);
573
+ });
574
+
575
+ test('invalid prop - invalid globalContexts - invalid sdj', () => {
576
+ const testConf = [
577
+ {
578
+ tag: 'testGCTag',
579
+ globalContexts: [
580
+ {
581
+ data: { test: 'data' },
582
+ },
583
+ ],
584
+ },
585
+ ] as any;
586
+ expect(c.isValidGCConf(testConf)).toBe(false);
587
+ });
588
+
589
+ test('valid', () => {
590
+ const testConf = [
591
+ {
592
+ tag: 'testGCTag1',
593
+ globalContexts: [
594
+ {
595
+ schema: 'testSchema0',
596
+ data: { test: 'data' },
597
+ },
598
+ {
599
+ schema: 'testSchema1',
600
+ data: { test: 'data' },
601
+ },
602
+ ],
603
+ },
604
+ {
605
+ tag: 'testGCTag2',
606
+ globalContexts: [
607
+ {
608
+ schema: 'testSchema2',
609
+ data: { test: 'data' },
610
+ },
611
+ {
612
+ schema: 'testSchema3',
613
+ data: { test: 'data' },
614
+ },
615
+ ],
616
+ },
617
+ ] as any;
618
+ expect(c.isValidGCConf(testConf)).toBe(true);
619
+ });
620
+ });