UNPKG

nralcm

Version:

This is a framework based on NodeJs to manage rest api request lifecycle

45 lines (44 loc) 2.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("mocha"); const chai_1 = require("chai"); const http_configuration_1 = require("./http-configuration"); const __1 = require(".."); describe("HttpConfiguration", () => { describe("getHandler", () => { it("getHandler must return default RestApiHandler when not any handler added", () => { let restApiConfig = {}; let httpConfiguration = new http_configuration_1.HttpConfiguration(restApiConfig); const restApiHandler = httpConfiguration.getHandler("/api/product"); chai_1.expect(restApiHandler && restApiHandler[1]).to.instanceof(__1.RestApiHandler); }); }); describe("addHandler", () => { it("Add handler and then getHandler should return same", () => { let handler = {}; let restApiConfig = {}; let httpConfiguration = new http_configuration_1.HttpConfiguration(restApiConfig); httpConfiguration.addHandler("/newapi/*", handler); const restApiHandler = httpConfiguration.getHandler("/newapi/product"); chai_1.expect(restApiHandler && restApiHandler[0]).to.equal("/newapi/*"); }); }); describe("removeHandler", () => { it("should remove handler and will return true", () => { let restApiConfig = {}; let handler = new __1.RestApiHandler(restApiConfig); let httpConfiguration = new http_configuration_1.HttpConfiguration(restApiConfig); const result = httpConfiguration.removeHandler(handler); chai_1.expect(result).to.equal(true); }); it("After remove must return false", () => { let restApiConfig = {}; let handler = new __1.RestApiHandler(restApiConfig); let httpConfiguration = new http_configuration_1.HttpConfiguration(restApiConfig); const removed = httpConfiguration.removeHandler(handler); chai_1.expect(removed).to.equal(true); const result = httpConfiguration.removeHandler(handler); chai_1.expect(result).to.equal(false); }); }); });