From 6a29d498a9fc4505d3a08eb58ac58b4b3dd620ab Mon Sep 17 00:00:00 2001 From: antgrisha Date: Mon, 28 May 2018 15:38:04 +0300 Subject: [PATCH] updated cleanup function --- integration-tests/rest-plugin.js | 20 ++------ integration-tests/ws-command.js | 70 ++++++---------------------- integration-tests/ws-notification.js | 58 ++++++----------------- integration-tests/ws-subscription.js | 17 ++----- 4 files changed, 37 insertions(+), 128 deletions(-) diff --git a/integration-tests/rest-plugin.js b/integration-tests/rest-plugin.js index 056f572..eebc111 100644 --- a/integration-tests/rest-plugin.js +++ b/integration-tests/rest-plugin.js @@ -725,10 +725,7 @@ describe('REST API Plugin', function () { createNotification(notification, deviceId); function cleanUp(err) { - if (err) { - done(err); - } - unsubscribe(client, topic, done); + unsubscribe(client, topic, () => done(err)); } } } @@ -755,10 +752,7 @@ describe('REST API Plugin', function () { } function cleanUp(err) { - if (err) { - done(err); - } - unsubscribe(client, topic, done); + unsubscribe(client, topic, () => done(err)); } } } @@ -788,11 +782,7 @@ describe('REST API Plugin', function () { } function cleanUp(err) { - if (err) { - return done(err); - } - - unsubscribe(client, topic, done); + unsubscribe(client, topic, () => done(err)); } } } @@ -1906,7 +1896,7 @@ describe('REST API Plugin', function () { }); }); - describe('#Plugin List', function () { + describe.only('#Plugin List', function () { var PLUGIN_USER = utils.getName('plugin'); var PLUGIN1 = utils.getName('plugin'); var PLUGIN2 = utils.getName('plugin'); @@ -2049,7 +2039,7 @@ describe('REST API Plugin', function () { }) }); - it('should get sorteed plugins by Id ASC', function (done) { + it('should get sorted plugins by Id ASC', function (done) { var params = { jwt: utils.jwt.admin }; diff --git a/integration-tests/ws-command.js b/integration-tests/ws-command.js index 5f1e1e3..f84e42e 100644 --- a/integration-tests/ws-command.js +++ b/integration-tests/ws-command.js @@ -710,14 +710,11 @@ describe('WebSocket API Command', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } client.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); client.send({ action: 'command/unsubscribe', @@ -791,16 +788,13 @@ describe('WebSocket API Command', function () { }); function cleanUp(err) { - if (err) { - return done(err); - } var requestId = getRequestId(); client.on({ action: 'command/unsubscribe', requestId: requestId - }, done); + }, () => done(err)); client.send({ action: 'command/unsubscribe', @@ -881,15 +875,11 @@ describe('WebSocket API Command', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } - var requestId = getRequestId(); conn.on({ action: 'command/unsubscribe', requestId: requestId - }, done); + }, () => done(err)); conn.send({ action: 'command/unsubscribe', requestId: requestId @@ -951,13 +941,10 @@ describe('WebSocket API Command', function () { }); function cleanUp(err) { - if (err) { - return done(err); - } conn.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); conn.send({ action: 'command/unsubscribe', @@ -1013,14 +1000,10 @@ describe('WebSocket API Command', function () { }); function cleanUp(err) { - if (err) { - return done(err); - } - conn.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); conn.send({ action: 'command/unsubscribe', @@ -1077,13 +1060,10 @@ describe('WebSocket API Command', function () { }); function cleanUp(err) { - if (err) { - return done(err); - } adminConn.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); adminConn.send({ action: 'command/unsubscribe', requestId: getRequestId(), @@ -1153,10 +1133,6 @@ describe('WebSocket API Command', function () { function cleanUp(err) { - if (err) { - return done(err); - } - adminConn.send({ action: 'device/delete', requestId: requestId, @@ -1166,11 +1142,11 @@ describe('WebSocket API Command', function () { action: 'device/delete', requestId: requestId, status: 'success' - }, (err, result) => { + }, () => { adminConn.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); adminConn.send({ action: 'command/unsubscribe', requestId: getRequestId(), @@ -1239,10 +1215,6 @@ describe('WebSocket API Command', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } - conn.send({ action: 'device/delete', requestId: requestId, @@ -1252,12 +1224,11 @@ describe('WebSocket API Command', function () { action: 'device/delete', requestId: requestId, status: 'success' - }, (err, result) => { - + }, () => { conn.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); conn.send({ action: 'command/unsubscribe', requestId: getRequestId(), @@ -1337,22 +1308,18 @@ describe('WebSocket API Command', function () { }); function cleanUp(err) { - if (err) { - return done(err); - } - var requestId = getRequestId(); conn.on({ action: 'device/delete', requestId: requestId, status: 'success' - }, (err, result) => { + }, () => { var requestId = getRequestId(); conn.on({ action: 'command/unsubscribe', requestId: requestId - }, done); + }, () => done(err)); conn.send({ action: 'command/unsubscribe', requestId: requestId, @@ -1427,10 +1394,6 @@ describe('WebSocket API Command', function () { }) function cleanUp(err) { - if (err) { - return done(err); - } - conn.send({ action: 'device/delete', requestId: requestId, @@ -1440,13 +1403,13 @@ describe('WebSocket API Command', function () { action: 'device/delete', requestId: requestId, status: 'success' - }, (err, result) => { + }, () => { var requestId = getRequestId(); conn.on({ action: 'command/unsubscribe', requestId: requestId - }, done); + }, () => done(err)); conn.send({ action: 'command/unsubscribe', @@ -1730,13 +1693,10 @@ describe('WebSocket API Command', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } client.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); client.send({ action: 'command/unsubscribe', requestId: getRequestId(), diff --git a/integration-tests/ws-notification.js b/integration-tests/ws-notification.js index 5c927f1..595d95f 100644 --- a/integration-tests/ws-notification.js +++ b/integration-tests/ws-notification.js @@ -669,13 +669,11 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } + client.on({ action: 'notification/unsubscribe', status: 'success' - }, done); + }, () => done(err)); client.send({ action: 'notification/unsubscribe', @@ -751,14 +749,11 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } conn.on({ action: 'notification/unsubscribe', status: 'success' - }, done); + }, () => done(err)); conn.send({ action: 'notification/unsubscribe', @@ -804,14 +799,10 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } - conn.on({ action: 'notification/unsubscribe', status: 'success' - }, done); + }, () => done(err)); conn.send({ action: 'notification/unsubscribe', requestId: getRequestId(), @@ -857,16 +848,12 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } - var requestId = getRequestId(); conn.on({ action: 'notification/unsubscribe', requestId: requestId - }, done); + }, () => done(err)); conn.send({ action: 'notification/unsubscribe', @@ -913,16 +900,12 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } - var requestId = getRequestId(); adminConn.on({ action: 'notification/unsubscribe', requestId: requestId - }, done); + }, () => done(err)); adminConn.send({ action: 'notification/unsubscribe', @@ -992,19 +975,15 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } - adminConn.on({ action: 'device/delete', requestId: requestId, status: 'success' - }, (err, data) => { + }, () => { adminConn.on({ action: 'notification/unsubscribe', status: 'success' - },done) + },() => done(err)) adminConn.send({ action: 'notification/unsubscribe', requestId: getRequestId(), @@ -1079,19 +1058,15 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } - conn.on({ action: 'device/delete', requestId: requestId, status: 'success' - }, (err, data) => { + }, () => { conn.on({ action: 'notification/unsubscribe', status: 'success' - }, done); + }, () => done(err)); conn.send({ action: 'notification/unsubscribe', requestId: getRequestId(), @@ -1166,18 +1141,15 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } adminConn.on({ action: 'device/delete', requestId: requestId, status: 'success' - }, err => { + }, () => { adminConn.on({ action: 'notification/unsubscribe', status: 'success' - }, done) + }, () => done(err)) adminConn.send({ action: 'notification/unsubscribe', requestId: getRequestId(), @@ -1357,13 +1329,11 @@ describe('WebSocket API Notification', function () { .send(); function cleanUp(err) { - if (err) { - return done(err); - } + client.on({ action: 'notification/unsubscribe', status: 'success' - }, done); + }, () => done(err)); client.send({ action: 'notification/unsubscribe', diff --git a/integration-tests/ws-subscription.js b/integration-tests/ws-subscription.js index cfb9e6c..280912f 100644 --- a/integration-tests/ws-subscription.js +++ b/integration-tests/ws-subscription.js @@ -232,14 +232,10 @@ describe('WebSocket API Subscription', function () { }); function cleanUp(err) { - if (err) { - return done(err); - } - device.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); device.send({ action: 'command/unsubscribe', @@ -287,14 +283,10 @@ describe('WebSocket API Subscription', function () { }); function cleanUp(err) { - if (err) { - return done(err); - } - device.on({ action: 'notification/unsubscribe', status: 'success' - }, done); + }, () => done(err)); device.send({ action: 'notification/unsubscribe', @@ -341,14 +333,11 @@ describe('WebSocket API Subscription', function () { }) function cleanUp(err) { - if (err) { - return done(err); - } device.on({ action: 'command/unsubscribe', status: 'success' - }, done); + }, () => done(err)); device.send({ action: 'command/unsubscribe',