Skip to content

Commit

Permalink
Update multimeasure functional teste
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed May 8, 2024
1 parent 3705bd6 commit 94db695
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 37 deletions.
43 changes: 26 additions & 17 deletions test/functional/testCases.js
Expand Up @@ -544,7 +544,7 @@ const testCases = [
},
should: [
{
loglevel: 'debug',
//loglevel: 'debug',
shouldName:
'A - WHEN sending defined object_ids (measures) through http IT should send measures to Context Broker preserving value types and name mappings',
type: 'multimeasure', // TBD: this should be implemented to expect /v2/op/update
Expand All @@ -556,25 +556,34 @@ const testCases = [
k: globalEnv.apikey
},
json: [
[
{
a: 0
}
],
[
{
a: 6
}
]
{
a: 0
},
{
a: 6
}
]
},
expectation: {
id: globalEnv.entity_name,
type: globalEnv.entity_type,
attr_a: {
value: 6,
type: 'Number'
}
actionType: 'append',
entities: [
{
attr_a: {
type: 'Number',
value: 0
},
id: globalEnv.entity_name,
type: globalEnv.entity_type
},
{
attr_a: {
type: 'Number',
value: 6
},
id: globalEnv.entity_name,
type: globalEnv.entity_type
}
]
}
}
]
Expand Down
73 changes: 53 additions & 20 deletions test/functional/testUtils.js
Expand Up @@ -98,28 +98,61 @@ function sendMeasureIotaLib(measure, provision) {
* @param {Object} json
* @returns {Array} measures
*/
function jsonToIotaMeasures(json) {
let measures = [];
for (let key in json) {
/* eslint-disable-next-line no-prototype-builtins */
if (json.hasOwnProperty(key)) {
let measure = {
name: key,
value: json[key]
};
// A bit of Magic. If the key is TimeInstant, we set the type to DateTime.
// When sending the data through iot
if (key === 'TimeInstant') {
measure.type = 'DateTime';
} else {
// Although the type is not meaningfull and we could have picked any string for this,
// we have aligned with DEFAULT_ATTRIBUTE_TYPE constant in IOTA-JSON and IOTA-UL repositories
measure.type = 'Text';
function jsonToIotaMeasures(originJson) {
// FIXME: maybe this could be refactored to use less code
if (originJson && originJson[0]) {
// multimeasure case
let finalMeasures = [];

for (let json of originJson) {
let measures = [];
for (let key in json) {
/* eslint-disable-next-line no-prototype-builtins */
if (json.hasOwnProperty(key)) {
let measure = {
name: key,
value: json[key]
};
// A bit of Magic. If the key is TimeInstant, we set the type to DateTime.
// When sending the data through iot
if (key === 'TimeInstant') {
measure.type = 'DateTime';
} else {
// Although the type is not meaningfull and we could have picked any string for this,
// we have aligned with DEFAULT_ATTRIBUTE_TYPE constant in IOTA-JSON and IOTA-UL repositories
measure.type = 'Text';
}
measures.push(measure);
}
}
finalMeasures.push(measures);
}
return finalMeasures;
} else {
let json = originJson;

let measures = [];
for (let key in json) {
/* eslint-disable-next-line no-prototype-builtins */
if (json.hasOwnProperty(key)) {
let measure = {
name: key,
value: json[key]
};
// A bit of Magic. If the key is TimeInstant, we set the type to DateTime.
// When sending the data through iot
if (key === 'TimeInstant') {
measure.type = 'DateTime';
} else {
// Although the type is not meaningfull and we could have picked any string for this,
// we have aligned with DEFAULT_ATTRIBUTE_TYPE constant in IOTA-JSON and IOTA-UL repositories
measure.type = 'Text';
}
measures.push(measure);
}
measures.push(measure);
}
return measures;
}
return measures;
}

/**
Expand Down Expand Up @@ -170,7 +203,7 @@ async function testCase(measure, expectation, provision, env, config, type, tran
let receivedContext = [];
let cbMockRoute = '';
// Set the correct route depending if the test is multientity or not
if (type === 'multientity') {
if (type === 'multientity' || type === 'multimeasure') {
cbMockRoute = '/v2/op/update';
} else {
cbMockRoute = '/v2/entities?options=upsert';
Expand Down

0 comments on commit 94db695

Please sign in to comment.