Skip to content

Commit

Permalink
Add cross usage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mapedraza committed Aug 9, 2024
1 parent 9e25475 commit 0b38688
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"prettier": "prettier --config .prettierrc.json --write '**/**/**/**/*.js' '**/**/**/*.js' '**/**/*.js' '**/*.js' '*.js'",
"prettier:text": "prettier 'README.md' 'doc/*.md' 'doc/**/*.md' --no-config --tab-width 4 --print-width 120 --write --prose-wrap always",
"test": "nyc --reporter=text mocha --recursive 'test/**/*.js' --reporter spec --timeout 8000 --ui bdd --exit --color true",
"test:custom": "nyc --reporter=text mocha --recursive 'test/unit/memoryRegistry/*.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
"test:functional": "nyc --reporter=text mocha --recursive 'test/functional/*.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
"test:expression": "nyc --reporter=text mocha --recursive 'test/unit/expressions/*.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
"test:multientity": "nyc --reporter=text mocha --recursive 'test/unit/ngsiv2/plugins/multientity-plugin_test.js' --reporter spec --timeout 5000 --ui bdd --exit --color true",
Expand Down
99 changes: 99 additions & 0 deletions test/unit/ngsiv2/provisioning/device-group-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

/* eslint-disable no-unused-vars */

// FIXME: parallel tests in device-provisioning-configGroup-api_test.js.

const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
const _ = require('underscore');
const async = require('async');
Expand Down Expand Up @@ -250,6 +252,20 @@ const optionsGet = {
}
};

// Add new options using the literal configGroups instead of services
const configGroupTerm = 'configGroups';

const newOptionsCreation = JSON.parse(JSON.stringify(optionsCreation));
newOptionsCreation.url = newOptionsCreation.url.replace('services', configGroupTerm);
newOptionsCreation.json[configGroupTerm] = newOptionsCreation.json.services;
delete newOptionsCreation.json.services;

const newOptionsList = JSON.parse(JSON.stringify(optionsList));
newOptionsList.url = newOptionsList.url.replace('services', configGroupTerm);

const newOptionsGet = JSON.parse(JSON.stringify(optionsGet));
newOptionsGet.url = newOptionsGet.url.replace('services', configGroupTerm);

describe('NGSI-v2 - Device Group Configuration API', function () {
beforeEach(function (done) {
iotAgentLib.activate(iotAgentConfig, function () {
Expand Down Expand Up @@ -1156,4 +1172,87 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
});
});
});

describe('When a new device group creation request arrives with the NEW API endpoint ', function () {
it('should return a 200 OK', function (done) {
request(newOptionsCreation, function (error, response, body) {
should.not.exist(error);
response.statusCode.should.equal(201);
done();
});
});
it('should be recovered using the OLD API endpoint', function (done) {
request(newOptionsCreation, function (error, response, body) {
request(optionsList, function (error, response, body) {
body.count.should.equal(1);
body.services[0].apikey.should.equal('801230BJKL23Y9090DSFL123HJK09H324HV8732');
body.services[0].transport.should.equal('HTTP');
body.services[0].endpoint.should.equal('http://myendpoint.com');

body.count.should.equal(1);
should.exist(body.services[0].attributes);
body.services[0].attributes.length.should.equal(1);
body.services[0].attributes[0].name.should.equal('status');

should.exist(body.services[0].lazy);
body.services[0].lazy.length.should.equal(1);
body.services[0].lazy[0].name.should.equal('luminescence');

should.exist(body.services[0].commands);
body.services[0].commands.length.should.equal(1);
body.services[0].commands[0].name.should.equal('wheel1');

should.exist(body.services[0].static_attributes);
body.services[0].static_attributes.length.should.equal(1);
body.services[0].static_attributes[0].name.should.equal('bootstrapServer');

body.count.should.equal(1);
body.services[0].service.should.equal('testservice');
body.services[0].subservice.should.equal('/testingPath');
done();
});
});
});
});
describe('When a new device group creation request arrives with the NEW OLD endpoint ', function () {
it('should return a 200 OK', function (done) {
request(optionsCreation, function (error, response, body) {
should.not.exist(error);
response.statusCode.should.equal(201);
done();
});
});
it('should be recovered using the NEW API endpoint', function (done) {
request(optionsCreation, function (error, response, body) {
request(newOptionsList, function (error, response, body) {
body.count.should.equal(1);
body[configGroupTerm][0].apikey.should.equal('801230BJKL23Y9090DSFL123HJK09H324HV8732');
body[configGroupTerm][0].transport.should.equal('HTTP');
body[configGroupTerm][0].endpoint.should.equal('http://myendpoint.com');

body.count.should.equal(1);
should.exist(body[configGroupTerm][0].attributes);
body[configGroupTerm][0].attributes.length.should.equal(1);
body[configGroupTerm][0].attributes[0].name.should.equal('status');

should.exist(body[configGroupTerm][0].lazy);
body[configGroupTerm][0].lazy.length.should.equal(1);
body[configGroupTerm][0].lazy[0].name.should.equal('luminescence');

should.exist(body[configGroupTerm][0].commands);
body[configGroupTerm][0].commands.length.should.equal(1);
body[configGroupTerm][0].commands[0].name.should.equal('wheel1');

should.exist(body[configGroupTerm][0].static_attributes);
body[configGroupTerm][0].static_attributes.length.should.equal(1);
body[configGroupTerm][0].static_attributes[0].name.should.equal('bootstrapServer');

body.count.should.equal(1);
body[configGroupTerm][0].service.should.equal('testservice');
body[configGroupTerm][0].subservice.should.equal('/testingPath');
done();
});
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* Modified by: Daniel Calvo - ATOS Research & Innovation
*/

// FIXME: parallel tests in device-provisioning-configGroup-api_test.js. Remove this file if at the end /iot/services API (now Deprecated) is removed
/* eslint-disable no-unused-vars */

const iotAgentLib = require('../../../../lib/fiware-iotagent-lib');
Expand Down

0 comments on commit 0b38688

Please sign in to comment.