[Test] Realtime monitoring
This commit is contained in:
parent
46a61dc45e
commit
aba4fcf0fa
@ -58,6 +58,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"expect": "^1.20.2",
|
"expect": "^1.20.2",
|
||||||
"mocha": "^3.2.0",
|
"mocha": "^3.2.0",
|
||||||
|
"socketcluster-client": "^5.1.1",
|
||||||
"supertest": "^2.0.1"
|
"supertest": "^2.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,4 +37,74 @@ describe('Server', function() {
|
|||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Realtime monitoring', function() {
|
||||||
|
var socket, socket2, channel;
|
||||||
|
before(function() {
|
||||||
|
socket = scClient.connect({ hostname: 'localhost', port: 8000 });
|
||||||
|
socket.connect();
|
||||||
|
socket.on('error', function(error) {
|
||||||
|
console.error('Socket1 error', error);
|
||||||
|
});
|
||||||
|
socket2 = scClient.connect({ hostname: 'localhost', port: 8000 });
|
||||||
|
socket2.connect();
|
||||||
|
socket.on('error', function(error) {
|
||||||
|
console.error('Socket2 error', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
socket.disconnect();
|
||||||
|
socket2.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should connect', function(done) {
|
||||||
|
socket.on('connect', function(status) {
|
||||||
|
expect(status.id).toExist();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should login', function() {
|
||||||
|
socket.emit('login', 'master', function(error, channelName) {
|
||||||
|
if (error) { console.log(error); return; }
|
||||||
|
expect(channelName).toBe('respond');
|
||||||
|
channel = socket.subscribe(channelName);
|
||||||
|
expect(channel.SUBSCRIBED).toBe('subscribed');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should send message', function(done) {
|
||||||
|
var data = {
|
||||||
|
"type": "ACTION",
|
||||||
|
"payload": {
|
||||||
|
"todos": "do some"
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"timestamp": 1483349708506,
|
||||||
|
"action": {
|
||||||
|
"type": "ADD_TODO",
|
||||||
|
"text": "hggg"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"instanceId": "tAmA7H5fclyWhvizAAAi",
|
||||||
|
"name": "LoggerInstance",
|
||||||
|
"id": "tAmA7H5fclyWhvizAAAi"
|
||||||
|
};
|
||||||
|
|
||||||
|
socket2.emit('login', '', function(error, channelName) {
|
||||||
|
if (error) { console.log(error); return; }
|
||||||
|
expect(channelName).toBe('log');
|
||||||
|
var channel2 = socket2.subscribe(channelName);
|
||||||
|
expect(channel2.SUBSCRIBED).toBe('subscribed');
|
||||||
|
channel2.on('subscribe', function() {
|
||||||
|
channel2.watch(function(message) {
|
||||||
|
expect(message).toEqual(data);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
socket.emit(channelName, data);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user