UNPKG

avo-inspector

Version:

[![npm version](https://badge.fury.io/js/avo-inspector.svg)](https://badge.fury.io/js/avo-inspector)

116 lines (115 loc) 4.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var AvoInspector_1 = require("../AvoInspector"); var constants_1 = require("../__tests__/constants"); describe("Schema Parsing", function () { var inspector = new AvoInspector_1.AvoInspector(constants_1.defaultOptions); beforeAll(function () { inspector.enableLogging(false); }); test("Empty array returned if eventProperties are not set", function () { // @ts-ignore var schema = inspector.extractSchema(); expect(schema).toEqual([]); }); test("Property types and names are set", function () { // Given var eventProperties = { prop0: true, prop1: 1, prop2: "str", prop3: 0.5, prop4: undefined, prop5: null, prop6: { an: "object" }, prop7: [ "a", "list", { "obj in list": true, "int field": 1, }, ["another", "list"], [1, 2], ], }; // When var res = inspector.extractSchema(eventProperties); // Then res.forEach(function (_a, index) { var propertyName = _a.propertyName; expect(propertyName).toBe("prop".concat(index)); }); expect(res[0].propertyType).toBe(constants_1.type.BOOL); expect(res[1].propertyType).toBe(constants_1.type.INT); expect(res[2].propertyType).toBe(constants_1.type.STRING); expect(res[3].propertyType).toBe(constants_1.type.FLOAT); expect(res[4].propertyType).toBe(constants_1.type.NULL); expect(res[5].propertyType).toBe(constants_1.type.NULL); expect(res[6].propertyType).toBe(constants_1.type.OBJECT); expect(res[6].children).toMatchObject([ { propertyName: "an", propertyType: constants_1.type.STRING, }, ]); expect(res[7].propertyType).toBe(constants_1.type.LIST); expect(res[7].children).toMatchObject([ constants_1.type.STRING, [ { propertyName: "obj in list", propertyType: constants_1.type.BOOL, }, { propertyName: "int field", propertyType: constants_1.type.INT, }, ], [constants_1.type.STRING], [constants_1.type.INT], ]); }); test("Duplicated values are removed", function () { // Given var eventProperties = { prop0: ["true", "false", true, 10, "true", true, 11, 10, 0.1, 0.1], }; // When var res = inspector.extractSchema(eventProperties); // Then expect(res[0].propertyType).toBe(constants_1.type.LIST); expect(res[0].children).toMatchObject([ constants_1.type.STRING, constants_1.type.BOOL, constants_1.type.INT, constants_1.type.FLOAT, ]); }); test("Empty and falsy values are set correctly", function () { // Given var eventProperties = { prop0: false, prop1: 0, prop2: "", prop3: 0.0, prop4: undefined, prop5: null, prop6: {}, prop7: [], }; // When var res = inspector.extractSchema(eventProperties); // Then expect(res[0].propertyType).toBe(constants_1.type.BOOL); expect(res[1].propertyType).toBe(constants_1.type.INT); expect(res[2].propertyType).toBe(constants_1.type.STRING); expect(res[3].propertyType).toBe(constants_1.type.INT); expect(res[4].propertyType).toBe(constants_1.type.NULL); expect(res[5].propertyType).toBe(constants_1.type.NULL); expect(res[6].propertyType).toBe(constants_1.type.OBJECT); expect(res[6].children).toMatchObject([]); expect(res[7].propertyType).toBe(constants_1.type.LIST); expect(res[7].children).toMatchObject([]); }); });