avo-inspector
Version:
[](https://badge.fury.io/js/avo-inspector)
83 lines (82 loc) • 3.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var AvoBatcher_1 = require("../AvoBatcher");
var AvoInspector_1 = require("../AvoInspector");
var AvoNetworkCallsHandler_1 = require("../AvoNetworkCallsHandler");
var constants_1 = require("./constants");
var inspectorVersion = process.env.npm_package_version || "";
jest.mock("../AvoBatcher");
jest.mock("../AvoStorage");
describe("Batcher", function () {
var inspector;
var apiKey = constants_1.defaultOptions.apiKey, env = constants_1.defaultOptions.env, version = constants_1.defaultOptions.version;
var networkHandler = new AvoNetworkCallsHandler_1.AvoNetworkCallsHandler(apiKey, env, "", version, inspectorVersion);
beforeAll(function () {
inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions);
inspector.enableLogging(false);
});
afterEach(function () {
jest.clearAllMocks();
// @ts-ignore
inspector.avoDeduplicator._clearEvents();
});
test("Batcher is initialized on Inspector init", function () {
expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledTimes(1);
expect(AvoBatcher_1.AvoBatcher).toHaveBeenCalledWith(networkHandler);
});
test("handleTrackSchema is called on trackSchema", function () {
var eventName = "event name";
var schema = [
{
propertyName: "prop0",
propertyType: "string",
},
{
propertyName: "prop1",
propertyType: "string",
},
];
inspector.trackSchema(eventName, schema);
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, null, null);
});
test("handleTrackSchema is called on trackSchemaFromEvent", function () {
var eventName = "event name";
var properties = {
prop0: "",
prop2: false,
prop3: 0,
prop4: 0.0,
};
var schema = inspector.extractSchema(properties);
inspector.trackSchemaFromEvent(eventName, properties);
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, null, null);
});
test("handleTrackSchema is called on _avoFunctionTrackSchemaFromEvent", function () {
var eventName = "event name";
var properties = {
prop0: "",
prop2: false,
prop3: 0,
prop4: 0.0,
};
var eventId = "testId";
var eventHash = "testHash";
var schema = inspector.extractSchema(properties);
// @ts-ignore
inspector._avoFunctionTrackSchemaFromEvent(eventName, properties, eventId, eventHash);
expect(inspector.avoBatcher.handleTrackSchema).toHaveBeenCalledTimes(1);
expect(inspector.avoBatcher.handleTrackSchema).toBeCalledWith(eventName, schema, eventId, eventHash);
});
test("batchSize is updated", function () {
var count = 10;
inspector.setBatchSize(count);
expect(AvoInspector_1.AvoInspector.batchSize).toBe(count);
});
test("batchFlushSeconds is updated", function () {
var seconds = 10;
inspector.setBatchFlushSeconds(seconds);
expect(AvoInspector_1.AvoInspector.batchFlushSeconds).toBe(seconds);
});
});