Skip to content

Integration tests improvements #34

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

Merged
merged 1 commit into from
Feb 28, 2018
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
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"isomorphic-fetch": "^2.2.1",
"jwt-decode": "^2.2.0",
"query-string": "^5.1.0",
"randomstring": "^1.1.5",
"string-template": "^1.0.0",
"universal-websocket-client": "^1.0.1"
},
Expand Down
17 changes: 16 additions & 1 deletion src/ApiStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ class ApiStrategy extends EventEmitter {

me.strategy = new (ApiStrategy.getType(mainServiceURL))({ mainServiceURL, authServiceURL, pluginServiceURL });

me.strategy.on(`message`, (message) => { me.emit(`message`, message) });
me.strategy.on(`message`, (message) => {
if (message.subscriptionId && message.action) {
me.emit(`message`, message[message.action.split(`/`)[0]]);
} else {
me.emit(`message`, message);
}
});
}


Expand Down Expand Up @@ -96,6 +102,15 @@ class ApiStrategy extends EventEmitter {
}
});
}

/**
* Disconnects transport
*/
disconnect() {
const me = this;

me.strategy.disconnect();
}
}


Expand Down
10 changes: 10 additions & 0 deletions src/DeviceHive.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ class DeviceHive extends EventEmitter {

return me;
}

/**
* Disconnects from DeviceHive server
* @returns {*|void}
*/
disconnect() {
const me = this;

return me.strategy.disconnect();
}
}


Expand Down
13 changes: 1 addition & 12 deletions src/models/query/NotificationListQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@ class NotificationListQuery extends BaseModel {
* @param {string} options.start - Start timestamp
* @param {string} options.end - End timestamp
* @param {string} options.notification - Notification name
* @param {string} options.status - Command status
* @param {string} options.sortField - Sort field
* @param {string} options.sortOrder - Sort order
* @param {number} options.take - Limit param
* @param {number} options.skip - Skip param
*/
constructor({ deviceId, start, end, notification, status, sortField, sortOrder, take, skip } = {}) {
constructor({ deviceId, start, end, notification, sortField, sortOrder, take, skip } = {}) {
super();

this.deviceId = deviceId;
this.start = start;
this.end = end;
this.notification = notification;
this.status = status;
this.sortField = sortField;
this.sortOrder = sortOrder;
this.take = take;
Expand Down Expand Up @@ -65,14 +63,6 @@ class NotificationListQuery extends BaseModel {
this._notification = value;
}

get status() {
return this._status;
}

set status(value) {
this._status = value;
}

get sortField() {
return this._sortField;
}
Expand Down Expand Up @@ -115,7 +105,6 @@ class NotificationListQuery extends BaseModel {
start: this.start,
end: this.end,
notification: this.notification,
status: this.status,
sortField: this.sortField,
sortOrder: this.sortOrder,
take: this.take,
Expand Down
9 changes: 9 additions & 0 deletions src/transports/HTTP.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ class HTTP extends Transport {

return headers;
}

/**
* Disconnects HTTP transport
*/
disconnect() {
const me = this;

me.token= ``;
}
}


Expand Down
9 changes: 9 additions & 0 deletions src/transports/WS.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ class WS extends Transport {
});
});
}

/**
* Disconnects WS transport
*/
disconnect() {
const me = this;

me.socket.close();
}
}


Expand Down
7 changes: 7 additions & 0 deletions src/transports/base/Transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class Transport extends EventEmitter {
send() {
console.warn(`Method "send" should be implemented in nested classes`);
}

/**
* Disconnects transport
*/
disconnect() {
console.warn(`Method "disconnect" should be implemented in nested classes`);
}
}


Expand Down
3 changes: 3 additions & 0 deletions test/integration/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"TEST_USER_ID": 1,
"TEST_USER_LOGIN": "dhadmin",
"TEST_USER_PASSWORD": "dhadmin_#911",
"server": {
"http": {
"login": "dhadmin",
Expand Down
91 changes: 61 additions & 30 deletions test/integration/controllers/ConfigurationAPI.spec.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,97 @@
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 Configuration = DeviceHive.models.Configuration;

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


const testConfigurations = [
{
name: 'myTestName',
value: 'string'
const TEST_CONFIGURATIONS = {
HTTP: {
name: `myTestConfigurationName-HTTP}`,
value: `myTestConfigurationValue-HTTP}`
},
{
name: 'myTestName2',
value: 'string'
WS: {
name: `myTestConfigurationName-WS}`,
value: `myTestConfigurationValue-WS}`
}
];
};

describe('ConfigurationAPI', () => {

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

it(`should add new configuration with name ${TEST_CONFIGURATIONS.HTTP.name} and value ${TEST_CONFIGURATIONS.HTTP.value} via HTTP`, (done) => {
const configurationModel = new Configuration(TEST_CONFIGURATIONS.HTTP);

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)])
httpDeviceHive.configuration.put(configurationModel)
.then(() => done())
.catch(done);
});

it(`should add new configuration with name ${TEST_CONFIGURATIONS.WS.name} and value ${TEST_CONFIGURATIONS.WS.value} via WS`, (done) => {
const configurationModel = new Configuration(TEST_CONFIGURATIONS.WS);

it('ConfigurationAPI.get()', done => {
wsDeviceHive.configuration.put(configurationModel)
.then(() => done())
.catch(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]);
}
it(`should get configuration with name ${TEST_CONFIGURATIONS.HTTP.name} and value ${TEST_CONFIGURATIONS.HTTP.value} via HTTP`, done => {
httpDeviceHive.configuration.get(TEST_CONFIGURATIONS.HTTP.name)
.then(configuration => {
assert.isObject(configuration);
assert.equal(configuration.name, TEST_CONFIGURATIONS.HTTP.name);
assert.equal(configuration.value, TEST_CONFIGURATIONS.HTTP.value);
})
.then(done)
.then(() => done())
.catch(done);
});

it(`should get configuration with name ${TEST_CONFIGURATIONS.WS.name} and value ${TEST_CONFIGURATIONS.WS.value} via WS`, done => {
wsDeviceHive.configuration.get(TEST_CONFIGURATIONS.WS.name)
.then(configuration => {
assert.isObject(configuration);
assert.equal(configuration.name, TEST_CONFIGURATIONS.WS.name);
assert.equal(configuration.value, TEST_CONFIGURATIONS.WS.value);
})
.then(() => done())
.catch(done);
});

it('ConfigurationAPI.delete()', done => {
it(`should delete configuration with name ${TEST_CONFIGURATIONS.HTTP.name} and value ${TEST_CONFIGURATIONS.HTTP.value} via HTTP`, done => {
httpDeviceHive.configuration.delete(TEST_CONFIGURATIONS.HTTP.name)
.then(() => done())
.catch(done);
});

Promise.all([httpDeviceHive.configuration.delete(testConfigurations[0].name), wsDeviceHive.configuration.delete(testConfigurations[1].name)])
it(`should delete configuration with name ${TEST_CONFIGURATIONS.WS.name} and value ${TEST_CONFIGURATIONS.WS.value} via WS`, done => {
wsDeviceHive.configuration.delete(TEST_CONFIGURATIONS.WS.name)
.then(() => done())
.catch(done);
});

it(`should not get configuration with name ${TEST_CONFIGURATIONS.HTTP.name} and value ${TEST_CONFIGURATIONS.HTTP.value} via HTTP`, done => {
httpDeviceHive.configuration.get(TEST_CONFIGURATIONS.HTTP.name)
.then(() => done(new Error(`Configuration exists after deletion`)))
.catch(() => done());
});

it(`should not get configuration with name ${TEST_CONFIGURATIONS.WS.name} and value ${TEST_CONFIGURATIONS.WS.value} via WS`, done => {
wsDeviceHive.configuration.get(TEST_CONFIGURATIONS.WS.name)
.then(() => done(new Error(`Configuration exists after deletion`)))
.catch(() => done());
});

after(done => {
httpDeviceHive.disconnect();
wsDeviceHive.disconnect();

done();
});
});
Loading