Skip to content

Commit

Permalink
add tests about last measure
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Jan 10, 2025
1 parent adceb1b commit cfa121b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
99 changes: 99 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,73 @@ 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);
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 cfa121b

Please sign in to comment.