Skip to content
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"build": "node build.js",
"test": "node_modules/.bin/mocha test/unit/**/**.spec.js --exit"
"test": "npm run unitTest & npm run integrationTest",
"unitTest": "node_modules/.bin/mocha test/unit/**/**.spec.js --exit",
"integrationTest": "node_modules/.bin/mocha test/integration/**/**.spec.js --timeout 10000 --exit"
},
"repository": {
"type": "git",
Expand Down
10 changes: 0 additions & 10 deletions src/models/Configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ class Configuration extends BaseModel {
* @param {Object} options - model options object
* @param {string} options.name - Configuration parameter name.
* @param {string} options.value - Configuration parameter value.
* @param {number} options.entityVersion - Specifies the version field or property of an entity class.
*/
constructor({ name, value, entityVersion } = {}) {
super();

this.name = name;
this.value = value;
this.entityVersion = entityVersion;
}

get name() {
Expand All @@ -37,14 +35,6 @@ class Configuration extends BaseModel {
this._value = value;
}

get entityVersion() {
return this._entityVersion;
}

set entityVersion(value) {
this._entityVersion = value;
}

/**
* Returns instance as a plain JS object
* @returns {Object}
Expand Down
16 changes: 8 additions & 8 deletions src/models/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class Device extends BaseModel {
* @param {object} options.data - Device data, a JSON object with an arbitrary structure
* @param {number} options.networkId - Associated network id
* @param {number} options.deviceTypeId - Associated deviceType id
* @param {boolean} options.blocked - Indicates whether device is blocked
* @param {boolean} options.isBlocked - Indicates whether device is isBlocked
*/
constructor({ id, name, data, networkId, deviceTypeId, blocked } = {}) {
constructor({ id, name, data, networkId, deviceTypeId, isBlocked } = {}) {
super();

this.id = id;
this.name = name;
this.data = data;
this.networkId = networkId;
this.deviceTypeId = deviceTypeId;
this.blocked = blocked;
this.isBlocked = isBlocked;
}

get id() {
Expand Down Expand Up @@ -67,12 +67,12 @@ class Device extends BaseModel {
this._deviceTypeId = value;
}

get blocked() {
return this._blocked;
get isBlocked() {
return this._isBlocked;
}

set blocked(value) {
this._blocked = value;
set isBlocked(value) {
this._isBlocked = value;
}

/**
Expand All @@ -86,7 +86,7 @@ class Device extends BaseModel {
data: this.data,
networkId: this.networkId,
deviceTypeId: this.deviceTypeId,
blocked: this.blocked
isBlocked: this.isBlocked
};
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/models/query/PluginRegisterQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ class PluginRegisterQuery extends BaseModel {
* @param {boolean} [options.returnUpdatedCommands] - Checks if updated commands should be returned
* @param {boolean} [options.returnNotifications] - Checks if commands should be returned
*/
constructor({ deviceId, networkIds, deviceTypeIds, names, returnCommands, returnUpdatedCommands, returnNotifications } = {}) {
constructor({ deviceId, networkIds, deviceTypeIds, names, returnCommands = true, returnUpdatedCommands = false, returnNotifications = false } = {}) {
super();

this.deviceId = deviceId;
this.networkIds = networkIds;
this.deviceTypeIds = deviceTypeIds;
Expand Down
16 changes: 16 additions & 0 deletions test/integration/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"server": {
"http": {
"login": "dhadmin",
"password": "dhadmin_#911",
"mainServiceURL": "http://localhost:8080/dh/rest",
"authServiceURL": "http://localhost:8090/dh/rest",
"pluginServiceURL": "http://localhost:8110/dh/rest"
},
"ws": {
"login": "dhadmin",
"password": "dhadmin_#911",
"mainServiceURL": "ws://localhost:8080/dh/websocket"
}
}
}
66 changes: 66 additions & 0 deletions test/integration/controllers/ConfigurationAPI.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const chai = require(`chai`);
const assert = chai.assert;
const config = require('../config');

const EventEmitter = require('events');
const events = new EventEmitter();

const DeviceHive = require('../../../index');

const httpDeviceHive = new DeviceHive(config.server.http);
const wsDeviceHive = new DeviceHive(config.server.ws)


const testConfigurations = [
{
name: 'myTestName',
value: 'string'
},
{
name: 'myTestName2',
value: 'string'
}
];

describe('ConfigurationAPI', () => {

before(done => {
// Configaratuion DeviceHive
Promise.all([httpDeviceHive.connect(), wsDeviceHive.connect()])
.then(() => done());
});


it('ConfigurationAPI.put()', done => {

// Configurating Configaration model
const configuration = new DeviceHive.models.Configuration(testConfigurations[0]);
const configuration2 = new DeviceHive.models.Configuration(testConfigurations[1]);

Promise.all([httpDeviceHive.configuration.put(configuration), wsDeviceHive.configuration.put(configuration2)])
.then(() => done())
.catch(done);
});


it('ConfigurationAPI.get()', done => {

Promise.all([httpDeviceHive.configuration.get(testConfigurations[0].name), wsDeviceHive.configuration.get(testConfigurations[1].name)])
.then(dataAll => {
for (const key in dataAll) {
assert.isObject(dataAll[key])
assert.include(dataAll[key], testConfigurations[key]);
}
})
.then(done)
.catch(done);
});


it('ConfigurationAPI.delete()', done => {

Promise.all([httpDeviceHive.configuration.delete(testConfigurations[0].name), wsDeviceHive.configuration.delete(testConfigurations[1].name)])
.then(() => done())
.catch(done);
});
});
118 changes: 118 additions & 0 deletions test/integration/controllers/Device.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const chai = require(`chai`);
const assert = chai.assert;
const config = require('../config');

const EventEmitter = require('events');
const events = new EventEmitter();

const DeviceHive = require('../../../index');

const httpDeviceHive = new DeviceHive(config.server.http);
const wsDeviceHive = new DeviceHive(config.server.ws)


const testDevices = [
{
id: 'myTestId',
name: 'myTestName',
networkId: 1,
deviceTypeId: 1,
isBlocked: false
}, {
id: 'myTestId2',
name: 'myTestName',
networkId: 1,
deviceTypeId: 1,
isBlocked: false
}
];

describe('DeviceAPI', () => {

before(done => {
// Configaratuion DeviceHive

Promise.all([httpDeviceHive.connect(), wsDeviceHive.connect()])
.then(() => done());
});


it('DeviceAPI.add()', done => {

// Configurating Device model
const Device = DeviceHive.models.Device;

const device = new Device(testDevices[0]);
const device2 = new Device(testDevices[1]);

Promise.all([httpDeviceHive.device.add(device), wsDeviceHive.device.add(device2)])
.then(() => done())
.catch(done);
});


it('DeviceAPI.get()', done => {

const expected = {
deviceId: testDevices[0].id
};

Promise.all([httpDeviceHive.device.get(expected.deviceId), wsDeviceHive.device.get(expected.deviceId)])
.then(dataAll => {
for (const data of dataAll) {
assert.isObject(data)
assert.include(data, testDevices[0]);
}
})
.then(done)
.catch(done);
});


it('DeviceAPI.list()', done => {

// Configurating Device List query
const deviceListQuery = new DeviceHive.models.query.DeviceListQuery({
networkId: 1
});


Promise.all([httpDeviceHive.device.list(deviceListQuery), wsDeviceHive.device.list(deviceListQuery)])
.then(dataAll => {
for (const data of dataAll) {
for (const device of data) {
assert.containsAllKeys(device, Object.keys(testDevices[0]));
}
}
})
.then(done)
.catch(done);

});


it('DeviceAPI.count()', done => {

// Configurating Device List query
const deviceListQuery = new DeviceHive.models.query.DeviceCountQuery({
networkId: '1'
});

Promise.all([httpDeviceHive.device.count(deviceListQuery), wsDeviceHive.device.count(deviceListQuery)])
.then(dataAll => {
for (const data of dataAll) {
assert.property(data, 'count');
}
})
.then(done)
.catch(done);
});


it('DeviceAPI.delete()', done => {

Promise.all([httpDeviceHive.device.delete(testDevices[0].id), wsDeviceHive.device.delete(testDevices[1].id)])
.then(() => done())
.catch(done);
});
});
Loading