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 Apr 18, 2020
2 parents 451e081 + 2aa2cc9 commit 956c73e
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 13 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Node CI

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install and test
run: |
npm install
npm test
env:
CI: true
2 changes: 1 addition & 1 deletion api/mqtt/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Broker(conf) {
};
me.iamHealthyTopic = "server/{hash}/healthy";
me.isLive = false;
me.pingActivate = true;
me.pingActivate = false;
me.client = {
connected: false,
end: function() {}
Expand Down
4 changes: 3 additions & 1 deletion api/rest/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports.alerts = {
module.exports.auth = {
TOKEN: '/v1/api/auth/token',
TOKEN_INFO: '/v1/api/auth/tokenInfo',
USER_INFO: '/v1/api/auth/me'
USER_INFO: '/v1/api/auth/me',
REFRESH_TOKEN: '/v1/api/auth/refresh'
}

module.exports.cmpcatalog = {
Expand All @@ -74,6 +75,7 @@ module.exports.control = {

module.exports.data = {
SEND: '/v1/api/data/{deviceid}',
SEND_AS_USER: '/v1/api/accounts/{accountId}/data/{deviceId}',
SEARCH: '/v1/api/accounts/{accountId}/data/search',
SEARCH_ADVANCED: '/v1/api/accounts/{accountId}/data/search/advanced'
}
Expand Down
12 changes: 12 additions & 0 deletions api/rest/auth.def.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ module.exports = function(config) {
GetAuthUserInfoOption.prototype = new ConnectionOptions();
GetAuthUserInfoOption.prototype.constructor = GetAuthUserInfoOption;
module.GetAuthUserInfoOption = GetAuthUserInfoOption;


function RefreshAuthTokenOption(data) {
this.pathname = common.buildPath(api.auth.REFRESH_TOKEN);
this.token = data.token;
ConnectionOptions.call(this);
this.method = 'PUT';
this.body = JSON.stringify(data.body);
}
RefreshAuthTokenOption.prototype = new ConnectionOptions();
RefreshAuthTokenOption.prototype.constructor = RefreshAuthTokenOption;
module.RefreshAuthTokenOption = RefreshAuthTokenOption;

return module;
}
19 changes: 19 additions & 0 deletions api/rest/data.def.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ module.exports = function(config) {
module.SubmitDataOption = SubmitDataOption;


function SubmitDataAsUserOption(data) {
var isBinary = common.isBinary(data.body);
this.pathname = common.buildPath(api.data.SEND_AS_USER, [data.accountId, data.deviceId]);
this.token = data.userToken;
ConnectionOptions.call(this);
this.method = 'POST';
if ( isBinary ) {
this.body = cbor.encode(data.body);
this.headers["Content-type"] = "application/cbor";
} else {
this.body = JSON.stringify(data.body);
this.headers["Content-type"] = "application/json";
}
}
SubmitDataAsUserOption.prototype = new ConnectionOptions();
SubmitDataAsUserOption.prototype.constructor = SubmitDataAsUserOption;
module.SubmitDataAsUserOption = SubmitDataAsUserOption;


function SearchDataOption(data) {
this.pathname = common.buildPath(api.data.SEARCH, data.accountId);
this.token = data.userToken;
Expand Down
17 changes: 14 additions & 3 deletions api/rest/iot.auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module.exports = function(config) {
var module = {};

module.httpClient = require('../../lib/httpClient');
module.userAdminDef = require('./admin.def')(config);

/**
* @description Get user token through API:POST/v1/api/auth/token
* @param data.body.email the user email
* @param data.body.email the user email
* @param data.body.password the user password
*/
module.getAuthToken = function(data, callback) {
Expand All @@ -59,6 +59,17 @@ module.exports = function(config) {
var getAuthUserInfoOpt = new module.userAdminDef.auth.GetAuthUserInfoOption(data);
return module.httpClient.httpRequest(getAuthUserInfoOpt, callback);
};



/**
* @description Refresh access token through API:PUT/v1/api/auth/refresh
* @param data.token the access token
* @param data.body.refreshToken the refresh token
*/
module.refreshAuthToken = function(data, callback) {
var refreshAuthTokenOpt = new module.userAdminDef.auth.RefreshAuthTokenOption(data);
return module.httpClient.httpRequest(refreshAuthTokenOpt, callback);
};

return module;
}
23 changes: 18 additions & 5 deletions api/rest/iot.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

module.exports = function(config) {
var module = {};

module.httpClient = require('../../lib/httpClient');
module.userAdminDef = require('./admin.def')(config);

/**
* @description Sends data to cloud through API:POST/v1/api/data/{deviceId}
* @param data.body the data JSON object according to the API spec for this call
* @param data.body the data JSON object according to the API spec for this call
* @param data.userToken contains the access token
* @param data.deviceId id of the device which sends the data
*/
Expand All @@ -42,9 +42,22 @@ module.exports = function(config) {
};


/**
* @description Sends data to cloud through API:POST/v1/api/data/{deviceId}
* @param data.body the data JSON object according to the API spec for this call
* @param data.userToken contains the access token
* @param data.deviceId id of the device which sends the data
* @param data.accountId id of account that owns the device
*/
module.submitDataAsUser = function(data, callback) {
var submitDataAsUserOpt = new module.userAdminDef.data.SubmitDataAsUserOption(data);
return module.httpClient.httpRequest(submitDataAsUserOpt, callback);
};


/**
* @description Retrieve data from cloud through API:POST/v1/api/accounts/{accountId}/data/search
* @param data.body the detail of the search data JSON object according to the API spec for this call
* @param data.body the detail of the search data JSON object according to the API spec for this call
* @param data.userToken contains the access token
* @param data.accountId id of the account where the search is performed
*/
Expand All @@ -56,7 +69,7 @@ module.exports = function(config) {

/**
* @description Retrieve data from cloud through advanced API:POST/v1/api/accounts/{accountId}/data/search/advanced
* @param data.body the detail of the search data JSON object according to the API spec for this call
* @param data.body the detail of the search data JSON object according to the API spec for this call
* @param data.userToken contains the access token
* @param data.accountId id of the account where the search is performed
*/
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.1.1",
"version": "1.1.2",
"description": "OISP SDK for Node.js",
"main": "index.js",
"scripts": {
Expand Down
46 changes: 44 additions & 2 deletions test/api_iot.dataTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe(fileToTest, function() {
};

var Option = {
SendDataOption: {},
SubmitDataOption: {},
SubmitDataAsUserOption: {},
SearchDataOption: {},
SearchDataAdvancedOption: {}
};
Expand Down Expand Up @@ -76,7 +77,7 @@ describe(fileToTest, function() {
};

Option.SubmitDataOption = function(alerts) {
assert.deepEqual(alerts, data, "The data is not oki");
assert.deepEqual(alerts, data, "The data is not ok");
return optData;
}
httpClientMock.httpRequest = function (opt, cb) {
Expand All @@ -92,6 +93,47 @@ describe(fileToTest, function() {
toTest.userAdminDef.data = Option;
toTest.submitData(data, callBack);
});

it('Shall send submit data request as user for data submission', function(done) {
var optData = {
method: 'POST',
host: "myhost",
body: "mybody"
};

var data = {
accountid: "aid",
deviceid: "did",
body: {data: "message"}
};

var reData = {
x : 10,
y : 220,
ar : ["222", "333"]
};

Option.SubmitDataAsUserOption = function(alerts) {
assert.deepEqual(alerts, data, "The data is not ok");
return optData;
};

httpClientMock.httpRequest = function (opt, cb) {
assert.deepEqual(opt, optData, "the option object was missing");
cb(reData);
};

var callBack = function(response) {
assert.isNotNull(response, "The response was missing");
assert.deepEqual(response, reData, "The Data was missing");
done();
};

toTest.httpClient = httpClientMock;
toTest.userAdminDef.data = Option;
toTest.submitDataAsUser(data, callBack);
});

it('Shall send search data request for data', function(done) {

var optData = {
Expand Down

0 comments on commit 956c73e

Please sign in to comment.