UNPKG

avo-inspector

Version:

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

208 lines (207 loc) 7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var AvoInspector_1 = require("../AvoInspector"); var AvoInspectorEnv_1 = require("../AvoInspectorEnv"); var constants_1 = require("../__tests__/constants"); describe("Initialization", function () { test("Api Key is set", function () { // Given var apiKey = "api-key-xxx"; // When var inspector = new AvoInspector_1.AvoInspector({ env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, version: "0", apiKey: apiKey, }); // Then expect(inspector.apiKey).toBe(apiKey); }); test("Error is thrown when Api Key is not set", function () { // Given // @ts-ignore var apiKey; // Then expect(function () { new AvoInspector_1.AvoInspector({ env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, version: "0", // @ts-ignore apiKey: apiKey, }); }).toThrow(constants_1.error.API_KEY); }); test("Error is thrown when empty Api Key is used", function () { // Given var apiKey = " "; // Then expect(function () { new AvoInspector_1.AvoInspector({ env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, version: "0", apiKey: apiKey, }); }).toThrow(constants_1.error.API_KEY); }); test("Error is thrown when Api Key is set to null", function () { // Given var apiKey = null; // Then expect(function () { new AvoInspector_1.AvoInspector({ env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, version: "0", // @ts-ignore apiKey: apiKey, }); }).toThrow(constants_1.error.API_KEY); }); test("Dev environment is used when env is not provided", function () { // Given // @ts-ignore var env; // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", version: "0", // @ts-ignore env: env, }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev); }); test("Dev environment is used when empty string is used", function () { // Given var env = ""; // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", version: "0", // @ts-ignore env: env, }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev); }); test("Dev env is set using AvoInspectorEnv", function () { // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: AvoInspectorEnv_1.AvoInspectorEnv.Dev, version: "0", }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev); }); test("Dev environment is set using string", function () { // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: "dev", version: "0", }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev); }); test("Staging env is set using AvoInspectorEnv", function () { // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: AvoInspectorEnv_1.AvoInspectorEnv.Staging, version: "0", }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Staging); }); test("Staging environment is set using string", function () { // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: "staging", version: "0", }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Staging); }); test("Prod env is set using AvoInspectorEnv", function () { // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, version: "0", }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Prod); }); test("Prod environment is set using string", function () { // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: "prod", version: "0", }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Prod); }); test("Environment other than Dev, Staging, Prod falls back to Dev", function () { // When var env = "test"; var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", version: "0", // @ts-ignore env: env, }); // Then expect(inspector.environment).toBe(AvoInspectorEnv_1.AvoInspectorEnv.Dev); }); test("Version is set", function () { var version = "1"; // When var inspector = new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, version: version, }); // Then expect(inspector.version).toBe(version); }); test("Error is thrown when version is not set", function () { // Given // @ts-ignore var version; // Then expect(function () { new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, // @ts-ignore version: version, }); }).toThrow(constants_1.error.VERSION); }); test("Error is thrown when version is set to empty string", function () { // Given var version = " "; // Then expect(function () { new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, version: version, }); }).toThrow(constants_1.error.VERSION); }); test("Error is thrown when version is set to null", function () { // Given var version = null; // Then expect(function () { new AvoInspector_1.AvoInspector({ apiKey: "api-key-xxx", env: AvoInspectorEnv_1.AvoInspectorEnv.Prod, // @ts-ignore version: version, }); }).toThrow(constants_1.error.VERSION); }); });