telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
60 stars 85 forks source link

Add TimeInstant + explicitAttr tests (ftest 533) #1610

Closed mapedraza closed 3 months ago

mapedraza commented 4 months ago

A part of original PR https://github.com/telefonicaid/iotagent-node-lib/pull/1605 including test 533

0533 - Group with explicit attrs:[ ] (empty array) + active attributes + TimeInstant attribute + static

  • A - WHEN sending data and a measure called "t" (defined as TimeInstant attribte) through http IT should NOT
  • B - WHEN sending data and a measure called TimeInstant through http IT should NOT store anything into the

BUT some problems were discovered when using TimeInstant attribute and fucntionalities in cases 533 A) and B):

0533 A

Assertion Error - Context Broker received payload differs from expectation
+ expected - actual

-{
-  "TimeInstant": {
-    "type": "DateTime"
-    "value": "2015-12-14T08:06:01.468Z"
-  }
-  "id": "TestType:TestDevice"
-  "type": "TestType"
-}
+{}

0533 B

Assertion Error - Context Broker received payload differs from expectation
+ expected - actual

-{
-  "DateIssued": {
-    "metadata": {
-      "TimeInstant": {
-        "type": "DateTime"
-        "value": "2024-04-29T16:07:27.281Z"
-      }
-    }
-    "type": "DateTime"
-    "value": "2015-12-14T08:06:01.468Z"
-  }
-  "TimeInstant": {
-    "type": "DateTime"
-    "value": "2024-04-29T16:07:27.281Z"
-  }
-  "id": "TestType:TestDevice"
-  "type": "TestType"
-}
+{}

See https://github.com/telefonicaid/iotagent-node-lib/pull/1605#issuecomment-2100832653

fgalan commented 4 months ago

This is a future regression case for issue #1606

AlvaroVega commented 4 months ago

IMHO with this group definition:

                        explicitAttrs: "[ ]",
                        timestamp: true,

a TimeInstant will be always propaged to CB, regardless attribute mapping definition.

This PR is as I think it would be: https://github.com/telefonicaid/iotagent-node-lib/pull/1614

AlvaroVega commented 3 months ago

IMHO with this group definition:

                        explicitAttrs: "[ ]",
                        timestamp: true,

a TimeInstant will be always propaged to CB, regardless attribute mapping definition.

This PR is as I think it would be: #1614

If the logic is that explicitAttrs empty implies that no timestamp should be propagated to CB then the logic to change is

https://github.com/telefonicaid/iotagent-node-lib/blob/3e3842a14b77664c10aa896b31d157d267e36493/lib/services/ngsi/entities-NGSI-v2.js#L524

by adding check that explicit.length > 0

   if (explicit instanceof Array && explicit.length > 0 && mustInsertTimeInstant) {
mapedraza commented 3 months ago

overpassed by https://github.com/telefonicaid/iotagent-node-lib/pull/1618