Skip to content

Commit

Permalink
#231 add first tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-vaNu committed Dec 23, 2024
1 parent 897a7eb commit 2bdfa5f
Show file tree
Hide file tree
Showing 7 changed files with 8,505 additions and 8,347 deletions.
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));
});
});
49 changes: 49 additions & 0 deletions lib/tools.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable no-undef */
const expect = require('chai').expect;
const tools = require('../lib/tools');

const datapoints = {
'gatebox#command.move': {
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' },
},
},
};

const fruits = [];
fruits.push('banana', 'apple', 'peach');

describe('Test isObject', function () {
it('expect false', function () {
expect(tools.isObject(null)).to.be.false;
});

it('expect true', function () {
expect(tools.isObject(['true', 'true'])).to.be.false;
});

it('expect true', function () {
expect(tools.isObject(datapoints)).to.be.true;
});
});

describe('Test isArray', function () {
it('expect true', function () {
expect(tools.isArray(fruits)).to.be.true;
});

it('expect true', function () {
expect(tools.isArray(['true', 'true'])).to.be.true;
});

it('expect false', function () {
expect(tools.isArray(datapoints)).to.be.false;
});
});
8 changes: 4 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class Blebox extends utils.Adapter {
await tools.setIobStates(response);
tools.getBleboxData(device, 'shutterExtendedState');
// eslint-disable-next-line
shutterboxRefreshJob = schedule.scheduleJob(
shutterboxRefreshJob = schedule.scheduleJob(
{
start: new Date(Date.now() + 1000),
end: new Date(Date.now() + 20000),
Expand Down Expand Up @@ -435,7 +435,7 @@ class Blebox extends utils.Adapter {
await tools.setIobStates(response);
tools.getBleboxData(device, 'tvliftExtendedState');
// eslint-disable-next-line
tvliftRefreshJob = schedule.scheduleJob(
tvliftRefreshJob = schedule.scheduleJob(
{
start: new Date(Date.now() + 1000),
end: new Date(Date.now() + 45000),
Expand Down Expand Up @@ -470,7 +470,7 @@ class Blebox extends utils.Adapter {
await tools.setIobStates(response);
tools.getBleboxData(device, 'switchState');
// eslint-disable-next-line
switchboxRefreshJob = schedule.scheduleJob(
switchboxRefreshJob = schedule.scheduleJob(
{
start: new Date(Date.now() + 1000),
end: new Date(Date.now() + 1000 * state.val + 1000),
Expand Down Expand Up @@ -550,7 +550,7 @@ class Blebox extends utils.Adapter {
await tools.setIobStates(response);
tools.getBleboxData(device, 'gateExtendedState');
// eslint-disable-next-line
gateboxRefreshJob = schedule.scheduleJob(
gateboxRefreshJob = schedule.scheduleJob(
{
start: new Date(Date.now() + 1000),
end: new Date(Date.now() + 45000),
Expand Down
Loading

0 comments on commit 2bdfa5f

Please sign in to comment.