From cf2d18e5a44cca6b5197cb548b71a55ffd089e38 Mon Sep 17 00:00:00 2001 From: mapedraza Date: Thu, 9 Nov 2023 10:14:16 +0100 Subject: [PATCH 1/2] Add tests --- .../jexlBasedTransformations-test.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js b/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js index 9595b0abf..4f425a434 100644 --- a/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +++ b/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js @@ -724,6 +724,19 @@ const iotAgentConfig = { expression: 'v == undefined' } ] + }, + testContextVars: { + type: 'testNullExplicit', + explicitAttrs: true, + commands: [], + lazy: [], + active: [ + { + name: 'a', + type: 'Number', + expression: 'a+":"+service+subservice+id+type' + } + ] } }, service: 'smartgondor', @@ -2418,6 +2431,50 @@ describe('Java expression language (JEXL) based transformations plugin', functio }); }); }); + + describe('When using context values as part of expressions (service, subservice, dev ID)', function () { + const values = [ + { + name: 'a', + type: 'Text', + value: 'Text123' + } + ]; + + beforeEach(function () { + nock.cleanAll(); + + contextBrokerMock = nock('http://192.168.1.1:1026') + .matchHeader('fiware-service', 'smartgondor') + .matchHeader('fiware-servicepath', 'gardens') + .post('/v2/entities?options=upsert', function (body) { + // Pending to define the expected bod, so far the output is: + // { + // id: 'testContext', + // type: 'testNullExplicit', + // a: { + // type: 'Number', + // value: 'Text123:undefinedundefinedundefinedtestNullExplicit' + // } + // } + console.log(body); + return true; + }) + .reply(204); + }); + + afterEach(function (done) { + done(); + }); + + it('should calculate values using nested attributes names and skip measures', function (done) { + iotAgentLib.update('testContext', 'testContextVars', '', values, function (error) { + should.not.exist(error); + contextBrokerMock.done(); + done(); + }); + }); + }); }); describe('Java expression language (JEXL) based transformations plugin - Timestamps', function () { From c17cb23ddff1b4fe3eadfdb155c420c7a44b821f Mon Sep 17 00:00:00 2001 From: mapedraza <40356341+mapedraza@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:33:02 +0100 Subject: [PATCH 2/2] Update test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js --- test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js b/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js index 4f425a434..89d6a2128 100644 --- a/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +++ b/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js @@ -2467,7 +2467,7 @@ describe('Java expression language (JEXL) based transformations plugin', functio done(); }); - it('should calculate values using nested attributes names and skip measures', function (done) { + it('should calculate values using device JEXL context', function (done) { iotAgentLib.update('testContext', 'testContextVars', '', values, function (error) { should.not.exist(error); contextBrokerMock.done();