Commit 22b45ff3 authored by Tom JORQUERA's avatar Tom JORQUERA

Merge branch '59-server-need-function-to-force-disconnection-from-a-room' into 'master'

add server disconnect function

Closes #59

See merge request !40
parents ed8dc251 e43a7748
...@@ -36,6 +36,15 @@ const create = (runner, modules, config) => { ...@@ -36,6 +36,15 @@ const create = (runner, modules, config) => {
room, room,
config.client); config.client);
return controller.registry[room]; return controller.registry[room];
},
forceDisconnect: room => {
controller.registry[room].execute(() => {
/* eslint-disable no-undef */
robot.stop();
/* eslint-enable */
}).end();
delete controller.registry[room];
} }
}; };
return controller; return controller;
......
...@@ -24,8 +24,19 @@ const {create} = require('./controller.js'); ...@@ -24,8 +24,19 @@ const {create} = require('./controller.js');
// Here are some needed mocks // Here are some needed mocks
const functionRunnerMock = {
execute() {
return {
end() {
}
};
}
};
const runnerMock = { const runnerMock = {
run: () => {} run: () => {
return functionRunnerMock;
}
}; };
const configMock = { const configMock = {
...@@ -60,4 +71,17 @@ describe('controller', () => { ...@@ -60,4 +71,17 @@ describe('controller', () => {
controller.client('test'); controller.client('test');
expect(controller.registry).toHaveProperty('test', client1); expect(controller.registry).toHaveProperty('test', client1);
}); });
test('should not have any room in registry when the client is disconnect', () => {
controller.client('test');
controller.forceDisconnect('test');
expect(controller.registry).toEqual({});
});
test('should have a room in registry when one client disconnect', () => {
controller.client('test1');
const client2 = controller.client('test2');
controller.forceDisconnect('test1');
expect(controller.registry).toHaveProperty('test2', client2);
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment