avo-inspector 2.2.0 → 2.2.2-alpha
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.
- package/CHANGELOG.md +34 -1
- package/README.md +95 -0
- package/bin/avo-inspector.js +97 -0
- package/dist/AvoBatcher.d.ts +4 -2
- package/dist/AvoEncryption.d.ts +33 -0
- package/dist/AvoInspector.d.ts +31 -3
- package/dist/AvoNetworkCallsHandler.d.ts +28 -3
- package/dist/AvoSchemaParser.d.ts +12 -1
- package/dist/browser.js.LICENSE.txt +5 -0
- package/dist/eventSpec/AvoEventSpecCache.d.ts +73 -0
- package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +109 -0
- package/dist/eventSpec/AvoEventSpecFetcher.d.ts +54 -0
- package/dist/eventSpec/EventValidator.d.ts +90 -0
- package/dist/eventSpec/cache.d.ts +73 -0
- package/dist/eventSpec/index.d.ts +4 -0
- package/dist/eventSpec/types.d.ts +74 -0
- package/dist/index.js +2 -1
- package/dist/index.js.LICENSE.txt +5 -0
- package/dist-browser/AvoAnonymousId.d.ts +26 -0
- package/dist-browser/AvoBatcher.d.ts +26 -0
- package/dist-browser/AvoDeduplicator.d.ts +20 -0
- package/dist-browser/AvoEncryption.d.ts +33 -0
- package/dist-browser/AvoGuid.d.ts +3 -0
- package/dist-browser/AvoInspector.d.ts +78 -0
- package/dist-browser/AvoInspectorEnv.d.ts +7 -0
- package/dist-browser/AvoNetworkCallsHandler.d.ts +74 -0
- package/dist-browser/AvoSchemaParser.d.ts +20 -0
- package/dist-browser/AvoStorage.d.ts +22 -0
- package/dist-browser/__mocks__/xhr.d.ts +12 -0
- package/dist-browser/__mocks__/xhrError.d.ts +12 -0
- package/dist-browser/__tests__/AnonymousId_test.d.ts +1 -0
- package/dist-browser/__tests__/AvoEncryption_test.d.ts +1 -0
- package/dist-browser/__tests__/AvoInspectorEventSpec_test.d.ts +1 -0
- package/dist-browser/__tests__/AvoInspector_test.d.ts +1 -0
- package/dist-browser/__tests__/BatcherPublic_test.d.ts +1 -0
- package/dist-browser/__tests__/Batcher_test.d.ts +1 -0
- package/dist-browser/__tests__/Deduplicator_test.d.ts +1 -0
- package/dist-browser/__tests__/EncryptedPropertyTracking_test.d.ts +1 -0
- package/dist-browser/__tests__/EventSpecCache_test.d.ts +1 -0
- package/dist-browser/__tests__/EventSpecFetcher_test.d.ts +1 -0
- package/dist-browser/__tests__/EventValidator_test.d.ts +1 -0
- package/dist-browser/__tests__/NetworkCallsHandler_test.d.ts +1 -0
- package/dist-browser/__tests__/Parsing_test.d.ts +1 -0
- package/dist-browser/__tests__/Storage_test.d.ts +1 -0
- package/dist-browser/__tests__/ValidationIntegration_test.d.ts +1 -0
- package/dist-browser/__tests__/constants.d.ts +36 -0
- package/dist-browser/__tests__/helpers/encryptionHelpers.d.ts +13 -0
- package/dist-browser/__tests__/helpers/mockFactories.d.ts +49 -0
- package/dist-browser/eventSpec/AvoEventSpecCache.d.ts +73 -0
- package/dist-browser/eventSpec/AvoEventSpecFetchTypes.d.ts +109 -0
- package/dist-browser/eventSpec/AvoEventSpecFetcher.d.ts +55 -0
- package/dist-browser/eventSpec/EventValidator.d.ts +90 -0
- package/dist-browser/eventSpec/index.d.ts +4 -0
- package/dist-browser/index.d.ts +2 -0
- package/dist-browser/utils.d.ts +3 -0
- package/dist-native/AvoBatcher.d.ts +24 -0
- package/dist-native/AvoBatcher.js +82 -0
- package/dist-native/AvoDeduplicator.d.ts +36 -0
- package/dist-native/AvoDeduplicator.js +142 -0
- package/dist-native/AvoGuid.d.ts +3 -0
- package/dist-native/AvoGuid.js +14 -0
- package/dist-native/AvoInspector.d.ts +52 -0
- package/dist-native/AvoInspector.js +220 -0
- package/dist-native/AvoInspectorEnv.d.ts +7 -0
- package/dist-native/AvoInspectorEnv.js +8 -0
- package/dist-native/AvoInstallationId.d.ts +5 -0
- package/dist-native/AvoInstallationId.js +36 -0
- package/dist-native/AvoNetworkCallsHandler.d.ts +48 -0
- package/dist-native/AvoNetworkCallsHandler.js +142 -0
- package/dist-native/AvoSchemaParser.d.ts +11 -0
- package/dist-native/AvoSchemaParser.js +95 -0
- package/dist-native/AvoSessionTracker.d.ts +15 -0
- package/dist-native/AvoSessionTracker.js +104 -0
- package/dist-native/AvoStorage.d.ts +22 -0
- package/dist-native/AvoStorage.js +336 -0
- package/dist-native/__mocks__/xhr.d.ts +12 -0
- package/dist-native/__mocks__/xhr.js +14 -0
- package/dist-native/__mocks__/xhrError.d.ts +12 -0
- package/dist-native/__mocks__/xhrError.js +14 -0
- package/dist-native/__tests__/AvoInspector.d.ts +1 -0
- package/dist-native/__tests__/AvoInspector.js +207 -0
- package/dist-native/__tests__/Batcher.d.ts +1 -0
- package/dist-native/__tests__/Batcher.js +280 -0
- package/dist-native/__tests__/BatcherPublic.d.ts +1 -0
- package/dist-native/__tests__/BatcherPublic.js +82 -0
- package/dist-native/__tests__/Deduplicator.d.ts +1 -0
- package/dist-native/__tests__/Deduplicator.js +111 -0
- package/dist-native/__tests__/InstallationId.d.ts +1 -0
- package/dist-native/__tests__/InstallationId.js +40 -0
- package/dist-native/__tests__/NetworkCallsHandler.d.ts +1 -0
- package/dist-native/__tests__/NetworkCallsHandler.js +132 -0
- package/dist-native/__tests__/Parsing.d.ts +1 -0
- package/dist-native/__tests__/Parsing.js +115 -0
- package/dist-native/__tests__/Sessions.d.ts +1 -0
- package/dist-native/__tests__/Sessions.js +179 -0
- package/dist-native/__tests__/Storage.d.ts +1 -0
- package/dist-native/__tests__/Storage.js +173 -0
- package/dist-native/__tests__/constants.d.ts +36 -0
- package/dist-native/__tests__/constants.js +47 -0
- package/dist-native/index.d.ts +2 -0
- package/dist-native/index.js +7 -0
- package/dist-native/utils.d.ts +3 -0
- package/dist-native/utils.js +42 -0
- package/jest.config.js +6 -0
- package/package.json +8 -2
- package/webpack.browserConfig.js +1 -1
- package/webpack.config.js +1 -1
- package/.claude/settings.local.json +0 -9
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
var AvoBatcher_1 = require("../AvoBatcher");
|
|
60
|
+
var AvoInspector_1 = require("../AvoInspector");
|
|
61
|
+
var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
|
|
62
|
+
var AvoStorage_1 = require("../AvoStorage");
|
|
63
|
+
var constants_1 = require("./constants");
|
|
64
|
+
var inspectorVersion = process.env.npm_package_version || "";
|
|
65
|
+
describe("Batcher", function () {
|
|
66
|
+
var checkBatchSpy;
|
|
67
|
+
var inspectorCallSpy;
|
|
68
|
+
var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version, shouldLog = constants_1.defaultOptions.shouldLog;
|
|
69
|
+
var storage = new AvoStorage_1.AvoStorage(shouldLog);
|
|
70
|
+
var networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
|
|
71
|
+
beforeAll(function () {
|
|
72
|
+
checkBatchSpy = jest.spyOn(AvoBatcher_1.AvoBatcher.prototype, "checkIfBatchNeedsToBeSent");
|
|
73
|
+
inspectorCallSpy = jest.spyOn(AvoNetworkCallsHandler_1.AvoNetworkCallsHandler.prototype, "callInspectorWithBatchBody");
|
|
74
|
+
});
|
|
75
|
+
afterEach(function () {
|
|
76
|
+
jest.clearAllMocks();
|
|
77
|
+
AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
78
|
+
});
|
|
79
|
+
test("handleSessionStarted adds event to storage", function () {
|
|
80
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
81
|
+
inspector.enableLogging(false);
|
|
82
|
+
inspector.avoBatcher.handleSessionStarted();
|
|
83
|
+
var events = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
84
|
+
expect(events).not.toBeNull();
|
|
85
|
+
if (events !== null) {
|
|
86
|
+
expect(events.length).toEqual(1);
|
|
87
|
+
expect(events[0].type === constants_1.networkCallType.SESSION_STARTED);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
test("handleTrackSchema adds event to storage", function () {
|
|
91
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
92
|
+
inspector.enableLogging(false);
|
|
93
|
+
AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
94
|
+
inspector.avoBatcher.handleSessionStarted();
|
|
95
|
+
inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
|
|
96
|
+
var events = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
97
|
+
expect(events).not.toBeNull();
|
|
98
|
+
if (events !== null) {
|
|
99
|
+
expect(events.length).toEqual(2);
|
|
100
|
+
expect(events[0].type === constants_1.networkCallType.SESSION_STARTED);
|
|
101
|
+
expect(events[1].type === constants_1.networkCallType.EVENT);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
test("handleTrackSchema adds event to storage", function () {
|
|
105
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
106
|
+
inspector.enableLogging(false);
|
|
107
|
+
AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
108
|
+
inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
|
|
109
|
+
var events = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
110
|
+
expect(events).not.toBeNull();
|
|
111
|
+
if (events !== null) {
|
|
112
|
+
expect(events.length).toEqual(1);
|
|
113
|
+
expect(events[0].type === constants_1.networkCallType.EVENT);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
test("checkIfBatchNeedsToBeSent is called on Batcher initialization", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
|
+
var event;
|
|
118
|
+
return __generator(this, function (_a) {
|
|
119
|
+
switch (_a.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
event = networkHandler.bodyForEventSchemaCall("name", [
|
|
122
|
+
{ propertyName: "prop0", propertyType: "string" },
|
|
123
|
+
], "testEventId", "testEventHash");
|
|
124
|
+
storage.setItem(AvoBatcher_1.AvoBatcher.cacheKey, [event]);
|
|
125
|
+
return [4 /*yield*/, new AvoBatcher_1.AvoBatcher(networkHandler)];
|
|
126
|
+
case 1:
|
|
127
|
+
_a.sent();
|
|
128
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(1);
|
|
129
|
+
return [2 /*return*/];
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}); });
|
|
133
|
+
test("checkIfBatchNeedsToBeSent is called on handleSessionStarted", function () {
|
|
134
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
135
|
+
inspector.enableLogging(false);
|
|
136
|
+
inspector.avoBatcher.handleSessionStarted();
|
|
137
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(1);
|
|
138
|
+
});
|
|
139
|
+
test("checkIfBatchNeedsToBeSent is called on handleTrackSchema", function () {
|
|
140
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
141
|
+
inspector.enableLogging(false);
|
|
142
|
+
inspector.avoBatcher.handleSessionStarted();
|
|
143
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(1);
|
|
144
|
+
});
|
|
145
|
+
test("Batcher saves events produced by AvoNetworkCallsHandler", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
146
|
+
var schemaEvent, sessionEvent, inspector, events;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
149
|
+
schemaEvent = networkHandler.bodyForEventSchemaCall("name", [
|
|
150
|
+
{ propertyName: "prop0", propertyType: "string" },
|
|
151
|
+
], "testEventId", "testEventHash");
|
|
152
|
+
sessionEvent = networkHandler.bodyForSessionStartedCall();
|
|
153
|
+
inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
154
|
+
inspector.enableLogging(false);
|
|
155
|
+
inspector.avoBatcher.handleTrackSchema("name", [
|
|
156
|
+
{ propertyName: "prop0", propertyType: "string" },
|
|
157
|
+
], "testEventId", "testEventHash");
|
|
158
|
+
inspector.avoBatcher.handleSessionStarted();
|
|
159
|
+
events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
160
|
+
expect(events).not.toBeNull();
|
|
161
|
+
if (events != null) {
|
|
162
|
+
expect(events[0]).not.toBe(schemaEvent);
|
|
163
|
+
expect(__assign(__assign({}, events[0]), { messageId: undefined, createdAt: undefined })).toStrictEqual(__assign(__assign({}, schemaEvent), { messageId: undefined, createdAt: undefined }));
|
|
164
|
+
expect(events[1]).not.toBe(sessionEvent);
|
|
165
|
+
expect(__assign(__assign({}, events[1]), { messageId: undefined, createdAt: undefined })).toStrictEqual(__assign(__assign({}, sessionEvent), { messageId: undefined, createdAt: undefined }));
|
|
166
|
+
}
|
|
167
|
+
return [2 /*return*/];
|
|
168
|
+
});
|
|
169
|
+
}); });
|
|
170
|
+
test("Events are retrieved from Storage on init", function () {
|
|
171
|
+
var getItemAsyncSpy = jest.spyOn(AvoStorage_1.AvoStorage.prototype, "getItemAsync");
|
|
172
|
+
new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
173
|
+
expect(getItemAsyncSpy).toHaveBeenCalledTimes(1);
|
|
174
|
+
expect(getItemAsyncSpy).toHaveBeenCalledWith(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
175
|
+
});
|
|
176
|
+
test("Batch is not sent with batchSize - 1 events", function () {
|
|
177
|
+
var eventCount = AvoInspector_1.AvoInspector.batchSize - 1;
|
|
178
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
179
|
+
inspector.enableLogging(false);
|
|
180
|
+
__spreadArray([], Array(eventCount), true).forEach(function () {
|
|
181
|
+
inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
|
|
182
|
+
});
|
|
183
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(eventCount);
|
|
184
|
+
expect(inspectorCallSpy).not.toHaveBeenCalled();
|
|
185
|
+
});
|
|
186
|
+
test("Batch is sent when event count matches batchSize", function () {
|
|
187
|
+
var eventCount = AvoInspector_1.AvoInspector.batchSize;
|
|
188
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
189
|
+
inspector.enableLogging(false);
|
|
190
|
+
__spreadArray([], Array(eventCount), true).forEach(function () {
|
|
191
|
+
inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
|
|
192
|
+
});
|
|
193
|
+
var events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
194
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(eventCount);
|
|
195
|
+
expect(inspectorCallSpy).toHaveBeenCalledTimes(1);
|
|
196
|
+
expect(inspectorCallSpy).toHaveBeenCalledWith(events, expect.any(Function));
|
|
197
|
+
});
|
|
198
|
+
test("Batch is sent only one time for batchSize + 1 events", function () {
|
|
199
|
+
var eventCount = AvoInspector_1.AvoInspector.batchSize + 1;
|
|
200
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
201
|
+
inspector.enableLogging(false);
|
|
202
|
+
var events = [];
|
|
203
|
+
__spreadArray([], Array(eventCount), true).forEach(function (_, i) {
|
|
204
|
+
inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
|
|
205
|
+
if (i === AvoInspector_1.AvoInspector.batchSize - 1) {
|
|
206
|
+
events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(eventCount);
|
|
210
|
+
expect(inspectorCallSpy).toHaveBeenCalledTimes(1);
|
|
211
|
+
expect(inspectorCallSpy).toHaveBeenCalledWith(events, expect.any(Function));
|
|
212
|
+
events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
213
|
+
expect(events.length).toBe(1);
|
|
214
|
+
});
|
|
215
|
+
test("Batch is not sent if batchFlushSeconds not exceeded", function () {
|
|
216
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
217
|
+
inspector.enableLogging(false);
|
|
218
|
+
var now = new Date();
|
|
219
|
+
var dateNowSpy = jest
|
|
220
|
+
.spyOn(Date, "now")
|
|
221
|
+
.mockImplementation(function () {
|
|
222
|
+
return now.setMilliseconds(now.getMilliseconds() + (AvoInspector_1.AvoInspector.batchFlushSeconds - 1) * 1000);
|
|
223
|
+
});
|
|
224
|
+
inspector.avoBatcher.handleTrackSchema("event name", [], null, null);
|
|
225
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(1);
|
|
226
|
+
expect(inspectorCallSpy).not.toHaveBeenCalled();
|
|
227
|
+
dateNowSpy.mockRestore();
|
|
228
|
+
});
|
|
229
|
+
test("Batch is sent if batchFlushSeconds exceeded", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
230
|
+
var inspector, now, dateNowSpy, events;
|
|
231
|
+
return __generator(this, function (_a) {
|
|
232
|
+
switch (_a.label) {
|
|
233
|
+
case 0:
|
|
234
|
+
inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
235
|
+
inspector.enableLogging(false);
|
|
236
|
+
now = new Date();
|
|
237
|
+
dateNowSpy = jest
|
|
238
|
+
.spyOn(Date, "now")
|
|
239
|
+
.mockImplementation(function () {
|
|
240
|
+
return now.setMilliseconds(now.getMilliseconds() + AvoInspector_1.AvoInspector.batchFlushSeconds * 1000);
|
|
241
|
+
});
|
|
242
|
+
return [4 /*yield*/, inspector.avoBatcher.handleTrackSchema("event name", [], null, null)];
|
|
243
|
+
case 1:
|
|
244
|
+
_a.sent();
|
|
245
|
+
events = storage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
246
|
+
expect(checkBatchSpy).toHaveBeenCalledTimes(1);
|
|
247
|
+
expect(inspectorCallSpy).toHaveBeenCalledTimes(1);
|
|
248
|
+
expect(inspectorCallSpy).toHaveBeenCalledWith(events, expect.any(Function));
|
|
249
|
+
dateNowSpy.mockRestore();
|
|
250
|
+
return [2 /*return*/];
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}); });
|
|
254
|
+
test("Only latest 1000 events are stored in the storage", function (done) {
|
|
255
|
+
AvoInspector_1.AvoInspector.avoStorage.removeItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
256
|
+
var eventLimit = 1000;
|
|
257
|
+
var events = [];
|
|
258
|
+
for (var i = 0; i < eventLimit + 1; i++) {
|
|
259
|
+
events.push(networkHandler.bodyForEventSchemaCall("event-name-".concat(i), [
|
|
260
|
+
{ propertyName: "prop0", propertyType: "string" },
|
|
261
|
+
], null, null));
|
|
262
|
+
}
|
|
263
|
+
AvoInspector_1.AvoInspector.avoStorage.setItem(AvoBatcher_1.AvoBatcher.cacheKey, events);
|
|
264
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
265
|
+
inspector.enableLogging(false);
|
|
266
|
+
setTimeout(function () {
|
|
267
|
+
var setItemsSpy = jest.spyOn(AvoStorage_1.AvoStorage.prototype, "setItem");
|
|
268
|
+
inspector.avoBatcher.handleSessionStarted();
|
|
269
|
+
var savedEvents = AvoInspector_1.AvoInspector.avoStorage.getItem(AvoBatcher_1.AvoBatcher.cacheKey);
|
|
270
|
+
expect(savedEvents).not.toBeNull();
|
|
271
|
+
if (savedEvents !== null && savedEvents.length > 0) {
|
|
272
|
+
events.push(savedEvents[savedEvents.length - 1]);
|
|
273
|
+
}
|
|
274
|
+
events.splice(0, 2);
|
|
275
|
+
expect(setItemsSpy).toHaveBeenCalledTimes(1);
|
|
276
|
+
expect(setItemsSpy).toHaveBeenCalledWith(AvoBatcher_1.AvoBatcher.cacheKey, events);
|
|
277
|
+
done();
|
|
278
|
+
}, 1000);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var AvoBatcher_1 = require("../AvoBatcher");
|
|
4
|
+
var AvoInspector_1 = require("../AvoInspector");
|
|
5
|
+
var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
var inspectorVersion = process.env.npm_package_version || "";
|
|
8
|
+
jest.mock("../AvoBatcher");
|
|
9
|
+
jest.mock("../AvoStorage");
|
|
10
|
+
describe("Batcher", function () {
|
|
11
|
+
var inspector;
|
|
12
|
+
var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version;
|
|
13
|
+
var networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
|
|
14
|
+
beforeAll(function () {
|
|
15
|
+
inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
16
|
+
inspector.enableLogging(false);
|
|
17
|
+
});
|
|
18
|
+
afterEach(function () {
|
|
19
|
+
jest.clearAllMocks();
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
inspector.avoDeduplicator._clearEvents();
|
|
22
|
+
});
|
|
23
|
+
test("Batcher is initialized on Inspector init", function () {
|
|
24
|
+
expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledTimes(1);
|
|
25
|
+
expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledWith(networkHandler);
|
|
26
|
+
});
|
|
27
|
+
test("handleTrackSchema is called on trackSchema", function () {
|
|
28
|
+
var eventName = "event name";
|
|
29
|
+
var schema = [
|
|
30
|
+
{
|
|
31
|
+
propertyName: "prop0",
|
|
32
|
+
propertyType: "string",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
propertyName: "prop1",
|
|
36
|
+
propertyType: "string",
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
inspector.trackSchema(eventName, schema);
|
|
40
|
+
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
|
|
41
|
+
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, null, null);
|
|
42
|
+
});
|
|
43
|
+
test("handleTrackSchema is called on trackSchemaFromEvent", function () {
|
|
44
|
+
var eventName = "event name";
|
|
45
|
+
var properties = {
|
|
46
|
+
prop0: "",
|
|
47
|
+
prop2: false,
|
|
48
|
+
prop3: 0,
|
|
49
|
+
prop4: 0.0,
|
|
50
|
+
};
|
|
51
|
+
var schema = inspector.extractSchema(properties);
|
|
52
|
+
inspector.trackSchemaFromEvent(eventName, properties);
|
|
53
|
+
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
|
|
54
|
+
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, null, null);
|
|
55
|
+
});
|
|
56
|
+
test("handleTrackSchema is called on _avoFunctionTrackSchemaFromEvent", function () {
|
|
57
|
+
var eventName = "event name";
|
|
58
|
+
var properties = {
|
|
59
|
+
prop0: "",
|
|
60
|
+
prop2: false,
|
|
61
|
+
prop3: 0,
|
|
62
|
+
prop4: 0.0,
|
|
63
|
+
};
|
|
64
|
+
var eventId = "testId";
|
|
65
|
+
var eventHash = "testHash";
|
|
66
|
+
var schema = inspector.extractSchema(properties);
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
inspector._avoFunctionTrackSchemaFromEvent(eventName, properties, eventId, eventHash);
|
|
69
|
+
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
|
|
70
|
+
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, eventId, eventHash);
|
|
71
|
+
});
|
|
72
|
+
test("batchSize is updated", function () {
|
|
73
|
+
var count = 10;
|
|
74
|
+
inspector.setBatchSize(count);
|
|
75
|
+
expect(AvoInspector_1.AvoInspector.batchSize).toBe(count);
|
|
76
|
+
});
|
|
77
|
+
test("batchFlushSeconds is updated", function () {
|
|
78
|
+
var seconds = 10;
|
|
79
|
+
inspector.setBatchFlushSeconds(seconds);
|
|
80
|
+
expect(AvoInspector_1.AvoInspector.batchFlushSeconds).toBe(seconds);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var AvoDeduplicator_1 = require("../AvoDeduplicator");
|
|
15
|
+
var utils_1 = require("../utils");
|
|
16
|
+
var AvoSchemaParser_1 = require("../AvoSchemaParser");
|
|
17
|
+
var AvoInspector_1 = require("../AvoInspector");
|
|
18
|
+
var constants_1 = require("./constants");
|
|
19
|
+
describe("Deduplicator", function () {
|
|
20
|
+
var deduplicator = new AvoDeduplicator_1.AvoDeduplicator();
|
|
21
|
+
var testObject = {
|
|
22
|
+
"0": "some string",
|
|
23
|
+
"1": [1, 2, 3],
|
|
24
|
+
2: [["str", true]],
|
|
25
|
+
3: { avo: [1.1, 2.2, 3.3] }
|
|
26
|
+
};
|
|
27
|
+
test("AvoDeduplicator.deepEqual tests", function () {
|
|
28
|
+
var secondObject = {
|
|
29
|
+
"0": "some string",
|
|
30
|
+
"1": [1, 2, 3],
|
|
31
|
+
2: [["str", true]],
|
|
32
|
+
3: { avo: [1.1, 2.2, 3.3] }
|
|
33
|
+
};
|
|
34
|
+
expect((0, utils_1.deepEquals)(testObject, secondObject)).toBe(true);
|
|
35
|
+
expect((0, utils_1.deepEquals)(testObject, __assign(__assign({}, secondObject), { "4": "4" }))).toBe(false);
|
|
36
|
+
expect((0, utils_1.deepEquals)(testObject, __assign(__assign({}, secondObject), { 3: __assign(__assign({}, secondObject[3]), { avo: [1.1] }) }))).toBe(false);
|
|
37
|
+
expect((0, utils_1.deepEquals)(testObject, __assign(__assign({}, secondObject), { 0: "other string" }))).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
test("Detects duplications when track in avo and then manually", function () {
|
|
40
|
+
var shouldRegisterFromAvo = deduplicator.shouldRegisterEvent("Test", testObject, true);
|
|
41
|
+
var shouldRegisterManual = deduplicator.shouldRegisterEvent("Test", testObject, false);
|
|
42
|
+
expect(shouldRegisterFromAvo).toBe(true);
|
|
43
|
+
expect(shouldRegisterManual).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
test("Detects duplications when track manually and then in avo", function () {
|
|
46
|
+
var shouldRegisterManual = deduplicator.shouldRegisterEvent("Test", testObject, false);
|
|
47
|
+
var shouldRegisterFromAvo = deduplicator.shouldRegisterEvent("Test", testObject, true);
|
|
48
|
+
expect(shouldRegisterManual).toBe(true);
|
|
49
|
+
expect(shouldRegisterFromAvo).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
test("Detects duplications when track in avo and then schema manually", function () {
|
|
52
|
+
var shouldRegisterFromAvo = deduplicator.shouldRegisterEvent("Test", testObject, true);
|
|
53
|
+
var shouldRegisterSchemaManual = deduplicator.shouldRegisterSchemaFromManually("Test", AvoSchemaParser_1.AvoSchemaParser.extractSchema(testObject));
|
|
54
|
+
expect(shouldRegisterFromAvo).toBe(true);
|
|
55
|
+
expect(shouldRegisterSchemaManual).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
test("Inspector deduplicates only one event when track manually, in avo and then manually again", function () {
|
|
58
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
59
|
+
inspector.enableLogging(false);
|
|
60
|
+
var manuallyTrackedSchema = inspector.trackSchemaFromEvent("test", testObject);
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
var avoTrackedSchema = inspector._avoFunctionTrackSchemaFromEvent("test", testObject, "eventId", "eventhash");
|
|
63
|
+
var manuallyTrackedSchemaAgain = inspector.trackSchemaFromEvent("test", testObject);
|
|
64
|
+
expect(manuallyTrackedSchema.length).toBe(4);
|
|
65
|
+
expect(avoTrackedSchema.length).toBe(0);
|
|
66
|
+
expect(manuallyTrackedSchemaAgain.length).toBe(4);
|
|
67
|
+
});
|
|
68
|
+
test("Inspector deduplicates only one event when track in avo, manually and then in avo again", function () {
|
|
69
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
70
|
+
inspector.enableLogging(false);
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
var avoTrackedSchema = inspector._avoFunctionTrackSchemaFromEvent("test", testObject, "eventId", "eventhash");
|
|
73
|
+
var manuallyTrackedSchema = inspector.trackSchemaFromEvent("test", testObject);
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
var avoTrackedSchemaAgain = inspector._avoFunctionTrackSchemaFromEvent("test", testObject, "eventId", "eventhash");
|
|
76
|
+
expect(avoTrackedSchema.length).toBe(4);
|
|
77
|
+
expect(manuallyTrackedSchema.length).toBe(0);
|
|
78
|
+
expect(avoTrackedSchemaAgain.length).toBe(4);
|
|
79
|
+
});
|
|
80
|
+
test("Allows two same manual events in a row", function () {
|
|
81
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
82
|
+
inspector.enableLogging(false);
|
|
83
|
+
var manuallyTrackedSchema = inspector.trackSchemaFromEvent("test", testObject);
|
|
84
|
+
var manuallyTrackedSchemaAgain = inspector.trackSchemaFromEvent("test", testObject);
|
|
85
|
+
expect(manuallyTrackedSchema.length).toBe(4);
|
|
86
|
+
expect(manuallyTrackedSchemaAgain.length).toBe(4);
|
|
87
|
+
});
|
|
88
|
+
test("Allows two same avo events in a row", function () {
|
|
89
|
+
var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
90
|
+
inspector.enableLogging(false);
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
var avoTrackedSchema = inspector._avoFunctionTrackSchemaFromEvent("test", testObject, "eventId", "eventhash");
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
var avoTrackedSchemaAgain = inspector._avoFunctionTrackSchemaFromEvent("test", testObject, "eventId", "eventhash");
|
|
95
|
+
expect(avoTrackedSchema.length).toBe(4);
|
|
96
|
+
expect(avoTrackedSchemaAgain.length).toBe(4);
|
|
97
|
+
});
|
|
98
|
+
test("Does not deduplicate if more than 300ms pass", function () {
|
|
99
|
+
var shouldRegisterFromAvo = deduplicator.shouldRegisterEvent("Test", testObject, true);
|
|
100
|
+
var now = new Date();
|
|
101
|
+
var dateNowSpy = jest
|
|
102
|
+
.spyOn(Date, "now")
|
|
103
|
+
.mockImplementation(function () {
|
|
104
|
+
return now.setMilliseconds(now.getMilliseconds() + 301);
|
|
105
|
+
});
|
|
106
|
+
var shouldRegisterManual = deduplicator.shouldRegisterEvent("Test", testObject, false);
|
|
107
|
+
expect(shouldRegisterFromAvo).toBe(true);
|
|
108
|
+
expect(shouldRegisterManual).toBe(true);
|
|
109
|
+
dateNowSpy.mockRestore();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var AvoInstallationId_1 = require("../AvoInstallationId");
|
|
4
|
+
var AvoStorage_1 = require("../AvoStorage");
|
|
5
|
+
var AvoInspector_1 = require("../AvoInspector");
|
|
6
|
+
var constants_1 = require("../__tests__/constants");
|
|
7
|
+
describe("InstallationId", function () {
|
|
8
|
+
var storage = new AvoStorage_1.AvoStorage(constants_1.defaultOptions.shouldLog);
|
|
9
|
+
beforeAll(function () {
|
|
10
|
+
new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
|
|
11
|
+
});
|
|
12
|
+
test("cacheKey equal to \"AvoInstallationId\"", function () {
|
|
13
|
+
expect(AvoInstallationId_1.AvoInstallationId.cacheKey).toEqual("AvoInstallationId");
|
|
14
|
+
});
|
|
15
|
+
test("Sets installationId on AvoInspector init", function () {
|
|
16
|
+
// Given
|
|
17
|
+
// When
|
|
18
|
+
var installationId = AvoInstallationId_1.AvoInstallationId.getInstallationId();
|
|
19
|
+
// Then
|
|
20
|
+
expect(installationId).not.toBeNull();
|
|
21
|
+
});
|
|
22
|
+
test("Creates installation id if not present", function () {
|
|
23
|
+
// Given
|
|
24
|
+
storage.removeItem(AvoInstallationId_1.AvoInstallationId.cacheKey);
|
|
25
|
+
// When
|
|
26
|
+
var installationId = AvoInstallationId_1.AvoInstallationId.getInstallationId();
|
|
27
|
+
// Then
|
|
28
|
+
expect(installationId).not.toBeNull();
|
|
29
|
+
});
|
|
30
|
+
test("Reuses installation id if present", function () {
|
|
31
|
+
// Given
|
|
32
|
+
var newId = "test-installation-id";
|
|
33
|
+
storage.setItem(AvoInstallationId_1.AvoInstallationId.cacheKey, "test-installation-id");
|
|
34
|
+
AvoInstallationId_1.AvoInstallationId.installationId = null;
|
|
35
|
+
// When
|
|
36
|
+
var installationId = AvoInstallationId_1.AvoInstallationId.getInstallationId();
|
|
37
|
+
// Then
|
|
38
|
+
expect(installationId).toBe(newId);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var AvoGuid_1 = require("../AvoGuid");
|
|
15
|
+
var AvoInstallationId_1 = require("../AvoInstallationId");
|
|
16
|
+
var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
|
|
17
|
+
var AvoSessionTracker_1 = require("../AvoSessionTracker");
|
|
18
|
+
var xhr_1 = require("../__mocks__/xhr");
|
|
19
|
+
var constants_1 = require("./constants");
|
|
20
|
+
var inspectorVersion = process.env.npm_package_version || "";
|
|
21
|
+
describe("NetworkCallsHandler", function () {
|
|
22
|
+
var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version;
|
|
23
|
+
var appName = "";
|
|
24
|
+
var networkHandler;
|
|
25
|
+
var baseBody;
|
|
26
|
+
var customCallback = jest.fn();
|
|
27
|
+
var now = new Date();
|
|
28
|
+
beforeAll(function () {
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
jest.spyOn(global, "Date").mockImplementation(function () { return now; });
|
|
31
|
+
jest
|
|
32
|
+
.spyOn(AvoInstallationId_1.AvoInstallationId, "getInstallationId")
|
|
33
|
+
.mockImplementation(function () { return constants_1.mockedReturns.INSTALLATION_ID; });
|
|
34
|
+
jest
|
|
35
|
+
.spyOn(AvoGuid_1.default, "newGuid")
|
|
36
|
+
.mockImplementation(function () { return constants_1.mockedReturns.GUID; });
|
|
37
|
+
jest
|
|
38
|
+
.spyOn(AvoSessionTracker_1.AvoSessionTracker, "sessionId", "get")
|
|
39
|
+
.mockImplementation(function () { return constants_1.mockedReturns.SESSION_ID; });
|
|
40
|
+
networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
|
|
41
|
+
baseBody = {
|
|
42
|
+
apiKey: apiKey,
|
|
43
|
+
appName: appName,
|
|
44
|
+
appVersion: version,
|
|
45
|
+
libVersion: inspectorVersion,
|
|
46
|
+
env: env,
|
|
47
|
+
libPlatform: "web",
|
|
48
|
+
messageId: constants_1.mockedReturns.GUID,
|
|
49
|
+
trackingId: constants_1.mockedReturns.INSTALLATION_ID,
|
|
50
|
+
createdAt: new Date().toISOString(),
|
|
51
|
+
sessionId: constants_1.mockedReturns.SESSION_ID,
|
|
52
|
+
samplingRate: 1.0,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
afterEach(function () {
|
|
56
|
+
jest.clearAllMocks();
|
|
57
|
+
});
|
|
58
|
+
test("bodyForSessionStartedCall returns base body + session started body used for session started", function () {
|
|
59
|
+
var body = networkHandler.bodyForSessionStartedCall();
|
|
60
|
+
expect(body).toEqual(__assign(__assign({}, baseBody), { type: "sessionStarted" }));
|
|
61
|
+
});
|
|
62
|
+
test("bodyForEventSchemaCall returns base body + event schema used for event sending from non avo functions", function () {
|
|
63
|
+
var eventName = "event name";
|
|
64
|
+
var eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
65
|
+
var body = networkHandler.bodyForEventSchemaCall(eventName, eventProperties, null, null);
|
|
66
|
+
expect(body).toEqual(__assign(__assign({}, baseBody), { type: "event", eventName: eventName, eventProperties: eventProperties, avoFunction: false, eventId: null, eventHash: null }));
|
|
67
|
+
});
|
|
68
|
+
test("bodyForEventSchemaCall returns base body + event schema used for event sending from avo functions", function () {
|
|
69
|
+
var eventName = "event name";
|
|
70
|
+
var eventId = "event id";
|
|
71
|
+
var eventHash = "event hash";
|
|
72
|
+
var eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
73
|
+
var body = networkHandler.bodyForEventSchemaCall(eventName, eventProperties, eventId, eventHash);
|
|
74
|
+
expect(body).toEqual(__assign(__assign({}, baseBody), { type: "event", eventName: eventName, eventProperties: eventProperties, avoFunction: true, eventId: eventId, eventHash: eventHash }));
|
|
75
|
+
});
|
|
76
|
+
test("POST request is not sent if event list is empty", function () {
|
|
77
|
+
var events = [];
|
|
78
|
+
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
79
|
+
expect(xhr_1.default.open).not.toBeCalled();
|
|
80
|
+
});
|
|
81
|
+
test("callInspectorWithBatchBody sends POST request", function () {
|
|
82
|
+
var eventName = "event name";
|
|
83
|
+
var eventProperties = [{ propertyName: "prop0", propertyType: "string" }];
|
|
84
|
+
var sessionStartedBody = networkHandler.bodyForSessionStartedCall();
|
|
85
|
+
var eventBody = networkHandler.bodyForEventSchemaCall(eventName, eventProperties, null, null);
|
|
86
|
+
var events = [sessionStartedBody, eventBody];
|
|
87
|
+
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
88
|
+
expect(xhr_1.default.open).toBeCalledTimes(1);
|
|
89
|
+
expect(xhr_1.default.open).toBeCalledWith("POST", constants_1.trackingEndpoint, true);
|
|
90
|
+
expect(xhr_1.default.setRequestHeader).toBeCalledWith("Content-Type", "text/plain");
|
|
91
|
+
expect(xhr_1.default.send).toBeCalledTimes(1);
|
|
92
|
+
expect(xhr_1.default.send).toBeCalledWith(JSON.stringify(events));
|
|
93
|
+
xhr_1.default.onload();
|
|
94
|
+
expect(customCallback).toBeCalledTimes(1);
|
|
95
|
+
expect(customCallback).toBeCalledWith(null);
|
|
96
|
+
});
|
|
97
|
+
test("Custom callback is called when 200 OK", function () {
|
|
98
|
+
var sessionStartedBody = networkHandler.bodyForSessionStartedCall();
|
|
99
|
+
var events = [sessionStartedBody];
|
|
100
|
+
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
101
|
+
xhr_1.default.onload();
|
|
102
|
+
expect(customCallback).toBeCalledTimes(1);
|
|
103
|
+
expect(customCallback).toBeCalledWith(null);
|
|
104
|
+
});
|
|
105
|
+
test("Custom callback is called with error when not 200 OK", function () {
|
|
106
|
+
var xhrErrorMock = require("../__mocks__/xhrError").default;
|
|
107
|
+
var sessionStartedBody = networkHandler.bodyForSessionStartedCall();
|
|
108
|
+
var events = [sessionStartedBody];
|
|
109
|
+
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
110
|
+
xhrErrorMock.onload();
|
|
111
|
+
expect(customCallback).toBeCalledTimes(1);
|
|
112
|
+
expect(customCallback).toBeCalledWith("Error 400: Bad Request");
|
|
113
|
+
});
|
|
114
|
+
test("Custom callback is called onerror", function () {
|
|
115
|
+
var xhrErrorMock = require("../__mocks__/xhrError").default;
|
|
116
|
+
var sessionStartedBody = networkHandler.bodyForSessionStartedCall();
|
|
117
|
+
var events = [sessionStartedBody];
|
|
118
|
+
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
119
|
+
xhrErrorMock.onerror();
|
|
120
|
+
expect(customCallback).toBeCalledTimes(1);
|
|
121
|
+
expect(customCallback).toBeCalledWith(constants_1.requestMsg.ERROR);
|
|
122
|
+
});
|
|
123
|
+
test("Custom callback is called ontimeout", function () {
|
|
124
|
+
var xhrErrorMock = require("../__mocks__/xhrError").default;
|
|
125
|
+
var sessionStartedBody = networkHandler.bodyForSessionStartedCall();
|
|
126
|
+
var events = [sessionStartedBody];
|
|
127
|
+
networkHandler.callInspectorWithBatchBody(events, customCallback);
|
|
128
|
+
xhrErrorMock.ontimeout();
|
|
129
|
+
expect(customCallback).toBeCalledTimes(1);
|
|
130
|
+
expect(customCallback).toBeCalledWith(constants_1.requestMsg.TIMEOUT);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|