node-avo-inspector 1.2.0 → 2.0.0-beta.2

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 (132) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +270 -4
  3. package/dist/AvoBatchQueue.d.ts +73 -0
  4. package/dist/AvoBatchQueue.js +239 -0
  5. package/dist/AvoDeduplicator.d.ts +15 -6
  6. package/dist/AvoDeduplicator.js +46 -24
  7. package/dist/AvoInspector.d.ts +136 -23
  8. package/dist/AvoInspector.js +777 -109
  9. package/dist/AvoInspectorVersion.d.ts +3 -0
  10. package/dist/AvoInspectorVersion.js +10 -0
  11. package/dist/AvoLog.d.ts +52 -0
  12. package/dist/AvoLog.js +246 -0
  13. package/dist/AvoNetworkCallsHandler.d.ts +55 -8
  14. package/dist/AvoNetworkCallsHandler.js +266 -92
  15. package/dist/AvoSchemaParser.d.ts +6 -0
  16. package/dist/AvoSchemaParser.js +138 -33
  17. package/dist/AvoStreamId.d.ts +2 -1
  18. package/dist/AvoStreamId.js +21 -2
  19. package/dist/eventSpec/AvoEventSpecCache.d.ts +28 -5
  20. package/dist/eventSpec/AvoEventSpecCache.js +66 -11
  21. package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +50 -18
  22. package/dist/eventSpec/AvoEventSpecFetcher.d.ts +29 -6
  23. package/dist/eventSpec/AvoEventSpecFetcher.js +279 -69
  24. package/dist/eventSpec/EventValidator.d.ts +16 -10
  25. package/dist/eventSpec/EventValidator.js +351 -38
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +4 -1
  28. package/dist/utils.d.ts +29 -1
  29. package/dist/utils.js +86 -10
  30. package/package.json +18 -1
  31. package/.claude/scheduled_tasks.lock +0 -1
  32. package/.claude/settings.local.json +0 -11
  33. package/.claude/worktrees/release-1.1.1/LICENSE +0 -21
  34. package/.claude/worktrees/release-1.1.1/README.md +0 -69
  35. package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/index.js +0 -30
  36. package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/package.json +0 -15
  37. package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/yarn.lock +0 -6
  38. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/dist/index.js +0 -34
  39. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/index.ts +0 -30
  40. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/package.json +0 -18
  41. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/tsconfig.json +0 -15
  42. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/yarn.lock +0 -11
  43. package/.claude/worktrees/release-1.1.1/package-lock.json +0 -4039
  44. package/.claude/worktrees/release-1.1.1/package.json +0 -48
  45. package/.claude/worktrees/release-1.1.1/reason/AvoInspector.rei +0 -11
  46. package/.claude/worktrees/release-1.1.1/reason/NodeAvoInspector.re +0 -27
  47. package/.claude/worktrees/release-1.1.1/src/AvoDeduplicator.ts +0 -146
  48. package/.claude/worktrees/release-1.1.1/src/AvoEncryption.ts +0 -90
  49. package/.claude/worktrees/release-1.1.1/src/AvoGuid.ts +0 -9
  50. package/.claude/worktrees/release-1.1.1/src/AvoInspector.ts +0 -383
  51. package/.claude/worktrees/release-1.1.1/src/AvoInspectorEnv.ts +0 -8
  52. package/.claude/worktrees/release-1.1.1/src/AvoNetworkCallsHandler.ts +0 -267
  53. package/.claude/worktrees/release-1.1.1/src/AvoSchemaParser.ts +0 -115
  54. package/.claude/worktrees/release-1.1.1/src/AvoStreamId.ts +0 -16
  55. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEncryption.ts +0 -515
  56. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecCache.ts +0 -242
  57. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecFetcher.ts +0 -241
  58. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoInspector.ts +0 -360
  59. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoStreamId.ts +0 -72
  60. package/.claude/worktrees/release-1.1.1/src/__tests__/TestDeduplicator.ts +0 -191
  61. package/.claude/worktrees/release-1.1.1/src/__tests__/TestEventValidator.ts +0 -231
  62. package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandler.ts +0 -179
  63. package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
  64. package/.claude/worktrees/release-1.1.1/src/__tests__/TestParsing.ts +0 -153
  65. package/.claude/worktrees/release-1.1.1/src/__tests__/constants.ts +0 -63
  66. package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecCache.ts +0 -109
  67. package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
  68. package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetcher.ts +0 -106
  69. package/.claude/worktrees/release-1.1.1/src/eventSpec/EventValidator.ts +0 -74
  70. package/.claude/worktrees/release-1.1.1/src/index.ts +0 -2
  71. package/.claude/worktrees/release-1.1.1/src/utils.ts +0 -49
  72. package/.claude/worktrees/release-1.1.1/tsconfig.json +0 -13
  73. package/.claude/worktrees/release-1.1.1/yarn.lock +0 -2310
  74. package/.github/workflows/claude.yml +0 -55
  75. package/dist/__tests__/TestAvoEncryption.d.ts +0 -1
  76. package/dist/__tests__/TestAvoEncryption.js +0 -288
  77. package/dist/__tests__/TestAvoEventSpecCache.d.ts +0 -1
  78. package/dist/__tests__/TestAvoEventSpecCache.js +0 -194
  79. package/dist/__tests__/TestAvoEventSpecFetcher.d.ts +0 -1
  80. package/dist/__tests__/TestAvoEventSpecFetcher.js +0 -219
  81. package/dist/__tests__/TestAvoInspector.d.ts +0 -1
  82. package/dist/__tests__/TestAvoInspector.js +0 -291
  83. package/dist/__tests__/TestAvoStreamId.d.ts +0 -1
  84. package/dist/__tests__/TestAvoStreamId.js +0 -55
  85. package/dist/__tests__/TestDeduplicator.d.ts +0 -1
  86. package/dist/__tests__/TestDeduplicator.js +0 -102
  87. package/dist/__tests__/TestEventValidator.d.ts +0 -1
  88. package/dist/__tests__/TestEventValidator.js +0 -196
  89. package/dist/__tests__/TestNetworkCallsHandler.d.ts +0 -1
  90. package/dist/__tests__/TestNetworkCallsHandler.js +0 -86
  91. package/dist/__tests__/TestNetworkCallsHandlerPublic.d.ts +0 -1
  92. package/dist/__tests__/TestNetworkCallsHandlerPublic.js +0 -160
  93. package/dist/__tests__/TestParsing.d.ts +0 -1
  94. package/dist/__tests__/TestParsing.js +0 -128
  95. package/dist/__tests__/constants.d.ts +0 -42
  96. package/dist/__tests__/constants.js +0 -53
  97. package/examples/node-inspector-js/index.js +0 -30
  98. package/examples/node-inspector-js/package.json +0 -15
  99. package/examples/node-inspector-js/yarn.lock +0 -6
  100. package/examples/node-inspector-ts/dist/index.js +0 -34
  101. package/examples/node-inspector-ts/index.ts +0 -30
  102. package/examples/node-inspector-ts/package.json +0 -18
  103. package/examples/node-inspector-ts/tsconfig.json +0 -15
  104. package/examples/node-inspector-ts/yarn.lock +0 -11
  105. package/reason/AvoInspector.rei +0 -11
  106. package/reason/NodeAvoInspector.re +0 -27
  107. package/src/AvoDeduplicator.ts +0 -150
  108. package/src/AvoEncryption.ts +0 -90
  109. package/src/AvoGuid.ts +0 -9
  110. package/src/AvoInspector.ts +0 -498
  111. package/src/AvoInspectorEnv.ts +0 -8
  112. package/src/AvoNetworkCallsHandler.ts +0 -340
  113. package/src/AvoSchemaParser.ts +0 -115
  114. package/src/AvoStreamId.ts +0 -16
  115. package/src/__tests__/TestAvoEncryption.ts +0 -515
  116. package/src/__tests__/TestAvoEventSpecCache.ts +0 -242
  117. package/src/__tests__/TestAvoEventSpecFetcher.ts +0 -279
  118. package/src/__tests__/TestAvoInspector.ts +0 -376
  119. package/src/__tests__/TestAvoStreamId.ts +0 -72
  120. package/src/__tests__/TestDeduplicator.ts +0 -191
  121. package/src/__tests__/TestEventValidator.ts +0 -231
  122. package/src/__tests__/TestNetworkCallsHandler.ts +0 -181
  123. package/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
  124. package/src/__tests__/TestParsing.ts +0 -153
  125. package/src/__tests__/constants.ts +0 -63
  126. package/src/eventSpec/AvoEventSpecCache.ts +0 -119
  127. package/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
  128. package/src/eventSpec/AvoEventSpecFetcher.ts +0 -186
  129. package/src/eventSpec/EventValidator.ts +0 -74
  130. package/src/index.ts +0 -2
  131. package/src/utils.ts +0 -49
  132. package/tsconfig.json +0 -13
@@ -1,360 +0,0 @@
1
- import { AvoInspector } from "../AvoInspector";
2
- import { AvoInspectorEnv } from "../AvoInspectorEnv";
3
-
4
- import { error, defaultOptions } from "./constants";
5
- import { AvoNetworkCallsHandler } from "../AvoNetworkCallsHandler";
6
-
7
- jest.mock("../AvoNetworkCallsHandler");
8
-
9
- describe("Initialization", () => {
10
-
11
- test("Network Handler is initialized on Inspector init", () => {
12
- const inspectorVersion = process.env.npm_package_version || "";
13
- const { apiKey, env, version, appName } = defaultOptions;
14
-
15
- let inspector = new AvoInspector(defaultOptions);
16
- inspector.enableLogging(true);
17
-
18
- expect(AvoNetworkCallsHandler).toHaveBeenCalledTimes(1);
19
- expect(AvoNetworkCallsHandler).toHaveBeenCalledWith(apiKey,
20
- env,
21
- "my-test-app",
22
- version,
23
- inspectorVersion,
24
- undefined);
25
- });
26
-
27
- test("Api Key is set", () => {
28
- // Given
29
- const apiKey = "api-key-xxx";
30
-
31
- // When
32
- let inspector = new AvoInspector({
33
- env: AvoInspectorEnv.Prod,
34
- version: "0",
35
- apiKey,
36
- });
37
-
38
- // Then
39
- expect(inspector.apiKey).toBe(apiKey);
40
- });
41
-
42
- test("Error is thrown when Api Key is not set", () => {
43
- // Given
44
- // @ts-ignore
45
- let apiKey;
46
-
47
- // Then
48
- expect(() => {
49
- new AvoInspector({
50
- env: AvoInspectorEnv.Prod,
51
- version: "0",
52
- // @ts-ignore
53
- apiKey,
54
- });
55
- }).toThrow(error.API_KEY);
56
- });
57
-
58
- test("Error is thrown when whitespace Api Key is used", () => {
59
- // Given
60
- const apiKey = " ";
61
-
62
- // Then
63
- expect(() => {
64
- new AvoInspector({
65
- env: AvoInspectorEnv.Prod,
66
- version: "0",
67
- apiKey,
68
- });
69
- }).toThrow(error.API_KEY);
70
- });
71
-
72
- test("Error is thrown when empty string Api Key is used", () => {
73
- expect(() => {
74
- new AvoInspector({
75
- env: AvoInspectorEnv.Prod,
76
- version: "0",
77
- apiKey: "",
78
- });
79
- }).toThrow(error.API_KEY);
80
- });
81
-
82
- test("Error is thrown when Api Key is set to null", () => {
83
- // Given
84
- const apiKey = null;
85
-
86
- // Then
87
- expect(() => {
88
- new AvoInspector({
89
- env: AvoInspectorEnv.Prod,
90
- version: "0",
91
- // @ts-ignore
92
- apiKey,
93
- });
94
- }).toThrow(error.API_KEY);
95
- });
96
-
97
- test("Dev environment is used when env is not provided", () => {
98
- // Given
99
- // @ts-ignore
100
- let env;
101
-
102
- // When
103
- let inspector = new AvoInspector({
104
- apiKey: "api-key-xxx",
105
- version: "0",
106
- // @ts-ignore
107
- env,
108
- });
109
-
110
- // Then
111
- expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
112
- });
113
-
114
- test("Dev environment is used when empty string is used", () => {
115
- // Given
116
- const env = "";
117
-
118
- // When
119
- let inspector = new AvoInspector({
120
- apiKey: "api-key-xxx",
121
- version: "0",
122
- // @ts-ignore
123
- env,
124
- });
125
-
126
- // Then
127
- expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
128
- });
129
-
130
- test("Dev env is set using AvoInspectorEnv", () => {
131
- // When
132
- let inspector = new AvoInspector({
133
- apiKey: "api-key-xxx",
134
- env: AvoInspectorEnv.Dev,
135
- version: "0",
136
- });
137
-
138
- // Then
139
- expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
140
- });
141
-
142
- test("Dev environment is set using string", () => {
143
- // When
144
- let inspector = new AvoInspector({
145
- apiKey: "api-key-xxx",
146
- env: "dev",
147
- version: "0",
148
- });
149
-
150
- // Then
151
- expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
152
- });
153
-
154
- test("Staging env is set using AvoInspectorEnv", () => {
155
- // When
156
- let inspector = new AvoInspector({
157
- apiKey: "api-key-xxx",
158
- env: AvoInspectorEnv.Staging,
159
- version: "0",
160
- });
161
-
162
- // Then
163
- expect(inspector.environment).toBe(AvoInspectorEnv.Staging);
164
- });
165
-
166
- test("Staging environment is set using string", () => {
167
- // When
168
- let inspector = new AvoInspector({
169
- apiKey: "api-key-xxx",
170
- env: "staging",
171
- version: "0",
172
- });
173
-
174
- // Then
175
- expect(inspector.environment).toBe(AvoInspectorEnv.Staging);
176
- });
177
-
178
- test("Prod env is set using AvoInspectorEnv", () => {
179
- // When
180
- let inspector = new AvoInspector({
181
- apiKey: "api-key-xxx",
182
- env: AvoInspectorEnv.Prod,
183
- version: "0",
184
- });
185
-
186
- // Then
187
- expect(inspector.environment).toBe(AvoInspectorEnv.Prod);
188
- });
189
-
190
- test("Prod environment is set using string", () => {
191
- // When
192
- let inspector = new AvoInspector({
193
- apiKey: "api-key-xxx",
194
- env: "prod",
195
- version: "0",
196
- });
197
-
198
- // Then
199
- expect(inspector.environment).toBe(AvoInspectorEnv.Prod);
200
- });
201
-
202
- test("Environment other than Dev, Staging, Prod falls back to Dev", () => {
203
- // When
204
- const env = "test";
205
-
206
- let inspector = new AvoInspector({
207
- apiKey: "api-key-xxx",
208
- version: "0",
209
- // @ts-ignore
210
- env,
211
- });
212
-
213
- // Then
214
- expect(inspector.environment).toBe(AvoInspectorEnv.Dev);
215
- });
216
-
217
- test("Version is set", () => {
218
- const version = "1";
219
-
220
- // When
221
- let inspector = new AvoInspector({
222
- apiKey: "api-key-xxx",
223
- env: AvoInspectorEnv.Prod,
224
- version,
225
- });
226
-
227
- // Then
228
- expect(inspector.version).toBe(version);
229
- });
230
-
231
- test("Error is thrown when version is not set", () => {
232
- // Given
233
- // @ts-ignore
234
- let version;
235
-
236
- // Then
237
- expect(() => {
238
- new AvoInspector({
239
- apiKey: "api-key-xxx",
240
- env: AvoInspectorEnv.Prod,
241
- // @ts-ignore
242
- version,
243
- });
244
- }).toThrow(error.VERSION);
245
- });
246
-
247
- test("Error is thrown when version is set to empty string", () => {
248
- // Given
249
- const version = " ";
250
-
251
- // Then
252
- expect(() => {
253
- new AvoInspector({
254
- apiKey: "api-key-xxx",
255
- env: AvoInspectorEnv.Prod,
256
- version,
257
- });
258
- }).toThrow(error.VERSION);
259
- });
260
-
261
- test("Error is thrown when version is set to null", () => {
262
- // Given
263
- const version = null;
264
-
265
- // Then
266
- expect(() => {
267
- new AvoInspector({
268
- apiKey: "api-key-xxx",
269
- env: AvoInspectorEnv.Prod,
270
- // @ts-ignore
271
- version,
272
- });
273
- }).toThrow(error.VERSION);
274
- });
275
-
276
- test("publicEncryptionKey is forwarded to AvoNetworkCallsHandler when provided", () => {
277
- const inspectorVersion = process.env.npm_package_version || "";
278
-
279
- (AvoNetworkCallsHandler as unknown as jest.Mock).mockClear();
280
-
281
- let inspector = new AvoInspector({
282
- apiKey: "api-key-xxx",
283
- env: AvoInspectorEnv.Dev,
284
- version: "1",
285
- publicEncryptionKey: "my-public-key-123",
286
- });
287
-
288
- expect(AvoNetworkCallsHandler).toHaveBeenCalledWith(
289
- "api-key-xxx",
290
- AvoInspectorEnv.Dev,
291
- "",
292
- "1",
293
- inspectorVersion,
294
- "my-public-key-123"
295
- );
296
- });
297
-
298
- test("publicEncryptionKey is forwarded as undefined to AvoNetworkCallsHandler when not provided", () => {
299
- const inspectorVersion = process.env.npm_package_version || "";
300
-
301
- (AvoNetworkCallsHandler as unknown as jest.Mock).mockClear();
302
-
303
- let inspector = new AvoInspector({
304
- apiKey: "api-key-xxx",
305
- env: AvoInspectorEnv.Dev,
306
- version: "1",
307
- });
308
-
309
- expect(AvoNetworkCallsHandler).toHaveBeenCalledWith(
310
- "api-key-xxx",
311
- AvoInspectorEnv.Dev,
312
- "",
313
- "1",
314
- inspectorVersion,
315
- undefined
316
- );
317
- });
318
-
319
- test("warns when publicEncryptionKey is malformed in dev/staging", () => {
320
- const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
321
-
322
- new AvoInspector({
323
- apiKey: "api-key-xxx",
324
- env: AvoInspectorEnv.Dev,
325
- version: "1",
326
- publicEncryptionKey: "not-valid-hex",
327
- });
328
-
329
- expect(consoleWarnSpy).toHaveBeenCalledWith(
330
- expect.stringContaining("publicEncryptionKey does not look like a valid")
331
- );
332
- consoleWarnSpy.mockRestore();
333
- });
334
-
335
- test("does not warn when publicEncryptionKey is a valid 130-char hex key in dev/staging", () => {
336
- const consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
337
-
338
- const validKey = "04" + "ab".repeat(64); // 2 + 128 = 130 hex chars
339
-
340
- new AvoInspector({
341
- apiKey: "api-key-xxx",
342
- env: AvoInspectorEnv.Dev,
343
- version: "1",
344
- publicEncryptionKey: validKey,
345
- });
346
-
347
- expect(consoleWarnSpy).not.toHaveBeenCalled();
348
- consoleWarnSpy.mockRestore();
349
- });
350
-
351
- test("constructor works without publicEncryptionKey (backwards compatible)", () => {
352
- expect(() => {
353
- new AvoInspector({
354
- apiKey: "api-key-xxx",
355
- env: AvoInspectorEnv.Dev,
356
- version: "1",
357
- });
358
- }).not.toThrow();
359
- });
360
- });
@@ -1,72 +0,0 @@
1
- import { AvoStreamId } from "../AvoStreamId";
2
-
3
- describe("AvoStreamId", () => {
4
- let consoleWarnSpy: jest.SpyInstance;
5
-
6
- beforeEach(() => {
7
- consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation(() => {});
8
- });
9
-
10
- afterEach(() => {
11
- jest.restoreAllMocks();
12
- });
13
-
14
- test("streamId getter returns empty string by default", () => {
15
- const avoStreamId = new AvoStreamId();
16
- expect(avoStreamId.streamId).toBe("");
17
- });
18
-
19
- test("streamId getter returns the value passed to constructor", () => {
20
- const avoStreamId = new AvoStreamId("my-stream-id");
21
- expect(avoStreamId.streamId).toBe("my-stream-id");
22
- });
23
-
24
- test("streamId containing ':' logs a warning", () => {
25
- const avoStreamId = new AvoStreamId("invalid:stream:id");
26
- const id = avoStreamId.streamId;
27
-
28
- expect(consoleWarnSpy).toHaveBeenCalledWith(
29
- "[Avo Inspector] Warning: streamId contains ':' which is not supported"
30
- );
31
- expect(id).toBe("invalid:stream:id");
32
- });
33
-
34
- test("streamId without ':' does not log a warning", () => {
35
- const avoStreamId = new AvoStreamId("valid-stream-id");
36
- const id = avoStreamId.streamId;
37
-
38
- expect(consoleWarnSpy).not.toHaveBeenCalled();
39
- expect(id).toBe("valid-stream-id");
40
- });
41
-
42
- test("empty streamId does not log a warning", () => {
43
- const avoStreamId = new AvoStreamId("");
44
- const id = avoStreamId.streamId;
45
-
46
- expect(consoleWarnSpy).not.toHaveBeenCalled();
47
- expect(id).toBe("");
48
- });
49
-
50
- test("explicit undefined arg returns empty string and does not warn", () => {
51
- const avoStreamId = new AvoStreamId(undefined);
52
- const id = avoStreamId.streamId;
53
-
54
- expect(consoleWarnSpy).not.toHaveBeenCalled();
55
- expect(id).toBe("");
56
- });
57
-
58
- test("warning is only logged once per instance, not on every .streamId access", () => {
59
- const avoStreamId = new AvoStreamId("bad:id");
60
-
61
- // The warning is logged in the constructor, so it's already been called once
62
- expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
63
-
64
- // Access streamId multiple times
65
- avoStreamId.streamId;
66
- avoStreamId.streamId;
67
- avoStreamId.streamId;
68
-
69
- // Should still be only one warning total
70
- expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
71
- });
72
- });
@@ -1,191 +0,0 @@
1
- import { AvoDeduplicator } from "../AvoDeduplicator";
2
- import { deepEquals } from "../utils";
3
- import { AvoInspector } from "../AvoInspector";
4
- import { defaultOptions } from "./constants";
5
-
6
- jest
7
- .useFakeTimers()
8
- .setSystemTime(new Date('2020-01-01'));
9
-
10
- describe("Deduplicator", () => {
11
- const deduplicator = new AvoDeduplicator();
12
-
13
- const testObject = {
14
- "0": "some string",
15
- "1": [1, 2, 3],
16
- 2: [["str", true]],
17
- 3: { avo: [1.1, 2.2, 3.3] },
18
- };
19
-
20
- test(`AvoDeduplicator.deepEqual tests`, () => {
21
- const secondObject = {
22
- "0": "some string",
23
- "1": [1, 2, 3],
24
- 2: [["str", true]],
25
- 3: { avo: [1.1, 2.2, 3.3] },
26
- };
27
-
28
- expect(deepEquals(testObject, secondObject)).toBe(true);
29
-
30
- expect(deepEquals(testObject, { ...secondObject, "4": "4" })).toBe(false);
31
-
32
- expect(
33
- deepEquals(testObject, {
34
- ...secondObject,
35
- 3: { ...secondObject[3], avo: [1.1] },
36
- })
37
- ).toBe(false);
38
-
39
- expect(deepEquals(testObject, { ...secondObject, 0: "other string" })).toBe(
40
- false
41
- );
42
- });
43
-
44
- test(`Detects duplications when track in avo and then manually`, () => {
45
- const shouldRegisterFromAvo = deduplicator.shouldRegisterEvent(
46
- "Test",
47
- testObject,
48
- true
49
- );
50
- const shouldRegisterManual = deduplicator.shouldRegisterEvent(
51
- "Test",
52
- testObject,
53
- false
54
- );
55
-
56
- expect(shouldRegisterFromAvo).toBe(true);
57
- expect(shouldRegisterManual).toBe(false);
58
- });
59
-
60
- test(`Detects duplications when track manually and then in avo`, () => {
61
- const shouldRegisterManual = deduplicator.shouldRegisterEvent(
62
- "Test",
63
- testObject,
64
- false
65
- );
66
- const shouldRegisterFromAvo = deduplicator.shouldRegisterEvent(
67
- "Test",
68
- testObject,
69
- true
70
- );
71
-
72
- expect(shouldRegisterManual).toBe(true);
73
- expect(shouldRegisterFromAvo).toBe(false);
74
- });
75
-
76
- test(`Inspector deduplicates only one event when track manually, in avo and then manually again`, async () => {
77
- const inspector = new AvoInspector(defaultOptions);
78
- inspector.enableLogging(false);
79
-
80
- const manuallyTrackedSchema = await inspector.trackSchemaFromEvent(
81
- "test",
82
- testObject
83
- );
84
- // @ts-ignore
85
- const avoTrackedSchema = await inspector._avoFunctionTrackSchemaFromEvent(
86
- "test",
87
- testObject,
88
- "eventId",
89
- "eventhash"
90
- );
91
- const manuallyTrackedSchemaAgain = await inspector.trackSchemaFromEvent(
92
- "test",
93
- testObject
94
- );
95
-
96
- expect(manuallyTrackedSchema.length).toBe(4);
97
- expect(manuallyTrackedSchema.length + avoTrackedSchema.length + manuallyTrackedSchemaAgain.length).toBe(8);
98
- });
99
-
100
- test(`Inspector deduplicates only one event when track in avo, manually and then in avo again`, async () => {
101
- const inspector = new AvoInspector(defaultOptions);
102
- inspector.enableLogging(false);
103
-
104
- // @ts-ignore
105
- const avoTrackedSchema = await inspector._avoFunctionTrackSchemaFromEvent(
106
- "test",
107
- testObject,
108
- "eventId",
109
- "eventhash"
110
- );
111
- const manuallyTrackedSchema = await inspector.trackSchemaFromEvent(
112
- "test",
113
- testObject
114
- );
115
- // @ts-ignore
116
- const avoTrackedSchemaAgain = await inspector._avoFunctionTrackSchemaFromEvent(
117
- "test",
118
- testObject,
119
- "eventId",
120
- "eventhash"
121
- );
122
-
123
- expect(avoTrackedSchema.length).toBe(4);
124
- expect(manuallyTrackedSchema.length).toBe(0);
125
- expect(avoTrackedSchemaAgain.length).toBe(4);
126
- });
127
-
128
- test(`Allows two same manual events in a row`, async () => {
129
- const inspector = new AvoInspector(defaultOptions);
130
- inspector.enableLogging(false);
131
-
132
- const manuallyTrackedSchema = await inspector.trackSchemaFromEvent(
133
- "test",
134
- testObject
135
- );
136
- const manuallyTrackedSchemaAgain = await inspector.trackSchemaFromEvent(
137
- "test",
138
- testObject
139
- );
140
-
141
- expect(manuallyTrackedSchema.length).toBe(4);
142
- expect(manuallyTrackedSchemaAgain.length).toBe(4);
143
- });
144
-
145
- test(`Allows two same avo events in a row`, async () => {
146
- const inspector = new AvoInspector(defaultOptions);
147
- inspector.enableLogging(false);
148
-
149
- // @ts-ignore
150
- const avoTrackedSchema = await inspector._avoFunctionTrackSchemaFromEvent(
151
- "test",
152
- testObject,
153
- "eventId",
154
- "eventhash"
155
- );
156
- // @ts-ignore
157
- const avoTrackedSchemaAgain = await inspector._avoFunctionTrackSchemaFromEvent(
158
- "test",
159
- testObject,
160
- "eventId",
161
- "eventhash"
162
- );
163
-
164
- expect(avoTrackedSchema.length).toBe(4);
165
- expect(avoTrackedSchemaAgain.length).toBe(4);
166
- });
167
-
168
- test(`Does not deduplicate if more than 500ms pass`, () => {
169
- const shouldRegisterFromAvo = deduplicator.shouldRegisterEvent(
170
- "Test",
171
- testObject,
172
- true
173
- );
174
- const now = new Date();
175
- const dateNowSpy = jest
176
- .spyOn(Date, "now")
177
- .mockImplementation(() =>
178
- now.setMilliseconds(now.getMilliseconds() + 501)
179
- );
180
- const shouldRegisterManual = deduplicator.shouldRegisterEvent(
181
- "Test",
182
- testObject,
183
- false
184
- );
185
-
186
- expect(shouldRegisterFromAvo).toBe(true);
187
- expect(shouldRegisterManual).toBe(true);
188
-
189
- dateNowSpy.mockRestore();
190
- });
191
- });