Skip to content

Commit

Permalink
Merge pull request #848 from telefonicaid/task/add_test_about_last_me…
Browse files Browse the repository at this point in the history
…asure

add tests about last measure
  • Loading branch information
fgalan authored Jan 15, 2025
2 parents b6a8872 + 1c0fe49 commit 188b127
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/functional/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ config.iota = {
providerUrl: 'http://localhost:4041',
deviceRegistrationDuration: 'P1M',
defaultType: 'Thing',
defaultResource: '/iot/json'
defaultResource: '/iot/json',
useCBflowControl: true
};

config.defaultKey = '1234';
Expand Down
103 changes: 103 additions & 0 deletions test/unit/ngsiv2/HTTP_reveice_measures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,36 @@ const groupCreation = {
'fiware-servicepath': '/gardens'
}
};
const groupCreationStoreLastMeasure = {
url: 'http://localhost:' + config.iota.server.port + '/iot/services',
method: 'POST',
json: {
services: [
{
resource: '/iot/json',
apikey: 'KL223HHV8732SFL2',
entity_type: 'TheLightType',
trust: '8970A9078A803H3BL98PINEQRW8342HBAMS',
cbHost: 'http://192.168.1.1:1026',
storeLastMeasure: true,
commands: [],
lazy: [],
attributes: [
{
name: 'status',
type: 'Boolean'
}
],
static_attributes: []
}
]
},
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
}
};

let contextBrokerMock;
let contextBrokerUnprovMock;

Expand Down Expand Up @@ -470,4 +500,77 @@ describe('HTTP: Measure reception ', function () {
});
});
});

describe('When a POST measure arrives for an unprovisioned device with storeLastMeasure', function () {
const optionsMeasure = {
url: 'http://localhost:' + config.http.port + '/iot/json',
method: 'POST',
json: {
humidity: '32',
temperature: '87'
},
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'JSON_UNPROVISIONED2',
k: 'KL223HHV8732SFL2'
}
};
// This mock does not check the payload since the aim of the test is not to verify
// device provisioning functionality. Appropriate verification is done in tests under
// provisioning folder of iotagent-node-lib
beforeEach(function (done) {
contextBrokerUnprovMock = nock('http://192.168.1.1:1026');

contextBrokerUnprovMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
'/v2/entities?options=upsert',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedStoreLastMeasure.json')
)
.reply(204);

request(groupCreationStoreLastMeasure, function (error, response, body) {
done();
});
});

it('should send its value to the Context Broker', function (done) {
request(optionsMeasure, function (error, result, body) {
contextBrokerUnprovMock.done();
done();
});
});

it('should add a lastMeasure to the registered devices', function (done) {
const getDeviceOptions = {
url: 'http://localhost:' + config.iota.server.port + '/iot/devices',
method: 'GET',
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
qs: {
i: 'JSON_UNPROVISIONED2',
k: 'KL223HHV8732SFL2'
}
};

request(optionsMeasure, function (error, response, body) {
request(getDeviceOptions, function (error, response, body) {
should.not.exist(error);
response.statusCode.should.equal(200);
should.exist(body.devices[1].lastMeasure);
body.devices[1].lastMeasure[0][0].name.should.equal('humidity');
body.devices[1].lastMeasure[0][0].value.should.equal('32');
body.devices[1].lastMeasure[0][1].name.should.equal('temperature');
body.devices[1].lastMeasure[0][1].value.should.equal('87');
done();
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id":"TheLightType:JSON_UNPROVISIONED2",
"type":"TheLightType",
"humidity":{
"type": "Text",
"value": "32"
},
"temperature":{
"type": "Text",
"value": "87"
}
}

0 comments on commit 188b127

Please sign in to comment.