UNPKG

nralcm

Version:

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

68 lines (67 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("mocha"); const chai_1 = require("chai"); const sinon = require("sinon"); const _1 = require("."); const __1 = require(".."); const common_1 = require("../../common"); describe("FilterExecuter", () => { let request = {}; let response = {}; let httpContext = new __1.HttpContext(request, response); let testFilter = { beforeActionExceduted: sinon.stub(), aftereActionExceduted: sinon.stub() }; let globalFilters = [testFilter]; describe("executeBeforeActionExceduted", () => { let routeDescriptor = { route: "test", httpMethod: common_1.HttpMethod.GET, methodName: "testFilter" }; it("should execute IFilter.beforeActionExceduted with global filter", () => { httpContext.controllerObject = {}; let fe = new _1.FilterExecuter(httpContext, routeDescriptor, globalFilters); testFilter.beforeActionExceduted.callsFake((context, descriptor) => { chai_1.expect(descriptor.httpMethod).to.equal(common_1.HttpMethod.GET); }); fe.executeBeforeActionExceduted(); }); // it("should execute IFilter.beforeActionExceduted with decorator filter", () => { // httpContext.controller = ProductController; // let httpResponse: Partial<HttpResponse> = {}; // let di = new DependencyInjection(httpContext, <HttpResponse>httpResponse); // di.inject(); // let fe = new FilterExecuter(httpContext, <RouteDescriptor>routeDescriptor, globalFilters); // fe.executeBeforeActionExceduted(); // expect(routeDescriptor.route).to.equal("TestFilter-beforeActionExceduted ProductController"); // }); }); describe("executeAfterActionExceduted", () => { it("should execute IFilter.executeAfterActionExceduted with global filter", () => { httpContext.controllerObject = {}; let fe = new _1.FilterExecuter(httpContext, routeDescriptor, globalFilters); testFilter.aftereActionExceduted.callsFake((context, descriptor) => { chai_1.expect(descriptor.httpMethod).to.equal(common_1.HttpMethod.GET); }); fe.executeBeforeActionExceduted(); }); let routeDescriptor = { route: "test", httpMethod: common_1.HttpMethod.GET, methodName: "testFilter" }; // it("should execute IFilter.aftereActionExceduted with decorator filter", () => { // httpContext.controller = ProductController; // let httpResponse = getHttpResponse(httpContext, this.restApiConfiguration.HttpResponseHandler) // let di = new DependencyInjection(httpContext, httpResponse); // di.inject(); // let fe = new FilterExecuter(httpContext, <RouteDescriptor>routeDescriptor, globalFilters); // fe.executeBeforeActionExceduted(); // fe.executeAfterActionExceduted(); // expect(routeDescriptor.route).to.equal("TestFilter-aftereActionExceduted ProductController"); // }); }); });