Commit 29ef0ae4 authored by Tom Jorquera's avatar Tom Jorquera

lib: the controller is now in charge of managing the registry

Since it handles client creation, the controller now manager the registry.

Add corresponding tests.
parent 2e287af4
......@@ -24,8 +24,6 @@ const runner = require('./lib/runner.js')(config.runner);
const loader = require('./lib/loader.js')('./client');
const controllerFactory = require('./lib/controller.js');
const registry = {};
console.log('starting hublot...');
loader.loadAll('controller', 'lib', 'robot')
......@@ -38,8 +36,7 @@ loader.loadAll('controller', 'lib', 'robot')
// Note: client returned object can be used to control further the browser
// e.g.: let client = controller.client('room'); client.end();
const room = 'test-bot';
registry[room] = controller.client(room);
controller.client('test-bot');
})
.catch(err => {
console.error(err);
......
......@@ -25,10 +25,14 @@
const create = (runner, modules, config) => {
const controller = {
client: room => runner.run(modules,
config.visio.url,
room,
config.client)
registry: {},
client: room => {
controller.registry[room] = runner.run(modules,
config.visio.url,
room,
config.client);
return controller.registry[room];
}
};
return controller;
};
......
/*
* Copyright (c) 2017 Linagora.
*
* This file is part of Hublot
* (see https://ci.linagora.com/linagora/lgs/labs/hublot).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
const {create} = require('./controller.js');
// Here are some needed mocks
const runnerMock = {
run: () => {}
};
const configMock = {
visio: {url: 'someurl.test'},
client: {}
};
let controller;
describe('controller', () => {
beforeEach(() => {
controller = create(runnerMock, [], configMock);
});
test('should allow to create a client to a new room', () => {
expect(controller.client).toBeDefined();
});
test('should register a newly created client to its room', () => {
const client = controller.client('test');
expect(controller.registry).toHaveProperty('test', client);
});
});
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