@snowplow/react-native-tracker 1.4.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 (239) 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/README.md +23 -110
  20. package/android/build.gradle +93 -37
  21. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  22. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  23. package/android/gradle.properties +5 -2
  24. package/android/gradlew +172 -110
  25. package/android/gradlew.bat +24 -19
  26. package/android/src/main/AndroidManifest.xml +1 -3
  27. package/android/src/main/AndroidManifestNew.xml +2 -0
  28. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +704 -0
  29. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerPackage.kt +17 -0
  30. package/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +271 -0
  31. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +213 -0
  32. package/android/src/main/java/com/snowplow/reactnativetracker/util/TrackerVersion.kt +5 -0
  33. package/babel.config.js +3 -0
  34. package/example/.watchmanconfig +1 -0
  35. package/example/Gemfile +6 -0
  36. package/example/android/app/build.gradle +129 -0
  37. package/example/android/app/debug.keystore +0 -0
  38. package/example/android/app/proguard-rules.pro +10 -0
  39. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTest.java +36 -0
  40. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTestAppJUnitRunner.java +21 -0
  41. package/example/android/app/src/debug/AndroidManifest.xml +13 -0
  42. package/example/android/app/src/debug/java/com/reactnativetrackerexample/ReactNativeFlipper.java +75 -0
  43. package/example/android/app/src/main/AndroidManifest.xml +26 -0
  44. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainActivity.java +32 -0
  45. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainApplication.java +62 -0
  46. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  47. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  48. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  49. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  50. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  51. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  52. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  54. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  55. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  56. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  57. package/example/android/app/src/main/res/values/strings.xml +3 -0
  58. package/example/android/app/src/main/res/values/styles.xml +9 -0
  59. package/example/android/app/src/release/java/com/reactnativetrackerexample/ReactNativeFlipper.java +20 -0
  60. package/example/android/build.gradle +31 -0
  61. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  62. package/example/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  63. package/example/android/gradle.properties +44 -0
  64. package/example/android/gradlew +244 -0
  65. package/example/android/gradlew.bat +92 -0
  66. package/example/android/settings.gradle +4 -0
  67. package/example/app.json +4 -0
  68. package/example/babel.config.js +17 -0
  69. package/example/detox.config.js +92 -0
  70. package/example/e2e/config.json +10 -0
  71. package/example/e2e/emitEvents.e2e.detox.js +108 -0
  72. package/example/e2e/environment.js +23 -0
  73. package/example/e2e/helpers/microCommands.js +153 -0
  74. package/example/e2e/helpers/microHelpers.js +346 -0
  75. package/example/e2e/helpers/microHelpers.test.js +308 -0
  76. package/example/e2e/helpers/schemas.js +62 -0
  77. package/example/e2e/jest.config.js +16 -0
  78. package/example/e2e/setup.js +4 -0
  79. package/example/e2e/testEvents.micro.test.js +300 -0
  80. package/example/index.js +5 -0
  81. package/example/ios/.xcode.env +11 -0
  82. package/example/ios/Podfile +64 -0
  83. package/example/ios/Podfile.lock +737 -0
  84. package/example/ios/ReactNativeTrackerExample/AppDelegate.h +6 -0
  85. package/example/ios/ReactNativeTrackerExample/AppDelegate.mm +26 -0
  86. package/example/ios/ReactNativeTrackerExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  87. package/example/ios/ReactNativeTrackerExample/Images.xcassets/Contents.json +6 -0
  88. package/example/ios/ReactNativeTrackerExample/Info.plist +55 -0
  89. package/example/ios/ReactNativeTrackerExample/LaunchScreen.storyboard +47 -0
  90. package/example/ios/ReactNativeTrackerExample/main.m +10 -0
  91. package/example/ios/ReactNativeTrackerExample-Bridging-Header.h +3 -0
  92. package/example/ios/ReactNativeTrackerExample.xcodeproj/project.pbxproj +722 -0
  93. package/{ios/RNSnowplowTracker.xcodeproj/xcshareddata/xcschemes/RNSnowplowTracker.xcscheme → example/ios/ReactNativeTrackerExample.xcodeproj/xcshareddata/xcschemes/ReactNativeTrackerExample.xcscheme} +29 -21
  94. package/example/ios/ReactNativeTrackerExample.xcworkspace/contents.xcworkspacedata +10 -0
  95. package/example/ios/ReactNativeTrackerExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  96. package/example/ios/ReactNativeTrackerExampleTests/Info.plist +24 -0
  97. package/example/ios/ReactNativeTrackerExampleTests/ReactNativeTrackerExampleTests.m +66 -0
  98. package/example/metro.config.js +45 -0
  99. package/example/package.json +54 -0
  100. package/example/react-native.config.js +10 -0
  101. package/example/src/App.js +557 -0
  102. package/example/tsconfig.json +5 -0
  103. package/example/yarn.lock +7379 -0
  104. package/ios/ReactNativeTracker-Bridging-Header.h +2 -0
  105. package/ios/ReactNativeTracker.mm +165 -0
  106. package/ios/ReactNativeTracker.swift +757 -0
  107. package/ios/{RNSnowplowTracker.xcodeproj → ReactNativeTracker.xcodeproj}/project.pbxproj +55 -79
  108. package/ios/Util/ConfigUtils.swift +206 -0
  109. package/ios/Util/TrackerVersion.swift +3 -0
  110. package/ios/Util/Utilities.swift +37 -0
  111. package/lefthook.yml +11 -0
  112. package/lib/commonjs/api.js +475 -0
  113. package/lib/commonjs/api.js.map +1 -0
  114. package/lib/commonjs/configurations.js +209 -0
  115. package/lib/commonjs/configurations.js.map +1 -0
  116. package/lib/commonjs/constants.js +85 -0
  117. package/lib/commonjs/constants.js.map +1 -0
  118. package/lib/commonjs/events.js +256 -0
  119. package/lib/commonjs/events.js.map +1 -0
  120. package/lib/commonjs/index.js +141 -0
  121. package/lib/commonjs/index.js.map +1 -0
  122. package/lib/commonjs/jsCore.js +393 -0
  123. package/lib/commonjs/jsCore.js.map +1 -0
  124. package/lib/commonjs/native.js +29 -0
  125. package/lib/commonjs/native.js.map +1 -0
  126. package/lib/commonjs/subject.js +248 -0
  127. package/lib/commonjs/subject.js.map +1 -0
  128. package/lib/commonjs/tracker.js +221 -0
  129. package/lib/commonjs/tracker.js.map +1 -0
  130. package/lib/commonjs/types.js +2 -0
  131. package/lib/commonjs/types.js.map +1 -0
  132. package/lib/commonjs/utils.js +85 -0
  133. package/lib/commonjs/utils.js.map +1 -0
  134. package/lib/commonjs/webViewInterface.js +79 -0
  135. package/lib/commonjs/webViewInterface.js.map +1 -0
  136. package/lib/module/api.js +439 -0
  137. package/lib/module/api.js.map +1 -0
  138. package/lib/module/configurations.js +197 -0
  139. package/lib/module/configurations.js.map +1 -0
  140. package/lib/module/constants.js +80 -0
  141. package/lib/module/constants.js.map +1 -0
  142. package/lib/module/events.js +240 -0
  143. package/lib/module/events.js.map +1 -0
  144. package/lib/module/index.js +129 -0
  145. package/lib/module/index.js.map +1 -0
  146. package/lib/module/jsCore.js +390 -0
  147. package/lib/module/jsCore.js.map +1 -0
  148. package/lib/module/native.js +25 -0
  149. package/lib/module/native.js.map +1 -0
  150. package/lib/module/subject.js +235 -0
  151. package/lib/module/subject.js.map +1 -0
  152. package/lib/module/tracker.js +209 -0
  153. package/lib/module/tracker.js.map +1 -0
  154. package/lib/module/types.js +2 -0
  155. package/lib/module/types.js.map +1 -0
  156. package/lib/module/utils.js +79 -0
  157. package/lib/module/utils.js.map +1 -0
  158. package/lib/module/webViewInterface.js +75 -0
  159. package/lib/module/webViewInterface.js.map +1 -0
  160. package/lib/typescript/__tests__/api.test.d.ts +2 -0
  161. package/lib/typescript/__tests__/api.test.d.ts.map +1 -0
  162. package/lib/typescript/__tests__/configurations.test.d.ts +2 -0
  163. package/lib/typescript/__tests__/configurations.test.d.ts.map +1 -0
  164. package/lib/typescript/__tests__/events.test.d.ts +2 -0
  165. package/lib/typescript/__tests__/events.test.d.ts.map +1 -0
  166. package/lib/typescript/__tests__/index.test.d.ts +2 -0
  167. package/lib/typescript/__tests__/index.test.d.ts.map +1 -0
  168. package/lib/typescript/__tests__/jsCore.test.d.ts +2 -0
  169. package/lib/typescript/__tests__/jsCore.test.d.ts.map +1 -0
  170. package/lib/typescript/__tests__/utils.test.d.ts +2 -0
  171. package/lib/typescript/__tests__/utils.test.d.ts.map +1 -0
  172. package/lib/typescript/api.d.ts +226 -0
  173. package/lib/typescript/api.d.ts.map +1 -0
  174. package/lib/typescript/configurations.d.ts +73 -0
  175. package/lib/typescript/configurations.d.ts.map +1 -0
  176. package/lib/typescript/constants.d.ts +59 -0
  177. package/lib/typescript/constants.d.ts.map +1 -0
  178. package/lib/typescript/events.d.ts +101 -0
  179. package/lib/typescript/events.d.ts.map +1 -0
  180. package/lib/typescript/index.d.ts +27 -0
  181. package/lib/typescript/index.d.ts.map +1 -0
  182. package/lib/typescript/jsCore.d.ts +140 -0
  183. package/lib/typescript/jsCore.d.ts.map +1 -0
  184. package/lib/typescript/native.d.ts +4 -0
  185. package/lib/typescript/native.d.ts.map +1 -0
  186. package/lib/typescript/subject.d.ts +91 -0
  187. package/lib/typescript/subject.d.ts.map +1 -0
  188. package/lib/typescript/tracker.d.ts +93 -0
  189. package/lib/typescript/tracker.d.ts.map +1 -0
  190. package/{dist/index.d.ts → lib/typescript/types.d.ts} +188 -75
  191. package/lib/typescript/types.d.ts.map +1 -0
  192. package/lib/typescript/utils.d.ts +35 -0
  193. package/lib/typescript/utils.d.ts.map +1 -0
  194. package/lib/typescript/webViewInterface.d.ts +15 -0
  195. package/lib/typescript/webViewInterface.d.ts.map +1 -0
  196. package/package.json +134 -52
  197. package/scripts/bootstrap.js +29 -0
  198. package/snowplow-react-native-tracker.podspec +42 -0
  199. package/src/__mocks__/react-native.js +7 -0
  200. package/src/__tests__/api.test.ts +34 -0
  201. package/src/__tests__/configurations.test.ts +620 -0
  202. package/src/__tests__/events.test.ts +749 -0
  203. package/src/__tests__/index.test.ts +27 -0
  204. package/src/__tests__/jsCore.test.ts +169 -0
  205. package/src/__tests__/utils.test.ts +23 -0
  206. package/src/api.ts +535 -0
  207. package/src/configurations.ts +337 -0
  208. package/src/constants.ts +102 -0
  209. package/src/events.ts +330 -0
  210. package/src/index.ts +189 -0
  211. package/src/jsCore.ts +553 -0
  212. package/src/native.ts +34 -0
  213. package/src/subject.ts +315 -0
  214. package/src/tracker.ts +330 -0
  215. package/src/types.ts +1087 -0
  216. package/src/utils.ts +78 -0
  217. package/src/webViewInterface.ts +105 -0
  218. package/tsconfig.build.json +5 -0
  219. package/tsconfig.json +28 -0
  220. package/turbo.json +34 -0
  221. package/yarn.lock +9333 -0
  222. package/RNSnowplowTracker.podspec +0 -24
  223. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java +0 -750
  224. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerPackage.java +0 -29
  225. package/android/src/main/java/com/snowplowanalytics/react/util/ConfigUtil.java +0 -351
  226. package/android/src/main/java/com/snowplowanalytics/react/util/EventUtil.java +0 -339
  227. package/android/src/main/java/com/snowplowanalytics/react/util/TrackerVersion.java +0 -7
  228. package/dist/index.js +0 -2026
  229. package/dist/index.js.map +0 -1
  230. package/ios/RNSnowplowTracker.h +0 -34
  231. package/ios/RNSnowplowTracker.m +0 -911
  232. package/ios/Util/NSDictionary+RNSP_TypeMethods.h +0 -33
  233. package/ios/Util/NSDictionary+RNSP_TypeMethods.m +0 -40
  234. package/ios/Util/RNConfigUtils.h +0 -44
  235. package/ios/Util/RNConfigUtils.m +0 -209
  236. package/ios/Util/RNTrackerVersion.h +0 -27
  237. package/ios/Util/RNTrackerVersion.m +0 -27
  238. package/ios/Util/RNUtilities.h +0 -32
  239. package/ios/Util/RNUtilities.m +0 -68
@@ -0,0 +1,749 @@
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 e from '../events';
15
+ import { logMessages } from '../constants';
16
+
17
+ describe('test isValidSD', () => {
18
+ test('test invalid type', () => {
19
+ const testSD = undefined as any;
20
+ expect(e.isValidSD(testSD)).toBe(false);
21
+ });
22
+
23
+ test('test invalid - no keys', () => {
24
+ const testSD = {} as any;
25
+ expect(e.isValidSD(testSD)).toBe(false);
26
+ });
27
+
28
+ test('test invalid schema', () => {
29
+ const testSD = {
30
+ schema: null,
31
+ data: { test: 'test' },
32
+ } as any;
33
+ expect(e.isValidSD(testSD)).toBe(false);
34
+ });
35
+
36
+ test('test invalid data', () => {
37
+ const testSD = {
38
+ schema: 'testSchema',
39
+ data: undefined,
40
+ } as any;
41
+ expect(e.isValidSD(testSD)).toBe(false);
42
+ });
43
+
44
+ test('test valid', () => {
45
+ const testSD = {
46
+ schema: 'testSchema',
47
+ data: {
48
+ test: 'valid',
49
+ },
50
+ };
51
+ expect(e.isValidSD(testSD)).toBe(true);
52
+ });
53
+ });
54
+
55
+ describe('test validateContexts', () => {
56
+ test('test invalid type', async () => {
57
+ const testContexts = 'notArray' as any;
58
+ await expect(e.validateContexts(testContexts)).rejects.toThrow(
59
+ logMessages.context
60
+ );
61
+ });
62
+
63
+ test('test invalid contexts', async () => {
64
+ const testContexts = [
65
+ { schema: 'test', data: { test: 'test' } },
66
+ { schema: null, data: { test: 'invalid' } },
67
+ ] as any;
68
+ await expect(e.validateContexts(testContexts)).rejects.toThrow(
69
+ logMessages.context
70
+ );
71
+ });
72
+
73
+ test('test valid contexts - empty', async () => {
74
+ const testContexts = [] as any;
75
+ await expect(e.validateContexts(testContexts)).resolves.toBe(true);
76
+ });
77
+
78
+ test('test valid contexts', async () => {
79
+ const testContexts = [
80
+ { schema: 'test', data: { test: 'test' } },
81
+ { schema: 'test', data: { test: 'valid' } },
82
+ ];
83
+ await expect(e.validateContexts(testContexts)).resolves.toBe(true);
84
+ });
85
+ });
86
+
87
+ describe('test validateSelfDesc', () => {
88
+ test('test invalid self-describing - wrong type', async () => {
89
+ const testEv = undefined as any;
90
+ await expect(e.validateSelfDesc(testEv)).rejects.toThrow(
91
+ logMessages.selfDesc
92
+ );
93
+ });
94
+
95
+ test('test invalid self-describing - empty object', async () => {
96
+ const testEv = {} as any;
97
+ await expect(e.validateSelfDesc(testEv)).rejects.toThrow(
98
+ logMessages.selfDesc
99
+ );
100
+ });
101
+
102
+ test('test valid self-describing', async () => {
103
+ const testEv = { schema: 'test', data: { test: 'test' } };
104
+ await expect(e.validateSelfDesc(testEv)).resolves.toBe(true);
105
+ });
106
+ });
107
+
108
+ describe('test validateScreenView', () => {
109
+ test('test invalid screen-view - wrong type', async () => {
110
+ const testEv = null as any;
111
+ await expect(e.validateScreenView(testEv)).rejects.toThrow(
112
+ logMessages.evType
113
+ );
114
+ });
115
+
116
+ test('test invalid screen-view - missing name', async () => {
117
+ const testEv = { type: 'test' } as any;
118
+ await expect(e.validateScreenView(testEv)).rejects.toThrow(
119
+ logMessages.screenViewReq
120
+ );
121
+ });
122
+
123
+ test('test invalid screen-view - wrong name', async () => {
124
+ const testEv = { name: null } as any;
125
+ await expect(e.validateScreenView(testEv)).rejects.toThrow(
126
+ logMessages.screenViewReq
127
+ );
128
+ });
129
+
130
+ test('test valid screen-view', async () => {
131
+ const testEv = {
132
+ name: 'test',
133
+ type: 'test',
134
+ previousName: 'preTest',
135
+ transitionType: 'testing',
136
+ };
137
+ await expect(e.validateScreenView(testEv)).resolves.toBe(true);
138
+ });
139
+ });
140
+
141
+ describe('test validateStructured', () => {
142
+ test('test invalid structured - wrong type', async () => {
143
+ const testEv = undefined as any;
144
+ await expect(e.validateStructured(testEv)).rejects.toThrow(
145
+ logMessages.evType
146
+ );
147
+ });
148
+
149
+ test('test invalid structured - missing category', async () => {
150
+ const testEv = { action: 'test' } as any;
151
+ await expect(e.validateStructured(testEv)).rejects.toThrow(
152
+ logMessages.structuredReq
153
+ );
154
+ });
155
+
156
+ test('test invalid structured - missing action', async () => {
157
+ const testEv = { category: 'test' } as any;
158
+ await expect(e.validateStructured(testEv)).rejects.toThrow(
159
+ logMessages.structuredReq
160
+ );
161
+ });
162
+
163
+ test('test invalid structured - wrong category', async () => {
164
+ const testEv = { category: null } as any;
165
+ await expect(e.validateStructured(testEv)).rejects.toThrow(
166
+ logMessages.structuredReq
167
+ );
168
+ });
169
+
170
+ test('test invalid structured - wrong action', async () => {
171
+ const testEv = { action: undefined } as any;
172
+ await expect(e.validateStructured(testEv)).rejects.toThrow(
173
+ logMessages.structuredReq
174
+ );
175
+ });
176
+
177
+ test('test valid structured', async () => {
178
+ const testEv = {
179
+ category: 'test',
180
+ action: 'test',
181
+ label: 'test',
182
+ property: 'test',
183
+ value: 0,
184
+ };
185
+ await expect(e.validateStructured(testEv)).resolves.toBe(true);
186
+ });
187
+ });
188
+
189
+ describe('test validatePageView', () => {
190
+ test('test invalid page-view - wrong type', async () => {
191
+ const testEv = 'pageView' as any;
192
+ await expect(e.validatePageView(testEv)).rejects.toThrow(
193
+ logMessages.evType
194
+ );
195
+ });
196
+
197
+ test('test invalid page-view - missing pageUrl', async () => {
198
+ const testEv = { pageTitle: 'test' } as any;
199
+ await expect(e.validatePageView(testEv)).rejects.toThrow(
200
+ logMessages.pageviewReq
201
+ );
202
+ });
203
+
204
+ test('test invalid page-view - pageUrl set to null', async () => {
205
+ const testEv = { pageUrl: null } as any;
206
+ await expect(e.validatePageView(testEv)).rejects.toThrow(
207
+ logMessages.pageviewReq
208
+ );
209
+ });
210
+
211
+ test('test valid page-view', async () => {
212
+ const testEv = {
213
+ pageUrl: 'test.test',
214
+ pageTitle: 'test',
215
+ pageReferrer: 'tested',
216
+ };
217
+ await expect(e.validatePageView(testEv)).resolves.toBe(true);
218
+ });
219
+ });
220
+
221
+ describe('test validateTiming', () => {
222
+ test('test invalid timing - wrong type', async () => {
223
+ const testEv = undefined as any;
224
+ await expect(e.validateTiming(testEv)).rejects.toThrow(logMessages.evType);
225
+ });
226
+
227
+ test('test invalid timing - missing category', async () => {
228
+ const testEv = {
229
+ variable: 'test',
230
+ timing: 0,
231
+ } as any;
232
+ await expect(e.validateTiming(testEv)).rejects.toThrow(
233
+ logMessages.timingReq
234
+ );
235
+ });
236
+
237
+ test('test invalid timing - missing variable', async () => {
238
+ const testEv = {
239
+ category: 'test',
240
+ timing: 0,
241
+ } as any;
242
+ await expect(e.validateTiming(testEv)).rejects.toThrow(
243
+ logMessages.timingReq
244
+ );
245
+ });
246
+
247
+ test('test invalid timing - missing timing', async () => {
248
+ const testEv = {
249
+ category: 'testing',
250
+ variable: 'test',
251
+ } as any;
252
+ await expect(e.validateTiming(testEv)).rejects.toThrow(
253
+ logMessages.timingReq
254
+ );
255
+ });
256
+
257
+ test('test invalid timing - wrong category', async () => {
258
+ const testEv = {
259
+ category: null,
260
+ variable: 'test',
261
+ timing: 0,
262
+ } as any;
263
+ await expect(e.validateTiming(testEv)).rejects.toThrow(
264
+ logMessages.timingReq
265
+ );
266
+ });
267
+
268
+ test('test invalid timing - wrong variable', async () => {
269
+ const testEv = {
270
+ category: 'test',
271
+ variable: null,
272
+ timing: 0,
273
+ } as any;
274
+ await expect(e.validateTiming(testEv)).rejects.toThrow(
275
+ logMessages.timingReq
276
+ );
277
+ });
278
+
279
+ test('test invalid timing - wrong timing', async () => {
280
+ const testEv = {
281
+ category: 'testing',
282
+ variable: 'test',
283
+ timing: 'invalid',
284
+ } as any;
285
+ await expect(e.validateTiming(testEv)).rejects.toThrow(
286
+ logMessages.timingReq
287
+ );
288
+ });
289
+
290
+ test('test valid timing', async () => {
291
+ const testEv = {
292
+ category: 'testing',
293
+ variable: 'test',
294
+ timing: 0,
295
+ label: 'test',
296
+ };
297
+ await expect(e.validateTiming(testEv)).resolves.toBe(true);
298
+ });
299
+ });
300
+
301
+ describe('test validateConsentGranted', () => {
302
+ test('test invalid consentGranted - wrong type', async () => {
303
+ const testEv = null as any;
304
+ await expect(e.validateConsentGranted(testEv)).rejects.toThrow(
305
+ logMessages.evType
306
+ );
307
+ });
308
+
309
+ test('test invalid consentGranted - missing expiry', async () => {
310
+ const testEv = {
311
+ documentId: 'testId',
312
+ version: '0.0.1',
313
+ } as any;
314
+ await expect(e.validateConsentGranted(testEv)).rejects.toThrow(
315
+ logMessages.consentGReq
316
+ );
317
+ });
318
+
319
+ test('test invalid consentGranted - missing documentId', async () => {
320
+ const testEv = {
321
+ expiry: '2022-01-01T00:00:00Z',
322
+ version: '0.0.1',
323
+ } as any;
324
+ await expect(e.validateConsentGranted(testEv)).rejects.toThrow(
325
+ logMessages.consentGReq
326
+ );
327
+ });
328
+
329
+ test('test invalid consentGranted - missing version', async () => {
330
+ const testEv = {
331
+ expiry: '2022-01-01T00:00:00Z',
332
+ documentId: 'testId',
333
+ } as any;
334
+ await expect(e.validateConsentGranted(testEv)).rejects.toThrow(
335
+ logMessages.consentGReq
336
+ );
337
+ });
338
+
339
+ test('test invalid consentGranted - wrong expiry', async () => {
340
+ const testEv = {
341
+ expiry: 0,
342
+ documentId: 'testId',
343
+ version: '0.0.1',
344
+ } as any;
345
+ await expect(e.validateConsentGranted(testEv)).rejects.toThrow(
346
+ logMessages.consentGReq
347
+ );
348
+ });
349
+
350
+ test('test invalid consentGranted - wrong documentId', async () => {
351
+ const testEv = {
352
+ expiry: '2022-01-01T00:00:00Z',
353
+ documentId: 0,
354
+ version: '0.0.1',
355
+ } as any;
356
+ await expect(e.validateConsentGranted(testEv)).rejects.toThrow(
357
+ logMessages.consentGReq
358
+ );
359
+ });
360
+
361
+ test('test invalid consentGranted - wrong version', async () => {
362
+ const testEv = {
363
+ expiry: '2022-01-01T00:00:00Z',
364
+ documentId: 'testId',
365
+ version: undefined,
366
+ } as any;
367
+ await expect(e.validateConsentGranted(testEv)).rejects.toThrow(
368
+ logMessages.consentGReq
369
+ );
370
+ });
371
+
372
+ test('test valid consentGranted', async () => {
373
+ const testEv = {
374
+ expiry: '2022-01-01T00:00:00Z',
375
+ documentId: 'testId',
376
+ version: '0.0.1',
377
+ name: 'testName',
378
+ documentDescription: 'testDescription',
379
+ };
380
+ await expect(e.validateConsentGranted(testEv)).resolves.toBe(true);
381
+ });
382
+ });
383
+
384
+ describe('test validateConsentWithdrawn', () => {
385
+ test('test invalid consentWithdrawn - wrong type', async () => {
386
+ const testEv = null as any;
387
+ await expect(e.validateConsentWithdrawn(testEv)).rejects.toThrow(
388
+ logMessages.evType
389
+ );
390
+ });
391
+
392
+ test('test invalid consentWithdrawn - missing all', async () => {
393
+ const testEv = {
394
+ documentId: 'testId',
395
+ version: '0.0.1',
396
+ } as any;
397
+ await expect(e.validateConsentWithdrawn(testEv)).rejects.toThrow(
398
+ logMessages.consentWReq
399
+ );
400
+ });
401
+
402
+ test('test invalid consentWithdrawn - missing documentId', async () => {
403
+ const testEv = {
404
+ all: false,
405
+ version: '0.0.1',
406
+ } as any;
407
+ await expect(e.validateConsentWithdrawn(testEv)).rejects.toThrow(
408
+ logMessages.consentWReq
409
+ );
410
+ });
411
+
412
+ test('test invalid consentWithdrawn - missing version', async () => {
413
+ const testEv = {
414
+ all: true,
415
+ documentId: 'testId',
416
+ } as any;
417
+ await expect(e.validateConsentWithdrawn(testEv)).rejects.toThrow(
418
+ logMessages.consentWReq
419
+ );
420
+ });
421
+
422
+ test('test invalid consentWithdrawn - wrong all', async () => {
423
+ const testEv = {
424
+ all: 'wrong',
425
+ documentId: 'testId',
426
+ version: '0.0.1',
427
+ } as any;
428
+ await expect(e.validateConsentWithdrawn(testEv)).rejects.toThrow(
429
+ logMessages.consentWReq
430
+ );
431
+ });
432
+
433
+ test('test invalid consentWithdrawn - wrong documentId', async () => {
434
+ const testEv = {
435
+ all: true,
436
+ documentId: null,
437
+ version: '0.0.1',
438
+ } as any;
439
+ await expect(e.validateConsentWithdrawn(testEv)).rejects.toThrow(
440
+ logMessages.consentWReq
441
+ );
442
+ });
443
+
444
+ test('test invalid consentWithdrawn - wrong version', async () => {
445
+ const testEv = {
446
+ all: true,
447
+ documentId: 'testId',
448
+ version: 0,
449
+ } as any;
450
+ await expect(e.validateConsentWithdrawn(testEv)).rejects.toThrow(
451
+ logMessages.consentWReq
452
+ );
453
+ });
454
+
455
+ test('test valid consentWithdrawn', async () => {
456
+ const testEv = {
457
+ all: true,
458
+ documentId: 'testId',
459
+ version: '0.0.1',
460
+ name: 'testName',
461
+ documentDescription: 'testDescription',
462
+ };
463
+ await expect(e.validateConsentWithdrawn(testEv)).resolves.toBe(true);
464
+ });
465
+ });
466
+
467
+ describe('test validateDeepLinkReceived', () => {
468
+ test('test invalid deepLinkReceived - wrong type', async () => {
469
+ const testEv = null as any;
470
+ await expect(e.validateDeepLinkReceived(testEv)).rejects.toThrow(
471
+ logMessages.evType
472
+ );
473
+ });
474
+
475
+ test('test invalid deepLinkReceived - missing url', async () => {
476
+ const testEv = {} as any;
477
+ await expect(e.validateDeepLinkReceived(testEv)).rejects.toThrow(
478
+ logMessages.deepLinkReq
479
+ );
480
+ });
481
+
482
+ test('test invalid deepLinkReceived - invalid url', async () => {
483
+ const testEv = {
484
+ url: true,
485
+ } as any;
486
+ await expect(e.validateDeepLinkReceived(testEv)).rejects.toThrow(
487
+ logMessages.deepLinkReq
488
+ );
489
+ });
490
+
491
+ test('test valid deepLinkReceived', async () => {
492
+ const testEv = {
493
+ url: 'https://example.com/to',
494
+ referrer: 'https://example.com/from',
495
+ };
496
+ await expect(e.validateDeepLinkReceived(testEv)).resolves.toBe(true);
497
+ });
498
+ });
499
+
500
+ describe('test validateMessageNotification', () => {
501
+ test('test invalid messageNotification - wrong type', async () => {
502
+ const testEv = null as any;
503
+ await expect(e.validateMessageNotification(testEv)).rejects.toThrow(
504
+ logMessages.evType
505
+ );
506
+ });
507
+
508
+ test('test invalid messageNotification - missing properties', async () => {
509
+ const testEv = {} as any;
510
+ await expect(e.validateMessageNotification(testEv)).rejects.toThrow(
511
+ logMessages.messageNotificationReq
512
+ );
513
+ });
514
+
515
+ test('test invalid messageNotification - invalid trigger', async () => {
516
+ const testEv = {
517
+ title: 'x',
518
+ body: 'y',
519
+ trigger: 'z',
520
+ } as any;
521
+ await expect(e.validateMessageNotification(testEv)).rejects.toThrow(
522
+ logMessages.messageNotificationReq
523
+ );
524
+ });
525
+
526
+ test('test valid messageNotification', async () => {
527
+ const testEv = {
528
+ title: 'x',
529
+ body: 'y',
530
+ trigger: 'push',
531
+ } as any;
532
+ await expect(e.validateMessageNotification(testEv)).resolves.toBe(true);
533
+ });
534
+ });
535
+
536
+ describe('test isValidEcomItem', () => {
537
+ test('invalid - wrong type', () => {
538
+ const testItem = 'invalid' as any;
539
+ expect(e.isValidEcomItem(testItem)).toBe(false);
540
+ });
541
+ test('invalid - missing sku', () => {
542
+ const testItem = {
543
+ price: 0.1,
544
+ quantity: 1,
545
+ } as any;
546
+ expect(e.isValidEcomItem(testItem)).toBe(false);
547
+ });
548
+ test('invalid - missing price', () => {
549
+ const testItem = {
550
+ sku: '123',
551
+ quantity: 1,
552
+ } as any;
553
+ expect(e.isValidEcomItem(testItem)).toBe(false);
554
+ });
555
+ test('invalid - missing quantity', () => {
556
+ const testItem = {
557
+ sku: '123',
558
+ price: 0.1,
559
+ } as any;
560
+ expect(e.isValidEcomItem(testItem)).toBe(false);
561
+ });
562
+ test('invalid - wrong sku', () => {
563
+ const testItem = {
564
+ sku: 123,
565
+ price: 0.1,
566
+ quantity: 1,
567
+ } as any;
568
+ expect(e.isValidEcomItem(testItem)).toBe(false);
569
+ });
570
+ test('invalid - wrong price', () => {
571
+ const testItem = {
572
+ sku: '123',
573
+ price: '0.1',
574
+ quantity: 1,
575
+ } as any;
576
+ expect(e.isValidEcomItem(testItem)).toBe(false);
577
+ });
578
+ test('invalid - wrong quantity', () => {
579
+ const testItem = {
580
+ sku: '123',
581
+ price: 0.1,
582
+ quantity: '1',
583
+ } as any;
584
+ expect(e.isValidEcomItem(testItem)).toBe(false);
585
+ });
586
+ test('valid', () => {
587
+ const testItem = {
588
+ sku: '123',
589
+ price: 0.1,
590
+ quantity: 1,
591
+ };
592
+ expect(e.isValidEcomItem(testItem)).toBe(true);
593
+ });
594
+ });
595
+
596
+ describe('test validItemsArg', () => {
597
+ test('invalid - not an array', () => {
598
+ const testArg = undefined as any;
599
+ expect(e.validItemsArg(testArg)).toBe(false);
600
+ });
601
+
602
+ test('invalid', () => {
603
+ const testArg = [
604
+ {
605
+ sku: '123',
606
+ price: 0.1,
607
+ quantity: 1,
608
+ },
609
+ {
610
+ sku: null,
611
+ price: 0.1,
612
+ quantity: 1,
613
+ },
614
+ ] as any;
615
+ expect(e.validItemsArg(testArg)).toBe(false);
616
+ });
617
+
618
+ test('valid - empty', () => {
619
+ const testArg = [] as any;
620
+ expect(e.validItemsArg(testArg)).toBe(true);
621
+ });
622
+
623
+ test('valid', () => {
624
+ const testArg = [
625
+ {
626
+ sku: '123',
627
+ price: 0.1,
628
+ quantity: 1,
629
+ },
630
+ ];
631
+ expect(e.validItemsArg(testArg)).toBe(true);
632
+ });
633
+ });
634
+
635
+ describe('test validateEcommerceTransaction', () => {
636
+ test('invalid - wrong type', async () => {
637
+ const testEcom = null as any;
638
+ await expect(e.validateEcommerceTransaction(testEcom)).rejects.toThrow(
639
+ logMessages.evType
640
+ );
641
+ });
642
+
643
+ test('invalid - missing orderId', async () => {
644
+ const testEcom = {
645
+ totalValue: 0.1,
646
+ items: [
647
+ {
648
+ sku: '123',
649
+ price: 0.1,
650
+ quantity: 1,
651
+ },
652
+ ],
653
+ } as any;
654
+ await expect(e.validateEcommerceTransaction(testEcom)).rejects.toThrow(
655
+ logMessages.ecomReq
656
+ );
657
+ });
658
+
659
+ test('invalid - missing totalValue', async () => {
660
+ const testEcom = {
661
+ orderId: '123',
662
+ items: [
663
+ {
664
+ sku: '123',
665
+ price: 0.1,
666
+ quantity: 1,
667
+ },
668
+ ],
669
+ } as any;
670
+ await expect(e.validateEcommerceTransaction(testEcom)).rejects.toThrow(
671
+ logMessages.ecomReq
672
+ );
673
+ });
674
+
675
+ test('invalid - missing items', async () => {
676
+ const testEcom = {
677
+ orderId: '123',
678
+ totalValue: 0.1,
679
+ } as any;
680
+ await expect(e.validateEcommerceTransaction(testEcom)).rejects.toThrow(
681
+ logMessages.ecomReq
682
+ );
683
+ });
684
+
685
+ test('invalid - wrong orderId', async () => {
686
+ const testEcom = {
687
+ orderId: 123,
688
+ totalValue: 0.1,
689
+ items: [
690
+ {
691
+ sku: '123',
692
+ price: 0.1,
693
+ quantity: 1,
694
+ },
695
+ ],
696
+ } as any;
697
+ await expect(e.validateEcommerceTransaction(testEcom)).rejects.toThrow(
698
+ logMessages.ecomReq
699
+ );
700
+ });
701
+
702
+ test('invalid - wrong totalValue', async () => {
703
+ const testEcom = {
704
+ orderId: '123',
705
+ totalValue: '0.1',
706
+ items: [
707
+ {
708
+ sku: '123',
709
+ price: 0.1,
710
+ quantity: 1,
711
+ },
712
+ ],
713
+ } as any;
714
+ await expect(e.validateEcommerceTransaction(testEcom)).rejects.toThrow(
715
+ logMessages.ecomReq
716
+ );
717
+ });
718
+
719
+ test('invalid - wrong items', async () => {
720
+ const testEcom = {
721
+ orderId: '123',
722
+ totalValue: 0.1,
723
+ items: [
724
+ {
725
+ sku: '123',
726
+ quantity: 1,
727
+ },
728
+ ],
729
+ } as any;
730
+ await expect(e.validateEcommerceTransaction(testEcom)).rejects.toThrow(
731
+ logMessages.ecomReq
732
+ );
733
+ });
734
+
735
+ test('valid', async () => {
736
+ const testEcom = {
737
+ orderId: '123',
738
+ totalValue: 0.1,
739
+ items: [
740
+ {
741
+ sku: '123',
742
+ price: 0.1,
743
+ quantity: 1,
744
+ },
745
+ ],
746
+ };
747
+ await expect(e.validateEcommerceTransaction(testEcom)).resolves.toBe(true);
748
+ });
749
+ });