Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests about last measure #848

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
Loading