108 lines
8.0 KiB
JavaScript
108 lines
8.0 KiB
JavaScript
"use strict";
|
|
require("typings-test");
|
|
const should = require("should");
|
|
const smartsocket = require("../dist/index");
|
|
const q = require("q");
|
|
const nodehash = require("nodehash");
|
|
let testSmartsocket;
|
|
let testSmartsocketClient;
|
|
let testSocketRole1;
|
|
let testSocketFunction1;
|
|
let testConfig = {
|
|
port: 3000
|
|
};
|
|
describe("smartsocket", function () {
|
|
describe("class Smartsocket", function () {
|
|
it("should create a new smartsocket", function () {
|
|
testSmartsocket = new smartsocket.Smartsocket({ port: testConfig.port });
|
|
should(testSmartsocket).be.instanceOf(smartsocket.Smartsocket);
|
|
});
|
|
it("should start listening when .started is called", function () {
|
|
testSmartsocket.startServer();
|
|
});
|
|
});
|
|
describe("class SocketRole", function () {
|
|
it("should add a socketrole", function () {
|
|
testSocketRole1 = new smartsocket.SocketRole({
|
|
name: "testRole1",
|
|
passwordHash: nodehash.sha256FromStringSync("testPassword")
|
|
});
|
|
testSmartsocket.addSocketRoles([testSocketRole1]);
|
|
});
|
|
});
|
|
describe("class SocketFunction", function () {
|
|
it("should register a new Function", function () {
|
|
testSocketFunction1 = new smartsocket.SocketFunction({
|
|
funcName: "testFunction1",
|
|
funcDef: (dataArg) => {
|
|
let done = q.defer();
|
|
done.resolve(dataArg);
|
|
return done.promise;
|
|
},
|
|
allowedRoles: [testSocketRole1]
|
|
});
|
|
});
|
|
});
|
|
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: "testRole1"
|
|
});
|
|
testSmartsocketClient.connect()
|
|
.then(() => {
|
|
done();
|
|
});
|
|
});
|
|
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();
|
|
});
|
|
});
|
|
it("2 clients should connect in parallel", function () {
|
|
});
|
|
it("should be able to make a functionCall from client to server", function (done) {
|
|
this.timeout(5000);
|
|
testSmartsocketClient.serverCall("testFunction1", {
|
|
value1: "hello"
|
|
}).then((dataArg) => {
|
|
console.log(dataArg);
|
|
done();
|
|
});
|
|
});
|
|
it("should be able to make a functionCall from server to client", function (done) {
|
|
this.timeout(5000);
|
|
let targetSocket = (() => {
|
|
return smartsocket.allSocketConnections.find((socketConnectionArg) => {
|
|
return socketConnectionArg.alias === "testClient1";
|
|
});
|
|
})();
|
|
testSmartsocket.clientCall("testFunction1", {
|
|
value1: "helloFromServer"
|
|
}, targetSocket).then((dataArg) => {
|
|
console.log(dataArg);
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
describe("terminating smartsocket", function () {
|
|
it("should close the server", function () {
|
|
testSmartsocket.closeServer();
|
|
});
|
|
});
|
|
});
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxNQUFNLFdBQVcsUUFBUSxDQUFDLENBQUM7QUFFbEMsTUFBTyxXQUFXLFdBQVcsZUFBZSxDQUFDLENBQUM7QUFDOUMsTUFBTyxDQUFDLFdBQVcsR0FBRyxDQUFDLENBQUM7QUFDeEIsTUFBTyxRQUFRLFdBQVcsVUFBVSxDQUFDLENBQUM7QUFFdEMsSUFBSSxlQUF3QyxDQUFDO0FBQzdDLElBQUkscUJBQW9ELENBQUM7QUFDekQsSUFBSSxlQUF1QyxDQUFDO0FBQzVDLElBQUksbUJBQ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