diff --git a/tests/lib/helpers/devices.js b/tests/lib/helpers/devices.js index c41c2841..5ed830c5 100644 --- a/tests/lib/helpers/devices.js +++ b/tests/lib/helpers/devices.js @@ -39,7 +39,7 @@ function createDevice(name, deviceId, userToken, accountId, cb) { name: name, deviceId: deviceId, gatewayId: "00-11-22-33-44-55", - tags: ["tag-a", "tag-b"], + tags: ["tag-a", "tag-b"], attributes: { os: "linux" } @@ -170,6 +170,26 @@ function activateDevice(userToken, accountId, deviceId, cb) { }) } +function activateDeviceWithoutToken(activationCode, deviceId, cb) { + if (!cb) { + throw "Callback required"; + } + var data = { + deviceId: deviceId, + body: { + activationCode: activationCode + } + }; + api.devices.registerDevice(data, function(err, response) { + if (err) { + cb(err); + } else { + assert.notEqual(response, null, 'response is null') + cb(null, response); + } + }); +} + function createComponentId() { return uuid(); } @@ -380,6 +400,7 @@ module.exports = { getDeviceDetails: getDeviceDetails, updateDeviceDetails: updateDeviceDetails, activateDevice: activateDevice, + activateDeviceWithoutToken: activateDeviceWithoutToken, addDeviceComponent: addDeviceComponent, submitData: submitData, deleteDevice: deleteDevice, diff --git a/tests/oisp-tests.js b/tests/oisp-tests.js index a1bd22e3..67a5cb6d 100644 --- a/tests/oisp-tests.js +++ b/tests/oisp-tests.js @@ -78,12 +78,12 @@ components.add( new Component("images", "ByteArray", "image/jpeg", "pixel", "bin imageData, imageCheckData) ); -components.add(new Component("metaData", "String", "JSON", "text", "binaryDataRenderer", null, null, +components.add(new Component("metaData", "String", "JSON", "text", "binaryDataRenderer", null, null, [], stringData, stringCheckData) ); -components.add(new Component("binaryState", "Boolean", "state", "bool", "timeSeries", null, null, +components.add(new Component("binaryState", "Boolean", "state", "bool", "timeSeries", null, null, [], boolData, boolCheckData) ); @@ -638,6 +638,24 @@ describe("Creating account and device ...\n".bold, function() { }) }) +describe("Device Activation Subtests".bold, function() { + var test; + var descriptions = require("./subtests/device-activation-tests").descriptions; + it(descriptions.prepareSetup, function(done) { + test = require("./subtests/device-activation-tests").test(userToken, accountId); + test.prepareSetup(done); + }).timeout(10000); + it(descriptions.activateExistingDeviceWithoutToken, function(done) { + test.activateExistingDeviceWithoutToken(done); + }).timeout(10000); + it(descriptions.activateNotExistingDeviceWithoutToken, function(done) { + test.activateNotExistingDeviceWithoutToken(done); + }).timeout(10000); + it(descriptions.cleanup, function(done) { + test.cleanup(done); + }).timeout(10000); +}); + describe("Managing components catalog ... \n".bold, function() { it('Shall create new custom Components Types', function(done) { diff --git a/tests/subtests/device-activation-tests.js b/tests/subtests/device-activation-tests.js new file mode 100644 index 00000000..f3df99a5 --- /dev/null +++ b/tests/subtests/device-activation-tests.js @@ -0,0 +1,60 @@ +var test = function(userToken, accountId) { + var promtests = require('./promise-wrap'); + var activationCode; + var deviceId1 = "ACTIVATION-TEST1"; + var deviceId2 = "ACTIVATION-TEST2"; + var deviceToken1; + var deviceToken2; + + return { + "prepareSetup": function(done) { + promtests.createDevice("device1", deviceId1, userToken, accountId) + .then(() => promtests.getAccountActivationCode(accountId, userToken)) + .then((res) => { activationCode = res.activationCode; }) + .then(() => { done(); }) + .catch((err) => { done(err); }); + }, + "activateExistingDeviceWithoutToken": function(done) { + promtests.activateDeviceWithoutToken(activationCode, deviceId1).then((res) => { + if (res.deviceToken) { + deviceToken1 = res.deviceToken; + done(); + } else { + done('Cannot activate device without user token.'); + } + }).catch((err) => { + done(err); + }); + }, + "activateNotExistingDeviceWithoutToken": function(done) { + promtests.activateDeviceWithoutToken(activationCode, deviceId2).then((res) => { + if (res.deviceToken) { + deviceToken1 = res.deviceToken; + done(); + } else { + done('Cannot activate not existing device without token'); + } + }).catch((err) => { + done(err); + }); + }, + "cleanup": function(done) { + promtests.deleteDevice(userToken, accountId, deviceId1) + .then(() => { promtests.deleteDevice(userToken, accountId, deviceId2) }) + .then(() => { done(); }) + .catch((err) => { done(err); }); + } + }; +}; + +var descriptions = { + "prepareSetup": "Create device for subtest", + "activateExistingDeviceWithoutToken": "Shall activate a device only with activation code", + "activateNotExistingDeviceWithoutToken": "Shall create and activate device only with activation code", + "cleanup": "Cleanup devices that are created for subtest", +}; + +module.exports = { + test: test, + descriptions: descriptions +}; diff --git a/tests/subtests/promise-wrap.js b/tests/subtests/promise-wrap.js index ac951386..08977646 100644 --- a/tests/subtests/promise-wrap.js +++ b/tests/subtests/promise-wrap.js @@ -367,7 +367,32 @@ var activateDevice = (userToken, accountId, deviceId) => { }); }; +var activateDeviceWithoutToken = (activationCode, deviceId) => { + return new Promise(function(resolve, reject){ + helpers.devices.activateDeviceWithoutToken(activationCode, deviceId, function(err, response) { + if (err) { + reject(err); + } else { + resolve(response); + } + }); + }); +} + +var getAccountActivationCode = (accountId, userToken) => { + return new Promise(function(resolve, reject){ + helpers.accounts.getAccountActivationCode(accountId, userToken, function(err, response) { + if (err) { + reject(err); + } else { + resolve(response); + } + }); + }); +} + module.exports = { + getAccountActivationCode: getAccountActivationCode, checkObservations: checkObservations, addComponent: addComponent, addActuator: addActuator, @@ -389,5 +414,6 @@ module.exports = { deleteInvite: inviteDelete, createDevice: createDevice, deleteDevice: deleteDevice, - activateDevice: activateDevice + activateDevice: activateDevice, + activateDeviceWithoutToken: activateDeviceWithoutToken };