diff --git a/README.md b/README.md
index 8f158b7..8022c90 100644
--- a/README.md
+++ b/README.md
@@ -170,9 +170,11 @@ Returns DeviceHive models
* [DeviceListQuery](#DeviceListQuery)
* [DeviceTypeCountQuery](#DeviceTypeCountQuery)
* [DeviceTypeListQuery](#DeviceTypeListQuery)
+ * [DeviceTypeDeleteQuery](#DeviceTypeDeleteQuery)
* [PluginUpdateQuery](#PluginUpdateQuery)
* [NetworkCountQuery](#NetworkCountQuery)
* [NetworkListQuery](#NetworkListQuery)
+ * [NetworkDeleteQuery](#NetworkDeleteQuery)
* [NotificationListQuery](#NotificationListQuery)
* [NotificationPollManyQuery](#NotificationPollManyQuery)
* [NotificationPollQuery](#NotificationPollQuery)
@@ -510,7 +512,7 @@ Returns information about the current deviceType
* [.count(deviceTypeCountQuery)](#DeviceTypeAPI+count) ⇒ Promise
* [.insert(deviceType)](#DeviceTypeAPI+insert) ⇒ Promise
* [.update(deviceType)](#DeviceTypeAPI+update) ⇒ Promise
- * [.delete(deviceTypeId)](#DeviceTypeAPI+delete) ⇒ Promise
+ * [.delete(deviceTypeDeleteQuery)](#DeviceTypeAPI+delete) ⇒ Promise
@@ -559,13 +561,13 @@ Updates a deviceType
-### deviceTypeAPI.delete(deviceTypeId) ⇒ Promise
+### deviceTypeAPI.delete(deviceTypeDeleteQuery) ⇒ Promise
Deletes an existing deviceType
| Param | Type |
| --- | --- |
-| deviceTypeId | number
|
+| deviceTypeDeleteQuery | deviceTypeDeleteQuery
|
@@ -579,7 +581,7 @@ Returns information about the current network
* [.count(networkCountQuery)](#NetworkAPI+count) ⇒ Promise
* [.insert(network)](#NetworkAPI+insert) ⇒ Promise
* [.update(networkId, network)](#NetworkAPI+update) ⇒ Promise
- * [.delete(networkId)](#NetworkAPI+delete) ⇒ Promise
+ * [.delete(networkDeleteQuery)](#NetworkAPI+delete) ⇒ Promise
@@ -629,12 +631,12 @@ Updates a network
-### networkAPI.delete(networkId) ⇒ Promise
+### networkAPI.delete(networkDeleteQuery) ⇒ Promise
Deletes an existing network
| Param | Type |
| --- | --- |
-| networkId | number
|
+| networkDeleteQuery | networkDeleteQuery
|
@@ -1131,7 +1133,7 @@ Returns information about the current deviceType
* [.count(deviceTypeCountQuery)](#DeviceTypeAPI+count) ⇒ Promise
* [.insert(deviceType)](#DeviceTypeAPI+insert) ⇒ Promise
* [.update(deviceType)](#DeviceTypeAPI+update) ⇒ Promise
- * [.delete(deviceTypeId)](#DeviceTypeAPI+delete) ⇒ Promise
+ * [.delete(deviceTypeDeleteQuery)](#DeviceTypeAPI+delete) ⇒ Promise
@@ -1190,13 +1192,13 @@ Updates a deviceType
-### deviceTypeAPI.delete(deviceTypeId) ⇒ Promise
+### deviceTypeAPI.delete(deviceTypeDeleteQuery) ⇒ Promise
Deletes an existing deviceType
| Param | Type |
| --- | --- |
-| deviceTypeId | number
|
+| deviceTypeDeleteQuery | deviceTypeDeleteQuery
|
@@ -1210,7 +1212,7 @@ Returns information about the current network
* [.count(networkCountQuery)](#NetworkAPI+count) ⇒ Promise
* [.insert(network)](#NetworkAPI+insert) ⇒ Promise
* [.update(network)](#NetworkAPI+update) ⇒ Promise
- * [.delete(networkId)](#NetworkAPI+delete) ⇒ Promise
+ * [.delete(networkDeleteQuery)](#NetworkAPI+delete) ⇒ Promise
@@ -1269,14 +1271,14 @@ Updates a network
-### networkAPI.delete(networkId) ⇒ Promise
+### networkAPI.delete(networkDeleteQuery) ⇒ Promise
Deletes an existing network
**Returns**: Promise
- Network
| Param | Type |
| --- | --- |
-| networkId | number
|
+| networkDeleteQuery | networkDeleteQuery
|
@@ -2280,6 +2282,33 @@ Creates new DeviceTypeListQuery model
### deviceTypeListQuery.toObject() ⇒ Object
Returns instance as a plain JS object
+
+
+## DeviceTypeDeleteQuery
+DeviceTypeDeleteQuery class
+
+
+* [DeviceTypeDeleteQuery](#DeviceTypeDeleteQuery)
+ * [new DeviceTypeDeleteQuery(options)](#new_DeviceTypeDeleteQuery_new)
+ * [.toObject()](#DeviceTypeDeleteQuery+toObject) ⇒ Object
+
+
+
+### new DeviceTypeDeleteQuery(options)
+Creates new DeviceTypeDeleteQuery model
+
+
+| Param | Type | Description |
+| --- | --- | --- |
+| options | object
| model options object |
+| options.deviceTypeId | number
| Id of device type |
+| options.force | boolean
| Flag, if true then it will delete device type with existing devices |
+
+
+
+### deviceTypeDeleteQuery.toObject() ⇒ Object
+Returns instance as a plain JS object
+
## NetworkCountQuery
@@ -2338,6 +2367,33 @@ Creates new NetworkListQuery model
### networkListQuery.toObject() ⇒ Object
Returns instance as a plain JS object
+
+
+## NetworkDeleteQuery
+NetworkDeleteQuery class
+
+
+* [NetworkDeleteQuery](#NetworkDeleteQuery)
+ * [new NetworkDeleteQuery(options)](#new_NetworkDeleteQuery_new)
+ * [.toObject()](#NetworkDeleteQuery+toObject) ⇒ Object
+
+
+
+### new NetworkDeleteQuery(options)
+Creates new NetworkDeleteQuery model
+
+
+| Param | Type | Description |
+| --- | --- | --- |
+| options | object
| model options object |
+| options.networkId | number
| Id of network |
+| options.force | boolean
| Flag, if true then it will delete network with existing devices |
+
+
+
+### networkDeleteQuery.toObject() ⇒ Object
+Returns instance as a plain JS object
+
## NotificationListQuery
diff --git a/package.json b/package.json
index 756ac1c..e11ceeb 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "devicehive",
- "version": "2.0.2",
+ "version": "2.0.3",
"description": "DeviceHive JS Library",
"main": "index.js",
"scripts": {
diff --git a/src/DeviceHive.js b/src/DeviceHive.js
index 82e3c5a..9b25d84 100644
--- a/src/DeviceHive.js
+++ b/src/DeviceHive.js
@@ -29,9 +29,11 @@ const DeviceCountQuery = require(`./models/query/DeviceCountQuery`);
const DeviceListQuery = require(`./models/query/DeviceListQuery`);
const DeviceTypeCountQuery = require(`./models/query/DeviceTypeCountQuery`);
const DeviceTypeListQuery = require(`./models/query/DeviceTypeListQuery`);
+const DeviceTypeDeleteQuery = require('./models/query/DeviceTypeDeleteQuery');
const PluginUpdateQuery = require(`./models/query/PluginUpdateQuery`);
const NetworkCountQuery = require(`./models/query/NetworkCountQuery`);
const NetworkListQuery = require(`./models/query/NetworkListQuery`);
+const NetworkDeleteQuery = require('./models/query/NetworkDeleteQuery');
const NotificationListQuery = require(`./models/query/NotificationListQuery`);
const NotificationPollManyQuery = require(`./models/query/NotificationPollManyQuery`);
const NotificationPollQuery = require(`./models/query/NotificationPollQuery`);
@@ -73,9 +75,11 @@ class DeviceHive extends EventEmitter {
DeviceListQuery: DeviceListQuery,
DeviceTypeCountQuery: DeviceTypeCountQuery,
DeviceTypeListQuery: DeviceTypeListQuery,
+ DeviceTypeDeleteQuery: DeviceTypeDeleteQuery,
PluginUpdateQuery: PluginUpdateQuery,
NetworkCountQuery: NetworkCountQuery,
NetworkListQuery: NetworkListQuery,
+ NetworkDeleteQuery: NetworkDeleteQuery,
NotificationListQuery: NotificationListQuery,
NotificationPollManyQuery: NotificationPollManyQuery,
NotificationPollQuery: NotificationPollQuery,
diff --git a/src/controllers/DeviceTypeAPI.js b/src/controllers/DeviceTypeAPI.js
index 277e3d0..17ab8ec 100644
--- a/src/controllers/DeviceTypeAPI.js
+++ b/src/controllers/DeviceTypeAPI.js
@@ -2,6 +2,7 @@ const API = require('./API');
const ApiMap = require(`./transportResolvers/ApiMap`);
const DeviceTypeListQuery = require('../models/query/DeviceTypeListQuery');
const DeviceTypeCountQuery = require('../models/query/DeviceTypeCountQuery');
+const DeviceTypeDeleteQuery = require('../models/query/DeviceTypeDeleteQuery');
/**
@@ -59,8 +60,8 @@ class DeviceTypeAPI extends API {
* @param {number} deviceTypeId
* @returns {Promise}
*/
- delete(deviceTypeId) {
- return this.send(ApiMap.deleteDeviceType, { deviceTypeId: deviceTypeId });
+ delete(deviceTypeDeleteQuery = new DeviceTypeDeleteQuery()) {
+ return this.send(ApiMap.deleteDeviceType, deviceTypeDeleteQuery.toObject());
}
}
diff --git a/src/controllers/NetworkAPI.js b/src/controllers/NetworkAPI.js
index a2d73cb..ed7115e 100644
--- a/src/controllers/NetworkAPI.js
+++ b/src/controllers/NetworkAPI.js
@@ -2,6 +2,7 @@ const API = require('./API');
const ApiMap = require(`./transportResolvers/ApiMap`);
const NetworkListQuery = require('../models/query/NetworkListQuery');
const NetworkCountQuery = require('../models/query/NetworkCountQuery');
+const NetworkDeleteQuery = require('../models/query/NetworkDeleteQuery');
/**
@@ -59,8 +60,8 @@ class NetworkAPI extends API {
* @param {number} networkId
* @returns {Promise} Network
*/
- delete(networkId) {
- return this.send(ApiMap.deleteNetwork, { networkId: networkId });
+ delete(networkDeleteQuery = new NetworkDeleteQuery()) {
+ return this.send(ApiMap.deleteNetwork, networkDeleteQuery.toObject());
}
}
diff --git a/src/models/query/DeviceTypeDeleteQuery.js b/src/models/query/DeviceTypeDeleteQuery.js
new file mode 100644
index 0000000..c27f1a0
--- /dev/null
+++ b/src/models/query/DeviceTypeDeleteQuery.js
@@ -0,0 +1,51 @@
+const BaseModel = require(`../BaseModel`);
+
+
+/**
+ * DeviceTypeDeleteQuery class
+ */
+class DeviceTypeDeleteQuery extends BaseModel {
+
+ /**
+ * Creates new DeviceTypeDeleteQuery model
+ * @param {object} options - model options object
+ * @param {string} options.deviceTypeId - deviceType's id
+ * @param {boolean} options.force - flag for force delete
+ */
+ constructor({ deviceTypeId, force } = {}) {
+ super();
+
+ this.deviceTypeId = deviceTypeId;
+ this.force = force;
+ }
+
+ get deviceTypeId() {
+ return this._deviceTypeId;
+ }
+
+ set deviceTypeId(value) {
+ this._deviceTypeId = value;
+ }
+
+ get force() {
+ return this._force;
+ }
+
+ set force(value) {
+ this._force = value;
+ }
+
+ /**
+ * Returns instance as a plain JS object
+ * @returns {Object}
+ */
+ toObject() {
+ return {
+ deviceTypeId: this.deviceTypeId,
+ force: this.force
+ }
+ }
+}
+
+
+module.exports = DeviceTypeDeleteQuery;
\ No newline at end of file
diff --git a/src/models/query/NetworkDeleteQuery.js b/src/models/query/NetworkDeleteQuery.js
new file mode 100644
index 0000000..d4df0cc
--- /dev/null
+++ b/src/models/query/NetworkDeleteQuery.js
@@ -0,0 +1,51 @@
+const BaseModel = require(`../BaseModel`);
+
+
+/**
+ * NetworkDeleteQuery class
+ */
+class NetworkDeleteQuery extends BaseModel {
+
+ /**
+ * Creates new NetworkDeleteQuery model
+ * @param {object} options - model options object
+ * @param {string} options.networkId - network's id
+ * @param {boolean} options.force - flag for force delete
+ */
+ constructor({ networkId, force } = {}) {
+ super();
+
+ this.networkId = networkId;
+ this.force = force;
+ }
+
+ get networkId() {
+ return this._networkId;
+ }
+
+ set networkId(value) {
+ this._networkId = value;
+ }
+
+ get force() {
+ return this._force;
+ }
+
+ set force(value) {
+ this._force = value;
+ }
+
+ /**
+ * Returns instance as a plain JS object
+ * @returns {Object}
+ */
+ toObject() {
+ return {
+ networkId: this.networkId,
+ force: this.force
+ }
+ }
+}
+
+
+module.exports = NetworkDeleteQuery;
\ No newline at end of file
diff --git a/test/integration/controllers/DeviceTypeAPI.spec.js b/test/integration/controllers/DeviceTypeAPI.spec.js
index 211a86c..045aef7 100644
--- a/test/integration/controllers/DeviceTypeAPI.spec.js
+++ b/test/integration/controllers/DeviceTypeAPI.spec.js
@@ -4,8 +4,10 @@ const assert = chai.assert;
const config = require('../config');
const DeviceHive = require('../../../index');
const DeviceType = DeviceHive.models.DeviceType;
+const Device = DeviceHive.models.Device;
const DeviceTypeListQuery = DeviceHive.models.query.DeviceTypeListQuery;
const DeviceTypeCountQuery = DeviceHive.models.query.DeviceTypeCountQuery;
+const DeviceTypeDeleteQuery = DeviceHive.models.query.DeviceTypeDeleteQuery;
const httpDeviceHive = new DeviceHive(config.server.http);
const wsDeviceHive = new DeviceHive(config.server.ws);
@@ -24,6 +26,28 @@ const TEST_DEVICE_TYPES = {
}
};
+const TEST_DEVICE_ID_PREFIX = `DH-JS-LIB-DEVICE-ID-`;
+const TEST_DEVICE_NAME_PREFIX = `DH-JS-LIB-DEVICE-NAME-`;
+
+const TEST_DEVICES = {
+ HTTP: {
+ id: `${TEST_DEVICE_ID_PREFIX}HTTP`,
+ name: `${TEST_DEVICE_NAME_PREFIX}HTTP`,
+ networkId: 1,
+ deviceTypeId: 1,
+ isBlocked: false,
+ data: {}
+ },
+ WS: {
+ id: `${TEST_DEVICE_ID_PREFIX}WS`,
+ name: `${TEST_DEVICE_NAME_PREFIX}WS`,
+ networkId: 1,
+ deviceTypeId: 1,
+ isBlocked: false,
+ data: {}
+ }
+};
+
describe('DeviceTypeAPI', () => {
before(done => {
@@ -147,17 +171,72 @@ describe('DeviceTypeAPI', () => {
});
it(`should delete device type with name: ${TEST_DEVICE_TYPES.HTTP.name} via HTTP`, done => {
- httpDeviceHive.deviceType.delete(TEST_DEVICE_TYPES.HTTP.id)
+ const deviceTypeDeleteQuery = new DeviceTypeDeleteQuery({ deviceTypeId: TEST_DEVICE_TYPES.HTTP.id });
+ httpDeviceHive.deviceType.delete(deviceTypeDeleteQuery)
.then(() => done())
.catch(done);
});
it(`should delete device type with name: ${TEST_DEVICE_TYPES.WS.name} via WS`, done => {
- wsDeviceHive.deviceType.delete(TEST_DEVICE_TYPES.WS.id)
+ const deviceTypeDeleteQuery = new DeviceTypeDeleteQuery({ deviceTypeId: TEST_DEVICE_TYPES.WS.id });
+ wsDeviceHive.deviceType.delete(deviceTypeDeleteQuery)
.then(() => done())
.catch(done);
});
+ it(`should delete device type with name: ${TEST_DEVICE_TYPES.HTTP.name} via HTTP and delete all it's devices`, done => {
+
+ TEST_DEVICE_TYPES.HTTP.id = null;
+ const deviceTypeModel = new DeviceType(TEST_DEVICE_TYPES.HTTP);
+
+ httpDeviceHive.deviceType.insert(deviceTypeModel)
+ .then(({ id }) => {
+ TEST_DEVICE_TYPES.HTTP.id = id;
+ TEST_DEVICES.HTTP.deviceTypeId = id;
+ })
+ .then(() => {
+ const deviceModel = new Device(TEST_DEVICES.HTTP);
+ return httpDeviceHive.device.add(deviceModel);
+ })
+ .then(() => {
+ const deviceTypeDeleteQuery = new DeviceTypeDeleteQuery({ deviceTypeId: TEST_DEVICE_TYPES.HTTP.id, force: true });
+ return httpDeviceHive.deviceType.delete(deviceTypeDeleteQuery)
+ })
+ .then(() => httpDeviceHive.device.get(TEST_DEVICES.HTTP.id))
+ .catch(err => {
+ assert.equal(err,`Device with such deviceId = ${TEST_DEVICES.HTTP.id} not found`);
+ done();
+ });
+
+ });
+
+ it(`should delete device type with name: ${TEST_DEVICE_TYPES.WS.name} via WS and delete all it's devices`, done => {
+
+ TEST_DEVICE_TYPES.WS.id = null;
+
+ const deviceTypeModel = new DeviceType(TEST_DEVICE_TYPES.WS);
+
+ wsDeviceHive.deviceType.insert(deviceTypeModel)
+ .then(({ id }) => {
+ console.log('wow');
+ TEST_DEVICE_TYPES.WS.id = id;
+ TEST_DEVICES.WS.deviceTypeId = id;
+ })
+ .then(() => {
+ const deviceModel = new Device(TEST_DEVICES.WS);
+ return wsDeviceHive.device.add(deviceModel);
+ })
+ .then(() => {
+ const deviceTypeDeleteQuery = new DeviceTypeDeleteQuery({ deviceTypeId: TEST_DEVICE_TYPES.WS.id, force: true });
+ return wsDeviceHive.deviceType.delete(deviceTypeDeleteQuery)
+ })
+ .then(() => wsDeviceHive.device.get(TEST_DEVICES.WS.id))
+ .catch(err => {
+ assert.equal(err,`Device with such deviceId = ${TEST_DEVICES.WS.id} not found`);
+ done();
+ });
+ });
+
after(done => {
httpDeviceHive.disconnect();
wsDeviceHive.disconnect();
diff --git a/test/integration/controllers/NetworkAPI.spec.js b/test/integration/controllers/NetworkAPI.spec.js
index cab6b77..0e991ae 100644
--- a/test/integration/controllers/NetworkAPI.spec.js
+++ b/test/integration/controllers/NetworkAPI.spec.js
@@ -4,8 +4,10 @@ const assert = chai.assert;
const config = require('../config');
const DeviceHive = require('../../../index');
const Network = DeviceHive.models.Network;
+const Device = DeviceHive.models.Device;
const NetworkListQuery = DeviceHive.models.query.NetworkListQuery;
const NetworkCountQuery = DeviceHive.models.query.NetworkCountQuery;
+const NetworkDeleteQuery = DeviceHive.models.query.NetworkDeleteQuery;
const httpDeviceHive = new DeviceHive(config.server.http);
const wsDeviceHive = new DeviceHive(config.server.ws);
@@ -24,6 +26,28 @@ const TEST_NETWORKS = {
}
};
+const TEST_DEVICE_ID_PREFIX = `DH-JS-LIB-DEVICE-ID-`;
+const TEST_DEVICE_NAME_PREFIX = `DH-JS-LIB-DEVICE-NAME-`;
+
+const TEST_DEVICES = {
+ HTTP: {
+ id: `${TEST_DEVICE_ID_PREFIX}HTTP`,
+ name: `${TEST_DEVICE_NAME_PREFIX}HTTP`,
+ networkId: 1,
+ deviceTypeId: 1,
+ isBlocked: false,
+ data: {}
+ },
+ WS: {
+ id: `${TEST_DEVICE_ID_PREFIX}WS`,
+ name: `${TEST_DEVICE_NAME_PREFIX}WS`,
+ networkId: 1,
+ deviceTypeId: 1,
+ isBlocked: false,
+ data: {}
+ }
+};
+
describe('NetworkAPI', () => {
before(done => {
@@ -147,17 +171,70 @@ describe('NetworkAPI', () => {
});
it(`should delete network with name: ${TEST_NETWORKS.HTTP.name} via HTTP`, done => {
- httpDeviceHive.network.delete(TEST_NETWORKS.HTTP.id)
+ const networkDeleteQuery = new NetworkDeleteQuery({ networkId: TEST_NETWORKS.HTTP.id });
+ httpDeviceHive.network.delete(networkDeleteQuery)
.then(() => done())
.catch(done);
});
it(`should delete network with name: ${TEST_NETWORKS.WS.name} via WS`, done => {
- wsDeviceHive.network.delete(TEST_NETWORKS.WS.id)
+ const networkDeleteQuery = new NetworkDeleteQuery({ networkId: TEST_NETWORKS.WS.id });
+ wsDeviceHive.network.delete(networkDeleteQuery)
.then(() => done())
.catch(done);
});
+ it(`should delete network with name: ${TEST_NETWORKS.HTTP.name} via HTTP and delete all it's devices`, done => {
+
+ TEST_NETWORKS.HTTP.id = null;
+ const networkModel = new Network(TEST_NETWORKS.HTTP);
+
+ httpDeviceHive.network.insert(networkModel)
+ .then(({ id }) => {
+ TEST_NETWORKS.HTTP.id = id;
+ TEST_DEVICES.HTTP.networkId = id;
+ })
+ .then(() => {
+ const deviceModel = new Device(TEST_DEVICES.HTTP);
+ return httpDeviceHive.device.add(deviceModel);
+ })
+ .then(() => {
+ const networkDeleteQuery = new NetworkDeleteQuery({ networkId: TEST_NETWORKS.HTTP.id, force: true });
+ return httpDeviceHive.network.delete(networkDeleteQuery)
+ })
+ .then(() => httpDeviceHive.device.get(TEST_DEVICES.HTTP.id))
+ .catch(err => {
+ assert.equal(err,`Device with such deviceId = ${TEST_DEVICES.HTTP.id} not found`);
+ done();
+ });
+
+ });
+
+ it(`should delete network with name: ${TEST_NETWORKS.WS.name} via WS and delete all it's devices`, done => {
+
+ TEST_NETWORKS.WS.id = null;
+ const networkModel = new Network(TEST_NETWORKS.WS);
+
+ wsDeviceHive.network.insert(networkModel)
+ .then(({ id }) => {
+ TEST_NETWORKS.WS.id = id;
+ TEST_DEVICES.WS.networkId = id;
+ })
+ .then(() => {
+ const deviceModel = new Device(TEST_DEVICES.WS);
+ return wsDeviceHive.device.add(deviceModel);
+ })
+ .then(() => {
+ const networkDeleteQuery = new NetworkDeleteQuery({ networkId: TEST_NETWORKS.WS.id, force: true });
+ return wsDeviceHive.network.delete(networkDeleteQuery)
+ })
+ .then(() => wsDeviceHive.device.get(TEST_DEVICES.WS.id))
+ .catch(err => {
+ assert.equal(err,`Device with such deviceId = ${TEST_DEVICES.WS.id} not found`);
+ done();
+ });
+ });
+
after(done => {
httpDeviceHive.disconnect();
wsDeviceHive.disconnect();
diff --git a/test/integration/controllers/UserAPI.spec.js b/test/integration/controllers/UserAPI.spec.js
index 41e760e..1e70e6e 100644
--- a/test/integration/controllers/UserAPI.spec.js
+++ b/test/integration/controllers/UserAPI.spec.js
@@ -9,6 +9,8 @@ const DeviceType = DeviceHive.models.DeviceType;
const Network = DeviceHive.models.Network;
const UserListQuery = DeviceHive.models.query.UserListQuery;
const UserCountQuery = DeviceHive.models.query.UserCountQuery;
+const NetworkDeleteQuery = DeviceHive.models.query.NetworkDeleteQuery;
+const DeviceTypeDeleteQuery = DeviceHive.models.query.DeviceTypeDeleteQuery;
const httpDeviceHive = new DeviceHive(config.server.http);
const wsDeviceHive = new DeviceHive(config.server.ws);
@@ -276,7 +278,7 @@ describe(`UserAPI`, () => {
});
it(`should assign network with name: ${TEST_NETWORK.name} to user with login: ${TEST_USERS.HTTP.login} via HTTP`, done => {
- httpDeviceHive.user.assignNetwork(TEST_USERS.HTTP.id, TEST_NETWORK.id)
+ httpDeviceHive.user.assignNetwork(TEST_USERS.HTTP.id, TEST_NETWORK.id)
.then(() => done())
.catch(done);
});
@@ -334,8 +336,12 @@ describe(`UserAPI`, () => {
});
after(done => {
- httpDeviceHive.deviceType.delete(TEST_DEVICE_TYPE.id)
- .then(() => httpDeviceHive.network.delete(TEST_NETWORK.id))
+ const deviceTypeDeleteQuery = new DeviceTypeDeleteQuery({ deviceTypeId: TEST_DEVICE_TYPE.id });
+ httpDeviceHive.deviceType.delete(deviceTypeDeleteQuery)
+ .then(() => {
+ const networkDeleteQuery = new NetworkDeleteQuery({ networkId: TEST_NETWORK.id });
+ return httpDeviceHive.network.delete(networkDeleteQuery);
+ })
.then(() => {
httpDeviceHive.disconnect();
wsDeviceHive.disconnect();
diff --git a/test/unit/controllers/DeviceTypeAPI.http.spec.js b/test/unit/controllers/DeviceTypeAPI.http.spec.js
index 89c44da..aec2f66 100644
--- a/test/unit/controllers/DeviceTypeAPI.http.spec.js
+++ b/test/unit/controllers/DeviceTypeAPI.http.spec.js
@@ -172,15 +172,22 @@ describe('DeviceTypeAPI HTTP', () => {
});
it('DeviceTypeAPI.delete()', done => {
-
const id = '1';
+ const expectedQuery = {
+ force: 'false'
+ }
+ const deviceTypeDeleteQuery = new DeviceHive.models.query.DeviceTypeDeleteQuery({
+ deviceTypeId: id,
+ force: false
+ });
- deviceHive.deviceType.delete(id);
+ deviceHive.deviceType.delete(deviceTypeDeleteQuery);
// sent data
events.once('request', data => {
assert.equal(data.method, 'DELETE', 'Not correct method');
assert.equal(data.url.pathname, `/devicetype/${id}`, 'Not correct URL');
+ assert.deepEqual(data.url.parameters, expectedQuery, 'Not correct query');
done();
});
diff --git a/test/unit/controllers/DeviceTypeAPI.ws.spec.js b/test/unit/controllers/DeviceTypeAPI.ws.spec.js
index f041ff2..7378a26 100644
--- a/test/unit/controllers/DeviceTypeAPI.ws.spec.js
+++ b/test/unit/controllers/DeviceTypeAPI.ws.spec.js
@@ -161,11 +161,17 @@ describe('DeviceTypeAPI WS', () => {
it('DeviceTypeAPI.delete()', done => {
+ const id = '1';
const expected = {
- deviceTypeId: '1'
+ deviceTypeId: id,
+ force: false
}
+ const deviceTypeDeleteQuery = new DeviceHive.models.query.DeviceTypeDeleteQuery({
+ deviceTypeId: id,
+ force: false
+ });
- deviceHive.deviceType.delete(expected.deviceTypeId);
+ deviceHive.deviceType.delete(deviceTypeDeleteQuery);
// sent data
events.once('request', data => {
diff --git a/test/unit/controllers/NetworkAPI.http.spec.js b/test/unit/controllers/NetworkAPI.http.spec.js
index b654370..b96e9b8 100644
--- a/test/unit/controllers/NetworkAPI.http.spec.js
+++ b/test/unit/controllers/NetworkAPI.http.spec.js
@@ -174,13 +174,21 @@ describe('NetworkAPI', () => {
it('NetworkAPI.delete()', done => {
const id = '1';
+ const expectedQuery = {
+ force: 'false'
+ }
+ const networkDeleteQuery = new DeviceHive.models.query.NetworkDeleteQuery({
+ networkId: id,
+ force: false
+ });
- deviceHive.network.delete(id);
+ deviceHive.network.delete(networkDeleteQuery);
// sent data
events.once('request', data => {
assert.equal(data.method, 'DELETE', 'Not correct method');
assert.equal(data.url.pathname, `/network/${id}`, 'Not correct URL');
+ assert.deepEqual(data.url.parameters, expectedQuery, 'Not correct query');
done();
});
diff --git a/test/unit/controllers/NetworkAPI.ws.spec.js b/test/unit/controllers/NetworkAPI.ws.spec.js
index a330a88..abb35b1 100644
--- a/test/unit/controllers/NetworkAPI.ws.spec.js
+++ b/test/unit/controllers/NetworkAPI.ws.spec.js
@@ -161,11 +161,17 @@ describe('NetworkAPI WS', () => {
it('NetworkAPI.delete()', done => {
+ const id = '1';
const expected = {
- networkId: '1'
+ networkId: id,
+ force: false
}
+ const networkDeleteQuery = new DeviceHive.models.query.NetworkDeleteQuery({
+ networkId: id,
+ force: false
+ });
- deviceHive.network.delete(expected.networkId);
+ deviceHive.network.delete(networkDeleteQuery);
// sent data
events.once('request', data => {
diff --git a/test/unit/modelsQuery/DeviceTypeDeleteQuery.spec.js b/test/unit/modelsQuery/DeviceTypeDeleteQuery.spec.js
new file mode 100644
index 0000000..3085972
--- /dev/null
+++ b/test/unit/modelsQuery/DeviceTypeDeleteQuery.spec.js
@@ -0,0 +1,33 @@
+const chai = require(`chai`);
+const assert = chai.assert;
+const DeviceTypeDeleteQuery = require('../../../src/models/query/DeviceTypeDeleteQuery.js');
+
+describe('DeviceTypeDeleteQuery', () => {
+
+ const expected = {
+ deviceTypeId: '1',
+ force: false
+ };
+
+
+ describe(('DeviceTypeDeleteQuery fileds'), () => {
+ it('should create deviceTypeDeleteQuery', () => {
+ const deviceTypeDeleteQuery = new DeviceTypeDeleteQuery(expected);
+
+ Object.keys(expected).forEach(key => {
+ assert.isTrue(typeof deviceTypeDeleteQuery[key] !== 'undefined');
+ });
+ });
+ });
+
+ describe(('DeviceTypeDeleteQuery .toObject'), () => {
+ it('should convert deviceTypeDeleteQuery to object', () => {
+ const deviceTypeDeleteQuery = new DeviceTypeDeleteQuery(expected);
+ const deviceTypeDeleteQueryObject = deviceTypeDeleteQuery.toObject();
+
+ Object.keys(expected).forEach(key => {
+ assert.isTrue(deviceTypeDeleteQueryObject.hasOwnProperty(key));
+ });
+ });
+ });
+});
\ No newline at end of file
diff --git a/test/unit/modelsQuery/NetworkDeleteQuery.spec.js b/test/unit/modelsQuery/NetworkDeleteQuery.spec.js
new file mode 100644
index 0000000..7d34567
--- /dev/null
+++ b/test/unit/modelsQuery/NetworkDeleteQuery.spec.js
@@ -0,0 +1,33 @@
+const chai = require(`chai`);
+const assert = chai.assert;
+const NetworkDeleteQuery = require('../../../src/models/query/NetworkDeleteQuery.js');
+
+describe('NetworkDeleteQuery', () => {
+
+ const expected = {
+ networkId: '1',
+ force: false
+ };
+
+
+ describe(('NetworkDeleteQuery fileds'), () => {
+ it('should create networkDeleteQuery', () => {
+ const networkDeleteQuery = new NetworkDeleteQuery(expected);
+
+ Object.keys(expected).forEach(key => {
+ assert.isTrue(typeof networkDeleteQuery[key] !== 'undefined');
+ });
+ });
+ });
+
+ describe(('NetworkDeleteQuery .toObject'), () => {
+ it('should convert networkDeleteQuery to object', () => {
+ const networkDeleteQuery = new NetworkDeleteQuery(expected);
+ const networkDeleteQueryObject = networkDeleteQuery.toObject();
+
+ Object.keys(expected).forEach(key => {
+ assert.isTrue(networkDeleteQueryObject.hasOwnProperty(key));
+ });
+ });
+ });
+});
\ No newline at end of file