UNPKG

realm-object-server

Version:

Realm Object Server

100 lines 4.74 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const TestServer_1 = require("../TestServer"); const decorators_1 = require("../decorators"); const chai_1 = require("chai"); const bodyParser = require("body-parser"); const superagent = require("superagent"); describe("MiddlewaresBefore Integration Tests", function () { let server; const addPropertyMiddleware = (req, res, next) => { req.body["additionalProperty"] = "additionalValue"; next(); }; let ServiceA = class ServiceA { postSomething(body) { return body; } }; __decorate([ decorators_1.Post("/something"), __param(0, decorators_1.Body()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], ServiceA.prototype, "postSomething", null); ServiceA = __decorate([ decorators_1.BaseRoute("/a"), decorators_1.MiddlewaresBefore(addPropertyMiddleware) ], ServiceA); let ServiceB = class ServiceB { postSomething(body) { return body; } }; __decorate([ decorators_1.Post("/something"), decorators_1.MiddlewaresBefore(bodyParser.urlencoded({ extended: false })), __param(0, decorators_1.Body()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], ServiceB.prototype, "postSomething", null); ServiceB = __decorate([ decorators_1.BaseRoute("/b") ], ServiceB); before(() => __awaiter(this, void 0, void 0, function* () { server = new TestServer_1.TestServer(); server.addService(new ServiceA()); server.addService(new ServiceB()); yield server.start(); })); after(() => __awaiter(this, void 0, void 0, function* () { yield server.shutdown(); })); describe("POST /a ", () => { it("have added a property to the payload on the way back", () => __awaiter(this, void 0, void 0, function* () { const serviceARoute = `${server.url}/a/something`; const response = yield superagent.post(serviceARoute) .send({ "something": "something" }); chai_1.expect(response.body["something"]).to.be.eq("something"); chai_1.expect(response.body["additionalProperty"]).to.be.eq("additionalValue"); })); }); describe("POST /b ", () => { it("should allow posting application/x-www-form-urlencoded parser", () => __awaiter(this, void 0, void 0, function* () { const serviceARoute = `${server.url}/b/something`; const response = yield superagent.post(serviceARoute) .type("form") .send({ "some-form-information": "sally", "some-form-information-a": "sallya", }); chai_1.expect(response.body["some-form-information"]).to.be.eq("sally"); chai_1.expect(response.body["some-form-information-a"]).to.be.eq("sallya"); })); }); }); //# sourceMappingURL=middlewares-intergration-tests.spec.js.map