Skip to content

Commit

Permalink
Adapt status service to new live service
Browse files Browse the repository at this point in the history
  • Loading branch information
graduta committed Sep 7, 2024
1 parent f74b21a commit 4650df6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 13 additions & 9 deletions InfoLogger/lib/StatusService.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class StatusService {
* Set source of live mode once enabled
* @param {InfoLoggerReceiver} liveSource - source of live mode
*/
setLiveSource(liveSource) {
this.liveSource = liveSource;
set liveSource(liveSource) {
this._liveSource = liveSource;
}

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ class StatusService {
result['infoLogger-gui'] = this.getProjectInfo();

if (this.config.infoLoggerServer) {
result.infoLoggerServer = this.getLiveSourceStatus(this.config.infoLoggerServer);
result.infoLoggerServer = this._getLiveSourceStatus(this.config.infoLoggerServer);
}
if (this.config.mysql) {
result.mysql = await this.getDataSourceStatus(this.config.mysql);
Expand Down Expand Up @@ -113,14 +113,18 @@ class StatusService {
/**
* Build an object with information and status about live source
* @param {object} config used for retrieving data from live source
* @param {string} config.host - host of the live source
* @param {number} config.port - port of the live source
* @returns {object} - information on status of the live source
*/
getLiveSourceStatus(config) {
const ils = { host: config.host, port: config.port };
ils.status = this.liveSource && this.liveSource.isConnected ?
{ ok: true }
: { ok: false, message: 'Unable to connect to InfoLogger Server' };
return ils;
_getLiveSourceStatus({ host, port }) {
return {
host,
port,
status: this?._liveSource?.isAvailable
? { ok: true }
: { ok: false, message: 'Unable to connect to InfoLogger Server' },
};
}

/**
Expand Down
6 changes: 3 additions & 3 deletions InfoLogger/test/lib/mocha-status-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ describe('Status Service test suite', () => {
it('should successfully return InfoLogger Server info with status ok false if live source is missing', () => {
const statusService = new StatusService(config, undefined);
const info = {host: 'localhost', port: 6102, status: {ok: false, message: 'Unable to connect to InfoLogger Server'}};
assert.deepStrictEqual(statusService.getLiveSourceStatus(config.infoLoggerServer), info);
assert.deepStrictEqual(statusService._getLiveSourceStatus(config.infoLoggerServer), info);
});

it('should successfully return InfoLogger Server info with status ok when live source is present', () => {
const statusService = new StatusService(config, undefined);
statusService.setLiveSource({isConnected: true, onconnect: () => true});
statusService.liveSource = {isAvailable: true, onconnect: () => true};

const info = {host: 'localhost', port: 6102, status: {ok: true}};
assert.deepStrictEqual(statusService.getLiveSourceStatus(config.infoLoggerServer), info);
assert.deepStrictEqual(statusService._getLiveSourceStatus(config.infoLoggerServer), info);
});
});

Expand Down

0 comments on commit 4650df6

Please sign in to comment.