UNPKG

@xmt/server-framework

Version:

Backend Server Framework of XmT Inc.

82 lines 3.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const superagent = require("superagent"); const chai_1 = require("chai"); const interface_1 = require("../../lib/interface"); describe("Response.xmt_send()", function () { it("should sent json", function (done) { const router = new interface_1.Router(); router.xmt_common(function (request, response) { response.xmt_send({ "json": "hello!" }); }); const server = router.xmt_listen(7777); superagent.get("http://localhost:7777") .end(function (error, response) { chai_1.expect(response.type).to.equal("application/json"); chai_1.expect(response.body.json).to.equal("hello!"); server.close(done); }); }); it("should sent text", function (done) { const router = new interface_1.Router(); router.xmt_common(function (request, response) { response.xmt_send("hello text!"); }); const server = router.xmt_listen(7777); superagent.get("http://localhost:7777") .end(function (error, response) { chai_1.expect(response.type).to.equal("text/plain"); chai_1.expect(response.text).to.equal("hello text!"); server.close(done); }); }); it("should sent binary data", function (done) { const router = new interface_1.Router(); router.xmt_common(function (request, response) { response.xmt_send(new Buffer("raregrass")); }); const server = router.xmt_listen(7777); superagent.get("http://localhost:7777") .end(function (error, response) { chai_1.expect(response.type).to.equal("application/octet-stream"); server.close(done); }); }); it("should sent html", function (done) { const router = new interface_1.Router(); router.xmt_common(function (request, response) { response.xmt_setHeader({ "content-type": "html" }); response.xmt_send("<p>hello</p>"); }); const server = router.xmt_listen(7777); superagent.get("http://localhost:7777") .end(function (error, response) { chai_1.expect(response.type).to.equal("text/html"); server.close(done); }); }); it("should allow call this method multi times", function (done) { const router = new interface_1.Router(); router.xmt_common(function (request, response) { response.xmt_send({ "json": "hello 1!" }); response.xmt_send({ "json": "hello 2!" }); response.xmt_send({ "json": "hello 3!" }); }); const server = router.xmt_listen(7777); superagent.get("http://localhost:7777") .end(function (error, response) { chai_1.expect(response.type).to.equal("application/json"); chai_1.expect(response.body.json).to.equal("hello 1!"); server.close(done); }); }); }); //# sourceMappingURL=xmt_send.js.map