Commit e43a7748 authored by Yoann HOUPERT's avatar Yoann HOUPERT

add server disconnect function

parent ed8dc251
Pipeline #4485 passed with stage
in 49 seconds
......@@ -36,6 +36,15 @@ const create = (runner, modules, config) => {
room,
config.client);
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;
......
......@@ -24,8 +24,19 @@ const {create} = require('./controller.js');
// Here are some needed mocks
const functionRunnerMock = {
execute() {
return {
end() {
}
};
}
};
const runnerMock = {
run: () => {}
run: () => {
return functionRunnerMock;
}
};
const configMock = {
......@@ -60,4 +71,17 @@ describe('controller', () => {
controller.client('test');
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