smartsocket/test/test.js

75 lines
5.2 KiB
JavaScript
Raw Normal View History

2016-08-07 12:58:20 +00:00
"use strict";
require("typings-test");
require("should");
const smartsocket = require("../dist/index");
2016-08-14 20:17:55 +00:00
const q = require("q");
2016-08-07 12:58:20 +00:00
let testSmartsocket;
2016-08-12 03:57:32 +00:00
let testSmartsocketClient;
2016-08-14 20:17:55 +00:00
let testSocketFunction1;
2016-08-12 03:57:32 +00:00
let testConfig = {
port: 3000
};
2016-08-07 12:58:20 +00:00
describe("smartsocket", function () {
2016-08-14 20:17:55 +00:00
describe("class Smartsocket", function () {
it("should create a new smartsocket", function () {
testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port });
testSmartsocket.should.be.instanceOf(smartsocket.Smartsocket);
});
it("should start listening when .started is called", function () {
testSmartsocket.startServer();
});
2016-08-07 12:58:20 +00:00
});
2016-08-14 20:17:55 +00:00
describe("class SocketRole", function () {
2016-08-07 16:59:39 +00:00
});
2016-08-14 20:17:55 +00:00
describe("class SocketFunction", function () {
it("should register a new Function", function () {
testSocketFunction1 = new smartsocket.SocketFunction({
funcName: "testFunction1",
funcDef: () => {
let done = q.defer();
return done.promise;
},
allowedRoles: []
});
});
2016-08-07 16:59:39 +00:00
});
2016-08-14 20:17:55 +00:00
describe("class SmartsocketClient", function () {
it("should react to a new websocket connection from client", function (done) {
this.timeout(10000);
testSmartsocketClient = new smartsocket.SmartsocketClient({
port: testConfig.port,
url: "http://localhost",
password: "testPassword",
alias: "testClient1",
role: undefined
});
testSmartsocketClient.connect()
.then(() => {
done();
});
2016-08-07 12:58:20 +00:00
});
2016-08-14 20:17:55 +00:00
it("client should disconnect and reconnect", function (done) {
this.timeout(10000);
testSmartsocketClient.disconnect()
.then(() => {
let done = q.defer();
setTimeout(() => {
testSmartsocketClient.connect()
.then(done.resolve);
}, 0);
return done.promise;
})
.then(() => {
done();
});
2016-08-14 01:25:26 +00:00
});
2016-08-14 20:17:55 +00:00
it("2 clients should connect in parallel", function () {
2016-08-14 01:25:26 +00:00
});
2016-08-07 12:58:20 +00:00
});
2016-08-14 20:17:55 +00:00
describe("terminating smartsocket", function () {
it("should close the server", function () {
testSmartsocket.closeServer();
});
2016-08-07 16:59:39 +00:00
});
2016-08-07 12:58:20 +00:00
});
2016-08-14 20:17:55 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixNQUFPLFdBQVcsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUM5QyxNQUFPLENBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQztBQUV4QixJQUFJLGVBQXdDLENBQUM7QUFDN0MsSUFBSSxxQkFBb0QsQ0FBQztBQUN6RCxJQUFJLG1CQUE4QyxDQUFDO0FBRW5ELElBQUksVUFBVSxHQUFHO0lBQ2IsSUFBSSxFQUFFLElBQUk7Q0FDYixDQUFBO0FBRUQsUUFBUSxDQUFDLGFBQWEsRUFBRTtJQUNwQixRQUFRLENBQUMsbUJBQW1CLEVBQUU7UUFDMUIsRUFBRSxDQUFDLGlDQUFpQyxFQUFFO1lBQ2xDLGVBQWUsR0FBRyxJQUFJLFdBQVcsQ0FBQyxXQUFXLENBQUMsRUFBRSxJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUksRUFBRSxDQUFDLENBQUM7WUFDekUsZUFBZSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUNsRSxDQUFDLENBQUMsQ0FBQztRQUNILEVBQUUsQ0FBQyxnREFBZ0QsRUFBRTtZQUNqRCxlQUFlLENBQUMsV0FBVyxFQUFFLENBQUM7UUFDbEM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