UNPKG

queryda

Version:

watch/report/alert tool for elasticsearch

144 lines (129 loc) 4.47 kB
// Generated by CoffeeScript 1.10.0 (function() { var App, ConsoleReporter, Validator, Worker, app, assert, configMock, loglevelMock, mockery, ref; mockery = require("mockery"); assert = require("chai").assert; ref = [], app = ref[0], configMock = ref[1]; loglevelMock = { debug: function(str) { return this.strDebug = str; }, error: function(str) { console.error(str); return this.strError = str; } }; configMock = { name: "Test", elasticsearch: { host: "localhost", port: 9200, index: "_all", type: "type" }, query: {}, reporters: { console: {} }, validator: { fieldName: "prop", min: 10, max: 30, tolerance: 5 } }; mockery.registerMock("loglevel", loglevelMock); mockery.registerAllowables(["../reporter", "../src/reporter", "./reporters/console", "../src/reporters/console", "../worker", "../src/worker"]); mockery.enable({ useCleanCache: true }); App = require("../src/app"); ConsoleReporter = require("../src/reporters/console"); Worker = require("../src/worker"); Validator = require("../src/validator"); describe("App", function() { describe("init", function() { var stub; stub = [][0]; beforeEach(function() { return stub = { name: 1, elasticsearch: 1, query: 1, reporters: 1, validator: 1 }; }); it("should throw an error if config.name is missing", function() { var init; delete stub.name; init = function() { return new App(stub); }; return assert["throw"](init, Error, "config.name missing"); }); it("should throw an error if config.elasticsearch is missing", function() { var init; delete stub.elasticsearch; init = function() { return new App(stub); }; return assert["throw"](init, Error, "config.elasticsearch missing"); }); it("should throw an error if config.query is missing", function() { var init; delete stub.query; init = function() { return new App(stub); }; return assert["throw"](init, Error, "config.query missing"); }); it("should throw an error if config.reporters is missing", function() { var init; delete stub.reporters; init = function() { return new App(stub); }; return assert["throw"](init, Error, "config.reporters missing"); }); return it("should throw an error if config.validator is missing", function() { var init; delete stub.validator; init = function() { return new App(stub); }; return assert["throw"](init, Error, "config.validator missing"); }); }); describe("App.createWorker", function() { it("should create a Worker from a given config", function() { return assert.instanceOf(App.createWorker("testworker", configMock.elasticsearch, configMock.query, {}), Worker); }); it("should return null if any of the options are missing", function() { assert.isNull(App.createWorker(null, {}, {}, {})); assert.isNull(App.createWorker("name", null, {}, {})); assert.isNull(App.createWorker("name", {}, null, {})); return assert.isNull(App.createWorker("name", {}, {}, null)); }); return it("should return null if the Worker can't be created", function() { return assert.isNull(App.createWorker()); }); }); describe("App.createValidator", function() { it("should create a Validator from a given config", function() { return assert.instanceOf(App.createValidator("validator", configMock.validator), Validator); }); return it("should return null if the validator can't be created", function() { return assert.isNull(App.createValidator("!_random_garbage_!", {})); }); }); return describe("App.createReporter", function() { it("should create the correct Reporter (ConsoleReporter) from a given config", function() { return assert.instanceOf(App.createReporter("console", {}), ConsoleReporter); }); return it("should return null if the reporter can't be created", function() { return assert.isNull(App.createReporter("!_random_garbage_!", {})); }); }); }); }).call(this);