From ecca5431a680e7286b4d687f6176f7b62a00fdab Mon Sep 17 00:00:00 2001 From: Kazuhito Suda Date: Sat, 18 Feb 2023 11:14:09 +0900 Subject: [PATCH] ADD Service and ServicePath custom node --- CHANGELOG.md | 1 + README.ja.md | 1 + README.md | 1 + .../custom_nodes/service-and-servicepath.md | 134 ++++++++++++ docs/en/index.md | 1 + .../custom_nodes/service-and-servicepath.md | 140 +++++++++++++ docs/ja/index.md | 1 + examples/batch-update.json | 0 examples/registration.json | 0 examples/service-and-servicepath.json | 153 ++++++++++++++ src/lib.js | 3 + .../icons/fiware-non-free.svg | 55 +++++ .../service-and-servicepath.html | 124 +++++++++++ .../service-and-servicepath.js | 72 +++++++ test/unit/lib_spec.js | 6 + test/unit/service-and-servicepath_spec.js | 198 ++++++++++++++++++ 16 files changed, 890 insertions(+) create mode 100644 docs/en/custom_nodes/service-and-servicepath.md create mode 100644 docs/ja/custom_nodes/service-and-servicepath.md mode change 100755 => 100644 examples/batch-update.json mode change 100755 => 100644 examples/registration.json create mode 100644 examples/service-and-servicepath.json create mode 100755 src/nodes/NGSI/service-and-servicepath/icons/fiware-non-free.svg create mode 100644 src/nodes/NGSI/service-and-servicepath/service-and-servicepath.html create mode 100644 src/nodes/NGSI/service-and-servicepath/service-and-servicepath.js create mode 100644 test/unit/service-and-servicepath_spec.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 81fbf67..bb7eb89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## node-red-contrib-letsfiware-NGSI v0.8.0-next +- ADD Service and ServicePath custom node (#91) - Improve NGSI source custom node (#90) - Fix hyper links (#89) - Improve NGSI Batch update custom node (#88) diff --git a/README.ja.md b/README.ja.md index 4acf05c..ad7b258 100644 --- a/README.ja.md +++ b/README.ja.md @@ -31,6 +31,7 @@ FIWARE Open APIs の Node-RED 実装 - [NGSI to Dashboard](docs/ja/custom_nodes/ngsi_to_dashboard.md) - [GTFS realtime to NGSI](docs/ja/custom_nodes/ngsi_gtfs_realtime.md) - [FIWARE version](docs/ja/custom_nodes/fiware_version.md) +- [FIWARE Service and ServicePath](docs/ja/custom_nodes/service-and-servicepath.md) ## ドキュメント diff --git a/README.md b/README.md index c3c35f6..69d6ce7 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Node-RED implementation for FIWARE Open APIs - [NGSI to Dashboard](docs/en/custom_nodes/ngsi_to_dashboard.md) - [GTFS realtime to NGSI](docs/en/custom_nodes/ngsi_gtfs_realtime.md) - [FIWARE version](docs/en/custom_nodes/fiware_version.md) +- [FIWARE Service and ServicePath](docs/en/custom_nodes/service-and-servicepath.md) ## Documentation diff --git a/docs/en/custom_nodes/service-and-servicepath.md b/docs/en/custom_nodes/service-and-servicepath.md new file mode 100644 index 0000000..a39c311 --- /dev/null +++ b/docs/en/custom_nodes/service-and-servicepath.md @@ -0,0 +1,134 @@ +# FIWARE Service and ServicePath + +This custom node is a simple node that allows to manage FIWARE Service and ServicePath. + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images/service-and-servicepath/service-and-servicepath-01.png) + +## Contents + +
+Details + +- [Passthrough](#passthrough) +- [Add FIWARE Service and/or ServicePath](#add-fiware-service-andor-servicepath) +- [Delete FIWARE Service and/or ServicePath](#delete-fiware-service-andor-servicepath) + +
+ +## Passthrough + +It allows to pass FIWARE Service value and/or ServicePath value to output without manipulation. + +### Properties + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images//service-and-servicepath/service-and-servicepath-02.png) + +- `name`: A name for a node instance +- `FIWARE Service`: `Passthrough` +- `FIWARE ServicePath`: `Passthrough` + +### Example + +#### Input + +Payload *JSON Object* + +A `msg.context` should contain JSON Object. + +``` +{ + "fiwareService": "openiot", + "fiwareServicePath": "/iot" +} +``` + +#### Output + +Payload *JSON Object* + +A `msg.context` contains JSON Object. + +``` +{ + "fiwareService": "openiot", + "fiwareServicePath": "/iot" +} +``` + +## Add FIWARE Service and/or ServicePath + +It allows to add FIWARE Service and/or FIWARE ServicePath to `msg.context`. + +### Properties + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images/service-and-servicepath/service-and-servicepath-03.png) + +- `name`: A name for a node instance +- `FIWARE Service`: `Add` +- `Service value`: A value of FIWARE Service +- `FIWARE ServicePath`: `Add` +- `Service valuePath`: A value of FIWARE ServicePath + +### Examples + +Set `Service value` to `OpenIoT` and `Service valuePath` to `/iot`. + +#### Input + +Payload *JSON Object* + +A `msg.context` should contain JSON Object. + +``` +{} +``` + +#### Output + +Payload *JSON Object* + +A `msg.context` contains JSON Object. + +``` +{ + "fiwareService":"openiot", + "fiwareServicePath":"/iot" +} +``` + +## Delete FIWARE Service and/or ServicePath + +It allows to delete FIWARE Service and/or FIWARE ServicePath from `msg.context`. + +### Properties + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images//service-and-servicepath/service-and-servicepath-04.png) + +- `name`: A name for a node instance +- `FIWARE Service`: `Delete` +- `FIWARE ServicePath`: `Delete` + +### Example + +#### Input + +Payload *JSON Object* + +A `msg.context` should contain JSON Object. + +``` +{ + "fiwareService":"openiot", + "fiwareServicePath":"/iot" +} +``` + +#### Output + +Payload *JSON Object* + +A `msg.context` contains JSON Object. + +``` +{} +``` diff --git a/docs/en/index.md b/docs/en/index.md index a13e06c..23161c9 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -22,6 +22,7 @@ Node-RED NGSI integration - [NGSI to Worldmap](custom_nodes/ngsi_to_worldmap.md) - [GTFS realtime to NGSI](custom_nodes/ngsi_gtfs_realtime.md) - [FIWARE version](custom_nodes/fiware_version.md) +- [FIWARE Service and ServicePath](custom_nodes/service-and-servicepath.md) ## Documentation diff --git a/docs/ja/custom_nodes/service-and-servicepath.md b/docs/ja/custom_nodes/service-and-servicepath.md new file mode 100644 index 0000000..d5df7c0 --- /dev/null +++ b/docs/ja/custom_nodes/service-and-servicepath.md @@ -0,0 +1,140 @@ +# FIWARE Service and ServicePath + +このカスタム・ノードは、FIWARE Service と ServicePath を管理できるノードです。 + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images/service-and-servicepath/service-and-servicepath-01.png) + +## コンテンツ + +
+詳細 + +- [パススルー](#passthrough) +- [FIWARE Service および/または ServicePath の追加](#add-fiware-service-and-or-servicepath) +- [FIWARE Service および/または ServicePath の削除](#delete-fiware-service-and-or-servicepath) + +
+ + + +## パススルー + +FIWARE Service の値、および/または ServicePath の値を操作なしで出力に渡すことができます。 + +### プロパティ + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images//service-and-servicepath/service-and-servicepath-02.png) + +- `name`: ノード・インスタンスの名前 +- `FIWARE Service`: `Passthrough` +- `FIWARE ServicePath`: `Passthrough` + +### 例 + +#### 入力 + +Payload *JSON Object* + +`msg.context` には、JSON オブジェクトが含まれている必要があります。 + +``` +{ + "fiwareService": "openiot", + "fiwareServicePath": "/iot" +} +``` + +#### 出力 + +Payload *JSON Object* + +`msg.context` には、JSON オブジェクトが含まれます。 + +``` +{ + "fiwareService": "openiot", + "fiwareServicePath": "/iot" +} +``` + + + +## FIWARE Service および/または ServicePath の追加 + +`msg.context` に FIWARE Service および/または FIWARE ServicePath を追加できます。 + +### プロパティ + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images/service-and-servicepath/service-and-servicepath-03.png) + +- `name`: ノード・インスタンスの名前 +- `FIWARE Service`: `Add` +- `Service value`: FIWARE Service の値 +- `FIWARE ServicePath`: `Add` +- `Service valuePath`: FIWARE ServicePath の値 + +### 例 + +Set `Service value` to `OpenIoT` and `Service valuePath` to `/iot`. + +#### 入力 + +Payload *JSON Object* + +`msg.context` には、JSON オブジェクトが含まれている必要があります。 + +``` +{} +``` + +#### 出力 + +Payload *JSON Object* + +`msg.context` には、JSON オブジェクトが含まれます。 + +``` +{ + "fiwareService":"openiot", + "fiwareServicePath":"/iot" +} +``` + + + +## FIWARE Service および/または ServicePath の削除 + +`msg.context` から FIWARE Service および/または FIWARE ServicePath を削除できます。 + +### プロパティ + +![](https://raw.githubusercontent.com/lets-fiware/node-red-contrib-letsfiware-NGSI/gh-pages/images//service-and-servicepath/service-and-servicepath-04.png) + +- `name`: ノード・インスタンスの名前 +- `FIWARE Service`: `Delete` +- `FIWARE ServicePath`: `Delete` + +### 例 + +#### 入力 + +Payload *JSON Object* + +`msg.context` には、JSON オブジェクトが含まれている必要があります。 + +``` +{ + "fiwareService":"openiot", + "fiwareServicePath":"/iot" +} +``` + +#### 出力 + +Payload *JSON Object* + +`msg.context` には、JSON オブジェクトが含まれます。 + +``` +{} +``` diff --git a/docs/ja/index.md b/docs/ja/index.md index 368cd79..af66a0a 100644 --- a/docs/ja/index.md +++ b/docs/ja/index.md @@ -22,6 +22,7 @@ FIWARE Open APIs の Node-RED 実装 - [NGSI to Worldmap](custom_nodes/ngsi_to_worldmap.md) - [GTFS realtime to NGSI](custom_nodes/ngsi_gtfs_realtime.md) - [FIWARE version](custom_nodes/fiware_version.md) +- [FIWARE Service and ServicePath](custom_nodes/service-and-servicepath.md) ## ドキュメント diff --git a/examples/batch-update.json b/examples/batch-update.json old mode 100755 new mode 100644 diff --git a/examples/registration.json b/examples/registration.json old mode 100755 new mode 100644 diff --git a/examples/service-and-servicepath.json b/examples/service-and-servicepath.json new file mode 100644 index 0000000..9f552db --- /dev/null +++ b/examples/service-and-servicepath.json @@ -0,0 +1,153 @@ +[ + { + "id": "49b801ab6c13addc", + "type": "tab", + "label": "Flow 1", + "disabled": false, + "info": "", + "env": [] + }, + { + "id": "6cfe81addb62183b", + "type": "inject", + "z": "49b801ab6c13addc", + "name": "Add", + "props": [ + { + "p": "payload" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "payload": "{}", + "payloadType": "json", + "x": 170, + "y": 140, + "wires": [ + [ + "13fa9cb4c19f7ec1" + ] + ] + }, + { + "id": "13fa9cb4c19f7ec1", + "type": "Service and ServicePath", + "z": "49b801ab6c13addc", + "name": "", + "serviceMode": "add", + "serviceValue": "OpenIoT", + "servicePathMode": "add", + "servicePathValue": "/iot", + "x": 470, + "y": 140, + "wires": [ + [ + "713dae288c8917d3" + ] + ] + }, + { + "id": "713dae288c8917d3", + "type": "debug", + "z": "49b801ab6c13addc", + "name": "", + "active": true, + "tosidebar": true, + "console": false, + "tostatus": false, + "complete": "context", + "targetType": "msg", + "statusVal": "", + "statusType": "auto", + "x": 730, + "y": 140, + "wires": [] + }, + { + "id": "92114222797d8112", + "type": "inject", + "z": "49b801ab6c13addc", + "name": "Passthrough", + "props": [ + { + "p": "context", + "v": "{\"fiwareService\":\"openiot\",\"fiwareServicePath\":\"/iot\"}", + "vt": "json" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "x": 190, + "y": 60, + "wires": [ + [ + "16b545afef13e4b6" + ] + ] + }, + { + "id": "16b545afef13e4b6", + "type": "Service and ServicePath", + "z": "49b801ab6c13addc", + "name": "", + "serviceMode": "pass", + "serviceValue": "", + "servicePathMode": "pass", + "servicePathValue": "", + "x": 470, + "y": 60, + "wires": [ + [ + "713dae288c8917d3" + ] + ] + }, + { + "id": "166db1ce953b24e4", + "type": "inject", + "z": "49b801ab6c13addc", + "name": "Delete", + "props": [ + { + "p": "context", + "v": "{\"fiwareService\":\"openiot\",\"fiwareServicePath\":\"/iot\"}", + "vt": "json" + } + ], + "repeat": "", + "crontab": "", + "once": false, + "onceDelay": 0.1, + "topic": "", + "x": 190, + "y": 220, + "wires": [ + [ + "8e539f3506dbdce0" + ] + ] + }, + { + "id": "8e539f3506dbdce0", + "type": "Service and ServicePath", + "z": "49b801ab6c13addc", + "name": "", + "serviceMode": "delete", + "serviceValue": "", + "servicePathMode": "delete", + "servicePathValue": "", + "x": 470, + "y": 220, + "wires": [ + [ + "713dae288c8917d3" + ] + ] + } +] diff --git a/src/lib.js b/src/lib.js index b698646..d182462 100644 --- a/src/lib.js +++ b/src/lib.js @@ -151,6 +151,9 @@ function getServiceAndServicePath(msg, service, path) { if (msg.context.fiwareServicePath === null) { msg.context.fiwareServicePath = path; } + + msg.context.fiwareService = msg.context.fiwareService.toLowerCase(); + return [msg.context.fiwareService, msg.context.fiwareServicePath]; } diff --git a/src/nodes/NGSI/service-and-servicepath/icons/fiware-non-free.svg b/src/nodes/NGSI/service-and-servicepath/icons/fiware-non-free.svg new file mode 100755 index 0000000..1278dc1 --- /dev/null +++ b/src/nodes/NGSI/service-and-servicepath/icons/fiware-non-free.svg @@ -0,0 +1,55 @@ + + + + + + + + + + + diff --git a/src/nodes/NGSI/service-and-servicepath/service-and-servicepath.html b/src/nodes/NGSI/service-and-servicepath/service-and-servicepath.html new file mode 100644 index 0000000..6678718 --- /dev/null +++ b/src/nodes/NGSI/service-and-servicepath/service-and-servicepath.html @@ -0,0 +1,124 @@ + + + + + + + \ No newline at end of file diff --git a/src/nodes/NGSI/service-and-servicepath/service-and-servicepath.js b/src/nodes/NGSI/service-and-servicepath/service-and-servicepath.js new file mode 100644 index 0000000..569bdda --- /dev/null +++ b/src/nodes/NGSI/service-and-servicepath/service-and-servicepath.js @@ -0,0 +1,72 @@ +/* + MIT License + + Copyright 2022-2023 Kazuhito Suda + + This file is part of node-red-contrib-letsfiware-NGSI + + https://github.com/lets-fiware/node-red-contrib-letsfiware-NGSI + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +'use strict'; + +const manageServiceAndServicePath = function (msg, config) { + if (!msg.context) { + msg.context = {}; + } + + if (typeof msg.context !== 'object' || Array.isArray(msg.context)) { + this.error('msg.context not JSON Object'); + return msg; + } + + switch (config.serviceMode) { + case 'add': + msg.context.fiwareService = config.serviceValue.toLowerCase(); + break; + case 'delete': + delete msg.context.fiwareService; + break; + } + + switch (config.servicePathMode) { + case 'add': + msg.context.fiwareServicePath = config.servicePathValue; + break; + case 'delete': + delete msg.context.fiwareServicePath; + break; + } + + return msg; +}; + +module.exports = function (RED) { + function ServiceAndPath(config) { + RED.nodes.createNode(this, config); + const node = this; + + node.on('input', async function (msg) { + node.send(manageServiceAndServicePath.call(node, msg, config)); + }); + } + RED.nodes.registerType('Service and ServicePath', ServiceAndPath); +}; diff --git a/test/unit/lib_spec.js b/test/unit/lib_spec.js index b0bfd10..eae7328 100644 --- a/test/unit/lib_spec.js +++ b/test/unit/lib_spec.js @@ -312,6 +312,12 @@ describe('lib.js', () => { const msg = { context: { fiwareService: 'orion', fiwareServicePath: '/#' } }; const actual = lib.getServiceAndServicePath(msg, 'openio', '/'); + assert.deepEqual(actual, ['orion', '/#']); + }); + it('toLowerCase', () => { + const msg = { context: { fiwareService: 'ORION', fiwareServicePath: '/#' } }; + const actual = lib.getServiceAndServicePath(msg, 'openio', '/'); + assert.deepEqual(actual, ['orion', '/#']); }); }); diff --git a/test/unit/service-and-servicepath_spec.js b/test/unit/service-and-servicepath_spec.js new file mode 100644 index 0000000..1deec86 --- /dev/null +++ b/test/unit/service-and-servicepath_spec.js @@ -0,0 +1,198 @@ +/* + MIT License + + Copyright 2022-2023 Kazuhito Suda + + This file is part of node-red-contrib-letsfiware-NGSI + + https://github.com/lets-fiware/node-red-contrib-letsfiware-NGSI + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + */ + +/* eslint-env node, mocha */ + +'use strict'; + +require('babel-register')({ + plugins: ['babel-plugin-rewire'] +}); + +const { assert } = require('chai'); + +const serviceAndServicePathNode = require('../../src/nodes/NGSI/service-and-servicepath/service-and-servicepath.js'); +const MockRed = require('./helpers/mockred.js'); + +describe('service-and-servicepath.js', () => { + describe('manageServiceAndServicePath', () => { + it('msg.context is null', () => { + const manageServiceAndServicePath = serviceAndServicePathNode.__get__('manageServiceAndServicePath'); + const msg = { context: null }; + const defaultConfig = { + servicepath: '/', + serviceMode: 'add', + serviceValue: 'OpenIoT', + servicePathMode: 'add', + servicePathValue: '/iot', + }; + const node = { msg: '', error: () => { } }; + + const actual = manageServiceAndServicePath.call(node, msg, defaultConfig); + + const expected = { + context: { + fiwareService: 'openiot', + fiwareServicePath: '/iot', + } + }; + + assert.deepEqual(actual, expected); + }); + it('Add', () => { + const manageServiceAndServicePath = serviceAndServicePathNode.__get__('manageServiceAndServicePath'); + const msg = { context: null }; + const defaultConfig = { + servicepath: '/', + serviceMode: 'add', + serviceValue: 'OpenIoT', + servicePathMode: 'add', + servicePathValue: '/iot', + }; + const node = { msg: '', error: () => { } }; + + const actual = manageServiceAndServicePath.call(node, msg, defaultConfig); + + const expected = { + context: { + fiwareService: 'openiot', + fiwareServicePath: '/iot', + } + }; + + assert.deepEqual(actual, expected); + }); + it('Delete', () => { + const manageServiceAndServicePath = serviceAndServicePathNode.__get__('manageServiceAndServicePath'); + const msg = { + context: { + fiwareService: 'openiot', + fiwareServicePath: '/iot', + } + }; + const defaultConfig = { + servicepath: '/', + serviceMode: 'delete', + serviceValue: 'OpenIoT', + servicePathMode: 'delete', + servicePathValue: '/iot', + }; + const node = { msg: '', error: () => { } }; + + const actual = manageServiceAndServicePath.call(node, msg, defaultConfig); + + const expected = { context: {} }; + assert.deepEqual(actual, expected); + }); + it('Pass', () => { + const manageServiceAndServicePath = serviceAndServicePathNode.__get__('manageServiceAndServicePath'); + const msg = { + context: { + fiwareService: 'openiot', + fiwareServicePath: '/iot', + } + }; + const defaultConfig = { + servicepath: '/', + serviceMode: 'pass', + serviceValue: 'OpenIoT', + servicePathMode: 'pass', + servicePathValue: '/iot', + }; + const node = { msg: '', error: () => { } }; + + const actual = manageServiceAndServicePath.call(node, msg, defaultConfig); + + const expected = { + context: { + fiwareService: 'openiot', + fiwareServicePath: '/iot', + } + }; + assert.deepEqual(actual, expected); + }); + it('msg.context not JSON Object', () => { + const manageServiceAndServicePath = serviceAndServicePathNode.__get__('manageServiceAndServicePath'); + const msg = { context: [] }; + const defaultConfig = { + servicepath: '/', + serviceMode: 'add', + serviceValue: 'OpenIoT', + servicePathMode: 'add', + servicePathValue: '/iot', + }; + let err = ''; + const node = { msg: '', error: (e) => { err = e; } }; + + const actual = manageServiceAndServicePath.call(node, msg, defaultConfig); + + assert.deepEqual(actual, { context: [] }); + assert.equal(err, 'msg.context not JSON Object'); + }); + }); + describe('NGSI Entity node', () => { + it('Add FIWARE Service and ServicePath', async () => { + const red = new MockRed(); + serviceAndServicePathNode(red); + red.createNode({ + servicepath: '/', + serviceMode: 'add', + serviceValue: 'OpenIoT', + servicePathMode: 'add', + servicePathValue: '/iot', + }); + + await red.inputWithAwait({ context: {} }); + + const expected = { + context: { + fiwareService: 'openiot', + fiwareServicePath: '/iot', + } + }; + + assert.deepEqual(red.getOutput(), expected); + }); + it('msg.context not JSON Object', async () => { + const red = new MockRed(); + serviceAndServicePathNode(red); + red.createNode({ + servicepath: '/', + serviceMode: 'add', + serviceValue: 'OpenIoT', + servicePathMode: 'add', + servicePathValue: '/iot', + }); + + await red.inputWithAwait({ context: [] }); + + assert.deepEqual(red.getOutput(), { context: [] }); + assert.equal(red.getMessage(), 'msg.context not JSON Object'); + }); + }); +});