Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

231 add tests #236

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"licenseInformation": {
"license": "MIT",
"type": "free"
},
},
"platform": "Javascript/Node.js",
"icon": "blebox.png",
"enabled": true,
Expand Down
2 changes: 1 addition & 1 deletion lib/gatebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function getApiUrl(type, _value) {
case 'gateClose':
return '/s/c';
default:
break;
return false;
}
}

Expand Down
45 changes: 45 additions & 0 deletions lib/gatebox.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable no-undef */
'use strict';
const gatebox = require('./gatebox');

const { expect } = require('chai');

const datapointMoveCommand = {
path: 'command.move',
type: 'state',
common: {
name: 'primary action (p), secondary action (s), open (o), close (c)',
type: 'string',
role: 'text',
read: true,
write: true,
states: { p: 'Primary', s: 'Secondary', o: 'Open', c: 'Close' },
},
};

describe('test gatebox.getDatapoints', () => {
const result = gatebox.datapoints;
it(`expect command.move object`, () => {
expect(JSON.stringify(result['gatebox#command.move'])).to.equal(JSON.stringify(datapointMoveCommand));
});
});

describe('test gatebox.getApiUrl', () => {
it('expect correct URL', () => {
const result = '/state/extended';
expect(gatebox.getApiUrl('gateExtendedState')).to.be.equal(result);
});
it('expect false on unsupported call', () => {
expect(gatebox.getApiUrl('notExisting')).to.be.false;
});
});

describe('test gatebox.getDeviceTypeMapping', () => {
it('expect supported devices by this API', () => {
const result = {
gatebox: 'gatebox',
};

expect(JSON.stringify(gatebox.getDeviceTypeMapping())).to.be.equal(JSON.stringify(result));
});
});
2 changes: 1 addition & 1 deletion lib/multisensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function getApiUrl(type, _value) {
case 'multisensorExtendedState':
return '/state/extended';
default:
break;
return false;
}
}

Expand Down
52 changes: 52 additions & 0 deletions lib/multisensor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable no-undef */
'use strict';
const multisensor = require('./multisensor');

const { expect } = require('chai');

const datapointElapsedTimeS = {
path: 'multiSensor.sensors.0.elapsedTimeS',
type: 'state',
common: {
name: 'Time in seconds that has elapsed since last valid measurement occurred, where -1 = Error, 0 = Fresh data',
type: 'number',
role: 'value',
read: true,
write: false,
},
};

describe('test multisensor.getDatapoints', () => {
const result = multisensor.datapoints;
it(`expect command.move object`, () => {
expect(JSON.stringify(result['multisensor#multiSensor.sensors[0].elapsedTimeS'])).to.equal(
JSON.stringify(datapointElapsedTimeS),
);
});
});

describe('test multisensor.getApiUrl', () => {
it('expect correct URL', () => {
const result = '/state/extended';
expect(multisensor.getApiUrl('multisensorExtendedState')).to.be.equal(result);
});
it('expect false on unsupported call', () => {
expect(multisensor.getApiUrl('notExisting')).to.be.false;
});
});

describe('test multisensor.getDeviceTypeMapping', () => {
it('expect supported devices by this API', () => {
const result = {
multisensor: 'multisensor',
tempSensor_PRO: 'multisensor',
tempSensorAC: 'multisensor',
humiditySensor: 'multisensor',
windSensor_PRO: 'multisensor',
rainSensor: 'multisensor',
floodSensor: 'multisensor',
};

expect(JSON.stringify(multisensor.getDeviceTypeMapping())).to.be.equal(JSON.stringify(result));
});
});
2 changes: 1 addition & 1 deletion lib/saunabox.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function getApiUrl(type, value) {
case 'saunaboxSetdesiredTemp':
return `/s/t/${value}`;
default:
break;
return false;
}
}

Expand Down
44 changes: 44 additions & 0 deletions lib/saunabox.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable no-undef */
'use strict';
const saunabox = require('./saunabox');

const { expect } = require('chai');

const datapointDesiredTemp = {
path: 'command.desiredTemp',
type: 'state',
common: {
name: 'temperature in celsius. It should be value between max&min from settings',
type: 'number',
role: 'value',
read: true,
write: true,
},
};

describe('test saunabox.getDatapoints', () => {
const result = saunabox.datapoints;
it(`expect saunabox#command.desiredTemp object`, () => {
expect(JSON.stringify(result['saunabox#command.desiredTemp'])).to.equal(JSON.stringify(datapointDesiredTemp));
});
});

describe('test saunabox.getApiUrl', () => {
it('expect correct URL', () => {
const result = '/api/heat/extended/state';
expect(saunabox.getApiUrl('saunaboxExtendedState')).to.be.equal(result);
});
it('expect false on unsupported call', () => {
expect(saunabox.getApiUrl('notExisting')).to.be.false;
});
});

describe('test saunabox.getDeviceTypeMapping', () => {
it('expect supported devices by this API', () => {
const result = {
saunabox: 'saunabox',
};

expect(JSON.stringify(saunabox.getDeviceTypeMapping())).to.be.equal(JSON.stringify(result));
});
});
2 changes: 1 addition & 1 deletion lib/shutterbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function getApiUrl(type, value) {
case 'shutterExtendedState':
return '/api/shutter/extended/state';
default:
break;
return false;
}
}

Expand Down
48 changes: 48 additions & 0 deletions lib/shutterbox.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable no-undef */
'use strict';
const shutterbox = require('./shutterbox');

const { expect } = require('chai');

const datapointMoveCommand = {
path: 'command.move',
type: 'state',
common: {
name: 'move up (u), down (d), stop (s)',
type: 'string',
role: 'text',
read: true,
write: true,
states: { u: 'Up', d: 'Down', s: 'Stop' },
},
};

describe('test shutterbox.getDatapoints', () => {
const result = shutterbox.datapoints;
it(`expect command.move object`, () => {
expect(JSON.stringify(result['shutterbox#command.move'])).to.equal(JSON.stringify(datapointMoveCommand));
});
});

describe('test shutterbox.getApiUrl', () => {
it('expect correct URL', () => {
const result = '/api/shutter/extended/state';
expect(shutterbox.getApiUrl('shutterExtendedState')).to.be.equal(result);
});

it('expect false on unsupported call', () => {
expect(shutterbox.getApiUrl('notExisting')).to.be.false;
});
});

describe('test shutterbox.getDeviceTypeMapping', () => {
it('expect supported devices by this API', () => {
const result = {
shutterbox: 'shutterbox',
shutterboxDC: 'shutterbox',
shutterboxDIN: 'shutterbox',
};

expect(JSON.stringify(shutterbox.getDeviceTypeMapping())).to.be.equal(JSON.stringify(result));
});
});
2 changes: 1 addition & 1 deletion lib/switchbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function getApiUrl(type, value) {
case 'switchExtendedState':
return '/state/extended';
default:
break;
return false;
}
}

Expand Down
51 changes: 51 additions & 0 deletions lib/switchbox.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* eslint-disable no-undef */
'use strict';
const switchbox = require('./switchbox');

const { expect } = require('chai');

const datapointRelayCommand = {
path: 'command.relay',
type: 'state',
common: {
name: 'set state off (0) or on (1) or toggle (2)',
type: 'string',
role: 'text',
read: true,
write: true,
states: { 0: 'Off', 1: 'On', 2: 'Toggle' },
},
};

describe('test switchbox.getDatapoints', () => {
const result = switchbox.datapoints;
it(`expect command.move object`, () => {
expect(JSON.stringify(result['switchbox#command.relay'])).to.equal(JSON.stringify(datapointRelayCommand));
});
});

describe('test switchbox.getApiUrl', () => {
it('expect correct URL', () => {
const result = '/state/extended';
expect(switchbox.getApiUrl('switchExtendedState')).to.be.equal(result);
});

it('expect false on unsupported call', () => {
expect(switchbox.getApiUrl('notExisting')).to.be.false;
});
});

describe('test switchbox.getDeviceTypeMapping', () => {
it('expect supported devices by this API', () => {
const result = {
switchbox: 'switchbox',
switchBoxD: 'switchbox',
switchBoxDC: 'switchbox',
switchBox_DIN: 'switchbox',
switchBoxD_DIN: 'switchbox',
switchBoxT_PRO: 'switchbox',
};

expect(JSON.stringify(switchbox.getDeviceTypeMapping())).to.be.equal(JSON.stringify(result));
});
});
2 changes: 1 addition & 1 deletion lib/tempsensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function getApiUrl(type, _value) {
case 'tempsensorExtendedState':
return '/api/tempsensor/state';
default:
break;
return false;
}
}

Expand Down
46 changes: 46 additions & 0 deletions lib/tempsensor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable no-undef */
'use strict';
const tempsensor = require('./tempsensor');

const { expect } = require('chai');

const datapointElapsedTimeS = {
path: 'tempSensor.sensors.0.elapsedTimeS',
type: 'state',
common: {
name: 'Time in seconds that has elapsed since last valid measurement occurred, where -1 = Error, 0 = Fresh data',
type: 'number',
role: 'value',
read: true,
write: false,
},
};

describe('test tempsensor.getDatapoints', () => {
const result = tempsensor.datapoints;
it(`expect command.move object`, () => {
expect(JSON.stringify(result['tempsensor#tempSensor.sensors[0].elapsedTimeS'])).to.equal(
JSON.stringify(datapointElapsedTimeS),
);
});
});

describe('test tempsensor.getApiUrl', () => {
it('expect correct URL', () => {
const result = '/api/tempsensor/state';
expect(tempsensor.getApiUrl('tempsensorExtendedState')).to.be.equal(result);
});
it('expect false on unsupported call', () => {
expect(tempsensor.getApiUrl('notExisting')).to.be.false;
});
});

describe('test tempsensor.getDeviceTypeMapping', () => {
it('expect supported devices by this API', () => {
const result = {
tempsensor: 'tempsensor',
};

expect(JSON.stringify(tempsensor.getDeviceTypeMapping())).to.be.equal(JSON.stringify(result));
});
});
Loading
Loading