2016-12-23 11:50:11 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Helper = require("../src/helper");
|
|
|
|
const expect = require("chai").expect;
|
|
|
|
const request = require("request");
|
|
|
|
const io = require("socket.io-client");
|
|
|
|
|
2017-11-28 07:34:04 +00:00
|
|
|
describe("Server", function() {
|
2018-02-28 20:42:21 +00:00
|
|
|
// Travis is having issues with slow workers and thus tests timeout
|
|
|
|
this.timeout(process.env.CI ? 25000 : 5000);
|
|
|
|
|
2017-10-06 09:53:08 +00:00
|
|
|
let server;
|
2017-12-09 23:56:05 +00:00
|
|
|
let originalLogInfo;
|
|
|
|
|
|
|
|
before(function() {
|
|
|
|
originalLogInfo = log.info;
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
log.info = () => {};
|
2017-10-06 09:53:08 +00:00
|
|
|
|
|
|
|
server = require("../src/server")();
|
|
|
|
});
|
|
|
|
|
2017-12-09 23:56:05 +00:00
|
|
|
after(function(done) {
|
2017-10-06 09:53:08 +00:00
|
|
|
server.close(done);
|
2017-12-09 23:56:05 +00:00
|
|
|
|
|
|
|
log.info = originalLogInfo;
|
2017-10-06 09:53:08 +00:00
|
|
|
});
|
2016-12-23 11:50:11 +00:00
|
|
|
|
|
|
|
const webURL = `http://${Helper.config.host}:${Helper.config.port}/`;
|
|
|
|
|
|
|
|
describe("Express", () => {
|
2017-04-08 12:34:31 +00:00
|
|
|
it("should run a web server on " + webURL, (done) => {
|
2016-12-23 11:50:11 +00:00
|
|
|
request(webURL, (error, response, body) => {
|
|
|
|
expect(error).to.be.null;
|
|
|
|
expect(body).to.include("<title>The Lounge</title>");
|
2017-11-12 18:28:13 +00:00
|
|
|
expect(body).to.include("js/bundle.js");
|
2016-12-23 11:50:11 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
it("should serve static content correctly", (done) => {
|
2016-12-23 11:50:11 +00:00
|
|
|
request(webURL + "manifest.json", (error, response, body) => {
|
|
|
|
expect(error).to.be.null;
|
|
|
|
|
|
|
|
body = JSON.parse(body);
|
|
|
|
expect(body.name).to.equal("The Lounge");
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-27 23:47:19 +00:00
|
|
|
describe("WebSockets", function() {
|
|
|
|
this.slow(300);
|
|
|
|
|
2016-12-23 11:50:11 +00:00
|
|
|
let client;
|
|
|
|
|
2017-08-31 12:15:42 +00:00
|
|
|
before((done) => {
|
|
|
|
Helper.config.public = true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2016-12-23 11:50:11 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
client = io(webURL, {
|
|
|
|
path: "/socket.io/",
|
|
|
|
autoConnect: false,
|
|
|
|
reconnection: false,
|
|
|
|
timeout: 1000,
|
|
|
|
transports: [
|
2017-11-15 06:35:15 +00:00
|
|
|
"websocket",
|
|
|
|
],
|
2016-12-23 11:50:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Server emits events faster than the test can bind them
|
|
|
|
setTimeout(() => {
|
|
|
|
client.open();
|
|
|
|
}, 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
client.close();
|
|
|
|
});
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
it("should emit authorized message", (done) => {
|
2016-12-23 11:50:11 +00:00
|
|
|
client.on("authorized", done);
|
|
|
|
});
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
it("should create network", (done) => {
|
2016-12-23 11:50:11 +00:00
|
|
|
client.on("init", () => {
|
2018-03-15 08:37:32 +00:00
|
|
|
client.emit("network:new", {
|
2016-12-23 11:50:11 +00:00
|
|
|
username: "test-user",
|
|
|
|
realname: "The Lounge Test",
|
|
|
|
nick: "test-user",
|
|
|
|
join: "#thelounge, #spam",
|
|
|
|
name: "Test Network",
|
|
|
|
host: Helper.config.host,
|
|
|
|
port: 6667,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
client.on("network", (data) => {
|
2016-12-23 11:50:11 +00:00
|
|
|
expect(data.networks).to.be.an("array");
|
|
|
|
expect(data.networks).to.have.lengthOf(1);
|
|
|
|
expect(data.networks[0].realname).to.equal("The Lounge Test");
|
|
|
|
expect(data.networks[0].channels).to.have.lengthOf(3);
|
|
|
|
expect(data.networks[0].channels[0].name).to.equal("Test Network");
|
|
|
|
expect(data.networks[0].channels[1].name).to.equal("#thelounge");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
it("should emit init message", (done) => {
|
|
|
|
client.on("init", (data) => {
|
2016-12-23 11:50:11 +00:00
|
|
|
expect(data.active).to.equal(-1);
|
|
|
|
expect(data.networks).to.be.an("array");
|
|
|
|
expect(data.networks).to.be.empty;
|
|
|
|
expect(data.token).to.be.null;
|
2017-09-25 08:46:15 +00:00
|
|
|
expect(data.pushSubscription).to.be.undefined;
|
|
|
|
|
|
|
|
// Private key defined in vapid.json is "01020304050607080910111213141516" for this public key.
|
|
|
|
expect(data.applicationServerKey).to.equal("BM0eTDpvDnH7ewlHuXWcPTE1NjlJ06XWIS1cQeBTZmsg4EDx5sOpY7kdX1pniTo8RakL3UdfFuIbC8_zog_BWIM");
|
2016-12-23 11:50:11 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|