Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
srware committed Jul 10, 2019
2 parents 01843ed + ba4b50a commit e042284
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 58 deletions.
5 changes: 3 additions & 2 deletions api/rest/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ module.exports.device = {
GET_TAGS: '/v1/api/accounts/{accountid}/devices/tags',
GET_ATTRIBUTES: '/v1/api/accounts/{accountid}/devices/attributes',
COUNTS_ADVANCED: '/v1/api/accounts/{accountId}/devices/count',
SEARCH_ADVANCED: '/v1/api/accounts/{accountId}/devices/search'
SEARCH_ADVANCED: '/v1/api/accounts/{accountId}/devices/search',
TOTALS: '/v1/api/accounts/{accountId}/devices/totals'
}

module.exports.rules = {
Expand Down Expand Up @@ -125,4 +126,4 @@ module.exports.invitation = {
GET: '/v1/api/invites/{email}',
DELETE: '/v1/api/accounts/{accountId}/invites/{email}',
ACCEPT: '/v1/api/invites/{inviteId}/status'
}
}
34 changes: 17 additions & 17 deletions api/rest/cmpcatalog.def.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ module.exports = function(config) {

var module = {};

function GetCatalogOption(data) {
function DeviceCatalogOption(data) {
this.pathname = api.cmpcatalog.GET_CATALOG;
this.token = data.userToken;
this.token = data.deviceToken;
ConnectionOptions.call(this);
this.method = 'GET';
}
GetCatalogOption.prototype = new ConnectionOptions();
GetCatalogOption.prototype.constructor = GetCatalogOption;
module.GetCatalogOption = GetCatalogOption;
DeviceCatalogOption.prototype = new ConnectionOptions();
DeviceCatalogOption.prototype.constructor = DeviceCatalogOption;
module.DeviceCatalogOption = DeviceCatalogOption;

function CatalogFullOption(data) {
function CatalogOption(data) {
this.pathname = common.buildPath(api.cmpcatalog.GET_CATALOG_FULL, data.accountId);
this.token = data.userToken;
ConnectionOptions.call(this);
this.method = 'GET';
}
CatalogFullOption.prototype = new ConnectionOptions();
CatalogFullOption.prototype.constructor = CatalogFullOption;
module.CatalogFullOption = CatalogFullOption;
CatalogOption.prototype = new ConnectionOptions();
CatalogOption.prototype.constructor = CatalogOption;
module.CatalogOption = CatalogOption;

function CreateCatalogOption(data) {
this.pathname = common.buildPath(api.cmpcatalog.CREATE_CATALOG_FULL, data.accountId);
Expand All @@ -62,25 +62,25 @@ module.exports = function(config) {
CreateCatalogOption.prototype.constructor = CreateCatalogOption;
module.CreateCatalogOption = CreateCatalogOption;

function GetCatalogDetailOption(data) {
function DeviceCatalogDetailOption(data) {
this.pathname = common.buildPath(api.cmpcatalog.GET_COMPONENT, data.componentId);
this.token = data.userToken;
ConnectionOptions.call(this);
this.method = 'GET';
}
GetCatalogDetailOption.prototype = new ConnectionOptions();
GetCatalogDetailOption.prototype.constructor = GetCatalogDetailOption;
module.GetCatalogDetailOption = GetCatalogDetailOption;
DeviceCatalogDetailOption.prototype = new ConnectionOptions();
DeviceCatalogDetailOption.prototype.constructor = DeviceCatalogDetailOption;
module.DeviceCatalogDetailOption = DeviceCatalogDetailOption;

function GetCatalogDetailFullOption(data) {
function CatalogDetailOption(data) {
this.pathname = common.buildPath(api.cmpcatalog.GET_COMPONENT_FULL, [data.accountId, data.componentId]);
this.token = data.userToken;
ConnectionOptions.call(this);
this.method = 'GET';
}
GetCatalogDetailFullOption.prototype = new ConnectionOptions();
GetCatalogDetailFullOption.prototype.constructor = GetCatalogDetailFullOption;
module.GetCatalogDetailFullOption = GetCatalogDetailFullOption;
CatalogDetailOption.prototype = new ConnectionOptions();
CatalogDetailOption.prototype.constructor = CatalogDetailOption;
module.CatalogDetailOption = CatalogDetailOption;

function UpdateCatalogOption(data) {
this.pathname = common.buildPath(api.cmpcatalog.UPDATE_COMPONENT_FULL, [data.accountId, data.componentId]);
Expand Down
11 changes: 11 additions & 0 deletions api/rest/devices.def.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,16 @@ module.exports = function(config) {
CreateDeviceOption.prototype.constructor = SearchDevicesOption;
module.SearchDevicesOption = SearchDevicesOption;

function GetTotalsOption(data) {
this.pathname = common.buildPath(api.device.TOTALS, data.accountId);
this.token = data.userToken;
ConnectionOptions.call(this);
this.method = 'GET';
this.body = null;
}
CreateDeviceOption.prototype = new ConnectionOptions();
CreateDeviceOption.prototype.constructor = GetTotalsOption;
module.GetTotalsOption = GetTotalsOption;

return module;
}
23 changes: 10 additions & 13 deletions api/rest/iot.cmpcatalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ module.exports = function(config) {

module.httpClient = require('../../lib/httpClient');
module.CatalogDef = require('./cmpcatalog.def')(config);
/*
* The following methods should be executed only with device-token not with user/admin token
*
*/
module.getCatalog = function (data, callback) {
var catalog = new module.CatalogDef.GetCatalogOption(data);

module.getDeviceCatalog = function (data, callback) {
var catalog = new module.CatalogDef.DeviceCatalogOption(data);
return module.httpClient.httpRequest(catalog, callback);
};

module.getCatalogWithFullPath = function (data, callback) {
var catalog = new module.CatalogDef.CatalogFullOption(data);
module.getCatalog = function (data, callback) {
var catalog = new module.CatalogDef.CatalogOption(data);
return module.httpClient.httpRequest(catalog, callback);
};

Expand All @@ -48,13 +45,13 @@ module.exports = function(config) {
return module.httpClient.httpRequest(createCatalogOpt, callback);
};

module.getCatalogDetail = function (data, callback) {
var getCatalogDetailOpt = new module.CatalogDef.GetCatalogDetailOption(data);
return module.httpClient.httpRequest(getCatalogDetailOpt, callback);
module.getDeviceCatalogDetail = function (data, callback) {
var getDeviceCatalogDetailOpt = new module.CatalogDef.DeviceCatalogDetailOption(data);
return module.httpClient.httpRequest(getDeviceCatalogDetailOpt, callback);
};

module.getCatalogDetailWithFullPath = function (data, callback) {
var getCatalogDetailOpt = new module.CatalogDef.GetCatalogDetailFullOption(data);
module.getCatalogDetail = function (data, callback) {
var getCatalogDetailOpt = new module.CatalogDef.CatalogDetailOption(data);
return module.httpClient.httpRequest(getCatalogDetailOpt, callback);
};

Expand Down
10 changes: 10 additions & 0 deletions api/rest/iot.devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ module.exports = function(config) {
return module.httpClient.httpRequest(searchDevicesOpt, callback);
}

/**
* @description Get summary of active/inactive/created devices. API: GET: /v1/api/accounts/{accountId}/devices/totals
* @param data.userToken contains the access token
* @param data.accountId the id of the account
* @param data.body contains the filters as described in API spec
*/
module.getTotals = function(data, callback) {
var getTotalsOpt = new module.adminDef.devices.GetTotalsOption(data);
return module.httpClient.httpRequest(getTotalsOpt, callback);
}

/*
* The following methods should be executed only with device-token not with user/admin token
Expand Down
2 changes: 1 addition & 1 deletion lib/proxies/iot.rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ IoTKitRestCloud.prototype.getCatalog = function (data, callback) {
var dataPayload = {
deviceToken: data.deviceToken
};
me.client.cmpcatalog.getCatalog(dataPayload, function (err, response) {
me.client.cmpcatalog.getDeviceCatalog(dataPayload, function (err, response) {
if (!err && response) {
callback(response);
} else {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@open-iot-service-platform/oisp-sdk-js",
"version": "1.0.0",
"version": "1.0.1",
"description": "OISP SDK for Node.js",
"main": "index.js",
"scripts": {
Expand Down
22 changes: 9 additions & 13 deletions test/api_cmpcatalog.defTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe(fileToTest, function() {
function makeTokenBearer (token) {
return "Bearer " + token;
}
it('Shall Return the CatalogOption for Request >', function(done) {
it('Shall Return the DeviceCatalogOption for Request >', function(done) {
var config = {
connector: {
rest: {
Expand All @@ -51,7 +51,7 @@ describe(fileToTest, function() {
};

var toTest = require(fileToTest)(config);
var deTest = new toTest.GetCatalogOption(data);
var deTest = new toTest.DeviceCatalogOption(data);
var urD = url.parse(deTest.url);
assert.equal(urD.hostname, config.connector.rest.host, "the host data is missing");
assert.equal(urD.port, config.connector.rest.port, "the port were missing");
Expand All @@ -60,12 +60,10 @@ describe(fileToTest, function() {
assert.equal(deTest.method, "GET", "The verb is incorrect");
assert.isObject(deTest.headers, "Shall be an Object with a Key-Value for HTTP Header");
assert.property(deTest.headers, "Content-type", "The content Type has not Set");
assert.property(deTest.headers, "Authorization", "The Authorization Header has not set");
assert.equal(deTest.headers["Authorization"], makeTokenBearer(data.userToken));
done();
});

it('Shall Return the CatalogOption with full path for Request >', function(done) {
it('Shall Return the CatalogOption for Request >', function(done) {
var config = {
connector: {
rest: {
Expand All @@ -87,7 +85,7 @@ describe(fileToTest, function() {
};

var toTest = require(fileToTest)(config);
var deTest = new toTest.CatalogFullOption(data);
var deTest = new toTest.CatalogOption(data);
var urD = url.parse(deTest.url);
assert.equal(urD.hostname, config.connector.rest.host, "the host data is missing");
assert.equal(urD.port, config.connector.rest.port, "the port were missing");
Expand Down Expand Up @@ -138,7 +136,7 @@ describe(fileToTest, function() {
done();
});

it('Shall Return the GetCatalogDetailOption for Request >', function(done) {
it('Shall Return the DeviceCatalogDetailOption for Request >', function(done) {
var config = {
connector: {
rest: {
Expand All @@ -160,7 +158,7 @@ describe(fileToTest, function() {
};

var toTest = require(fileToTest)(config);
var deTest = new toTest.GetCatalogDetailOption(data);
var deTest = new toTest.DeviceCatalogDetailOption(data);
var urD = url.parse(deTest.url);
assert.equal(urD.hostname, config.connector.rest.host, "the host data is missing");
assert.equal(urD.port, config.connector.rest.port, "the port were missing");
Expand All @@ -169,12 +167,10 @@ describe(fileToTest, function() {
assert.equal(deTest.method, "GET", "The verb is incorrect");
assert.isObject(deTest.headers, "Shall be an Object with a Key-Value for HTTP Header");
assert.property(deTest.headers, "Content-type", "The content Type has not Set");
assert.property(deTest.headers, "Authorization", "The Authorization Header has not set");
assert.equal(deTest.headers["Authorization"], makeTokenBearer(data.userToken));
done();
});

it('Shall Return the GetCatalogDetailOption with full path for Request >', function(done) {
it('Shall Return the CatalogDetailOption for Request >', function(done) {
var config = {
connector: {
rest: {
Expand All @@ -197,7 +193,7 @@ describe(fileToTest, function() {
};

var toTest = require(fileToTest)(config);
var deTest = new toTest.GetCatalogDetailFullOption(data);
var deTest = new toTest.CatalogDetailOption(data);
var urD = url.parse(deTest.url);
assert.equal(urD.hostname, config.connector.rest.host, "the host data is missing");
assert.equal(urD.port, config.connector.rest.port, "the port were missing");
Expand Down Expand Up @@ -246,4 +242,4 @@ describe(fileToTest, function() {
assert.equal(deTest.headers["Authorization"], makeTokenBearer(data.userToken));
done();
});
});
});
36 changes: 36 additions & 0 deletions test/api_device.defTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,40 @@ describe(fileToTest, function() {
assert.equal(deTest.method, "POST", "The verb is incorrect");
done();
});

it('Shall Return the GetTotalsOption for Request >', function(done) {
var config = {
connector: {
rest: {
proxy: {
host: "myprox",
port: 2222
},
protocol: "http",
host: "myapi3",
port: 1000
}
}
};
var data = {
accountId: 20022,
userToken: "Thisis Mytoken",
body: {
a: 1,
d: 2,
n: [2,3]
}
};
var toTest = require(fileToTest)(config);
var deTest = new toTest.GetTotalsOption(data);
var urlD = url.parse(deTest.url);
assert.equal(urlD.hostname, config.connector.rest.host, "the host data is missing");
assert.equal(urlD.port, config.connector.rest.port, "the port were missing");
assert.equal(urlD.pathname, "/v1/api/accounts/20022/devices/totals", "path improper formed");
assert.equal(deTest.body, null);
assert.equal(deTest.method, "GET", "The verb is incorrect");
assert.equal(deTest.headers["Authorization"], makeTokenBearer(data.userToken),
"The Authorization Header has not set");
done();
});
});
22 changes: 11 additions & 11 deletions test/api_iot.cmpcatalogTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe(fileToTest, function() {
data : ""
};

it('Shall get list component types for an account >', function(done) {
it('Shall get list component types for a device >', function(done) {

var optData = {
method: 'GET',
Expand All @@ -81,7 +81,7 @@ describe(fileToTest, function() {
ar : ["222", "223"]
};

Option.GetCatalogOption = function (catalog) {
Option.DeviceCatalogOption = function (catalog) {
assert.deepEqual(catalog, data, "The Data is not oki");
return optData;
};
Expand All @@ -96,10 +96,10 @@ describe(fileToTest, function() {
};
toTest.httpClient = httpClientMock;
toTest.CatalogDef = Option;
toTest.getCatalog(data, callBack);
toTest.getDeviceCatalog(data, callBack);
});

it('Shall get list component types for an account with full path >', function(done) {
it('Shall get list component types for an account >', function(done) {

var optData = {
method: 'GET',
Expand All @@ -116,7 +116,7 @@ describe(fileToTest, function() {
ar : ["222", "223"]
};

Option.CatalogFullOption = function (catalog) {
Option.CatalogOption = function (catalog) {
assert.deepEqual(catalog, data, "The Data is not oki");
return optData;
};
Expand All @@ -131,7 +131,7 @@ describe(fileToTest, function() {
};
toTest.httpClient = httpClientMock;
toTest.CatalogDef = Option;
toTest.getCatalogWithFullPath(data, callBack);
toTest.getCatalog(data, callBack);
});

it('Shall create a new component type and control the Response from device Registration >', function(done) {
Expand Down Expand Up @@ -186,7 +186,7 @@ describe(fileToTest, function() {
ar : ["222", "223"]
};

Option.GetCatalogDetailOption = function (catalog) {
Option.DeviceCatalogDetailOption = function (catalog) {
assert.deepEqual(catalog, data, "The Data is not oki");
return optData;
};
Expand All @@ -201,10 +201,10 @@ describe(fileToTest, function() {
};
toTest.httpClient = httpClientMock;
toTest.CatalogDef = Option;
toTest.getCatalogDetail(data, callBack);
toTest.getDeviceCatalogDetail(data, callBack);
});

it('Shall get component detail with full path >', function(done) {
it('Shall get component detail for a given account >', function(done) {

var optData = {
method: 'GET',
Expand All @@ -221,7 +221,7 @@ describe(fileToTest, function() {
ar : ["222", "223"]
};

Option.GetCatalogDetailFullOption = function (catalog) {
Option.CatalogDetailOption = function (catalog) {
assert.deepEqual(catalog, data, "The Data is not oki");
return optData;
};
Expand All @@ -236,7 +236,7 @@ describe(fileToTest, function() {
};
toTest.httpClient = httpClientMock;
toTest.CatalogDef = Option;
toTest.getCatalogDetailWithFullPath(data, callBack);
toTest.getCatalogDetail(data, callBack);
});


Expand Down
Loading

0 comments on commit e042284

Please sign in to comment.