UNPKG

xmt-base

Version:

Backend Server Framework of XmT Inc.

81 lines 3.17 kB
"use strict"; const superagent = require("superagent"); const expect = require("chai").expect; 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) { expect(response.type).to.equal("application/json"); 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) { expect(response.type).to.equal("text/plain"); 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) { 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) { 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) { expect(response.type).to.equal("application/json"); expect(response.body.json).to.equal("hello 1!"); server.close(done); }); }); }); //# sourceMappingURL=xmt_send.js.map