Skip to content

Commit 195ccf8

Browse files
GuillaumeOdGuillaumeOdile
authored andcommitted
fix: attribute loss when updating entity
1 parent 518d322 commit 195ccf8

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

lib/services/ngsi/entities-NGSI-v2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,
463463
}
464464
//remove measures that has been shadowed by an alias (some may be left and managed later)
465465
//Maybe we must filter object_id if there is name == object_id
466-
measures = measures.filter((item) => item.name !== currentAttr.object_id && item.name !== currentAttr.name);
466+
measures = measures.filter((item) => item.name !== currentAttr.object_id);
467467

468468
if (
469469
currentAttr.expression !== undefined &&

test/functional/testCases.js

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,16 @@ const testCases = [
542542
object_id: '.1.0.0.1',
543543
name: 'psBatteryVoltage',
544544
type: 'Number'
545+
},
546+
{
547+
object_id: 'fdt',
548+
name: 'fireDetectionThreshold',
549+
type: 'Number'
550+
},
551+
{
552+
object_id: 'fireDetectionThreshold3',
553+
name: 'fireDetectionThreshold3',
554+
type: 'Number'
545555
}
546556
],
547557
static_attributes: []
@@ -556,7 +566,7 @@ const testCases = [
556566
should: [
557567
{
558568
shouldName:
559-
'A - WHEN sending defined object_ids with special format names (measures) through http IT should send measures to Context Broker preserving value types, name mappings and metadatas',
569+
'B - WHEN sending defined object_ids with special format names in attributes through http IT should send measures to Context Broker preserving value types, name mappings and metadatas',
560570
type: 'single',
561571
measure: {
562572
url: 'http://localhost:' + config.http.port + '/iot/json',
@@ -567,7 +577,10 @@ const testCases = [
567577
},
568578
json: {
569579
a: false,
570-
'.1.0.0.1': 23.5
580+
'.1.0.0.1': 10,
581+
fdt: 10,
582+
fireDetectionThreshold2: 20,
583+
fireDetectionThreshold3: 30
571584
}
572585
},
573586
expectation: {
@@ -585,7 +598,54 @@ const testCases = [
585598
},
586599
psBatteryVoltage: {
587600
type: 'Number',
588-
value: 23.5
601+
value: 10
602+
},
603+
fireDetectionThreshold: {
604+
type: 'Number',
605+
value: 10
606+
},
607+
fireDetectionThreshold2: {
608+
type: 'Text',
609+
value: 20
610+
},
611+
fireDetectionThreshold3: {
612+
type: 'Number',
613+
value: 30
614+
}
615+
}
616+
},
617+
{
618+
shouldName:
619+
'A - WHEN sending defined measures by attribute names through http IT should send measures to Context Broker preserving value types, name mappings and metadatas',
620+
type: 'single',
621+
measure: {
622+
url: 'http://localhost:' + config.http.port + '/iot/json',
623+
method: 'POST',
624+
qs: {
625+
i: globalEnv.deviceId,
626+
k: globalEnv.apikey
627+
},
628+
json: {
629+
a: false,
630+
fireDetectionThreshold: 10
631+
}
632+
},
633+
expectation: {
634+
id: globalEnv.entity_name,
635+
type: globalEnv.entity_type,
636+
attr_a: {
637+
value: false,
638+
type: 'Boolean',
639+
metadata: {
640+
accuracy: {
641+
value: 0.8,
642+
type: 'Float'
643+
}
644+
}
645+
},
646+
fireDetectionThreshold: {
647+
type: 'Number',
648+
value: 10
589649
}
590650
}
591651
}

0 commit comments

Comments
 (0)