Skip to content

Commit

Permalink
Added device activation subtests
Browse files Browse the repository at this point in the history
Signed-off-by: Oguzcan Kirmemis <[email protected]>
  • Loading branch information
oguzcankirmemis authored and wagmarcel committed Jun 27, 2019
1 parent b2ade31 commit c980672
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 4 deletions.
23 changes: 22 additions & 1 deletion tests/lib/helpers/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -380,6 +400,7 @@ module.exports = {
getDeviceDetails: getDeviceDetails,
updateDeviceDetails: updateDeviceDetails,
activateDevice: activateDevice,
activateDeviceWithoutToken: activateDeviceWithoutToken,
addDeviceComponent: addDeviceComponent,
submitData: submitData,
deleteDevice: deleteDevice,
Expand Down
22 changes: 20 additions & 2 deletions tests/oisp-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down Expand Up @@ -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) {
Expand Down
60 changes: 60 additions & 0 deletions tests/subtests/device-activation-tests.js
Original file line number Diff line number Diff line change
@@ -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
};
28 changes: 27 additions & 1 deletion tests/subtests/promise-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -389,5 +414,6 @@ module.exports = {
deleteInvite: inviteDelete,
createDevice: createDevice,
deleteDevice: deleteDevice,
activateDevice: activateDevice
activateDevice: activateDevice,
activateDeviceWithoutToken: activateDeviceWithoutToken
};

0 comments on commit c980672

Please sign in to comment.