From 787995f27e8498bed2f372501cddf1365a28a812 Mon Sep 17 00:00:00 2001
From: Alvaro Vega <alvaro.vegagarcia@telefonica.com>
Date: Tue, 12 Dec 2023 16:00:41 +0100
Subject: [PATCH 1/4] Update deviceService.js

---
 lib/services/devices/deviceService.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/services/devices/deviceService.js b/lib/services/devices/deviceService.js
index 1926c3f8d..d2e3b4124 100644
--- a/lib/services/devices/deviceService.js
+++ b/lib/services/devices/deviceService.js
@@ -352,7 +352,7 @@ function registerDevice(deviceObj, callback) {
                     deviceObj.subservice = deviceData.subservice;
                     deviceObj.type = deviceData.type;
                     deviceObj.staticAttributes = deviceObj.staticAttributes ? deviceObj.staticAttributes : [];
-                    deviceObj.commands = deviceObj.commands ? deviceObj.commands : [];
+                    deviceObj.commands = deviceData.commands ? deviceData.commands : [];
                     deviceObj.lazy = deviceObj.lazy ? deviceObj.lazy : [];
                     if ('apikey' in deviceData && deviceData.apikey !== undefined) {
                         deviceObj.apikey = deviceData.apikey;

From 0aeef2dd14d95bb98452a7038db34d300a1d2f68 Mon Sep 17 00:00:00 2001
From: Alvaro Vega <alvaro.vegagarcia@telefonica.com>
Date: Fri, 15 Dec 2023 10:03:07 +0100
Subject: [PATCH 2/4] Update CHANGES_NEXT_RELEASE

---
 CHANGES_NEXT_RELEASE | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE
index c6a609765..4bbeef13b 100644
--- a/CHANGES_NEXT_RELEASE
+++ b/CHANGES_NEXT_RELEASE
@@ -1 +1,2 @@
+- FIX: store commands from Group at Device level at provision device time
 - Log device id when BadTimestamp error

From 7874573700473a028bb068055f3e36aa19916467 Mon Sep 17 00:00:00 2001
From: Alvaro Vega <alvaro.vegagarcia@telefonica.com>
Date: Mon, 18 Dec 2023 10:15:54 +0100
Subject: [PATCH 3/4] add command tests

---
 test/functional/testCases.js | 60 ++++++++++++++++++++++++++++++++++++
 test/functional/testUtils.js |  2 ++
 2 files changed, 62 insertions(+)

diff --git a/test/functional/testCases.js b/test/functional/testCases.js
index 9a13ad85f..b7c7d9e2f 100644
--- a/test/functional/testCases.js
+++ b/test/functional/testCases.js
@@ -1476,6 +1476,66 @@ const testCases = [
             }
         ]
     },
+    // 0200 - COMMANDS TESTS
+    {
+        describeName: '0200 - Simple group with commands',
+        provision: {
+            url: 'http://localhost:' + config.iota.server.port + '/iot/services',
+            method: 'POST',
+            json: {
+                services: [
+                    {
+                        resource: '/iot/json',
+                        apikey: globalEnv.apikey,
+                        entity_type: globalEnv.entity_type,
+                        commands: [
+                            {
+                                name: 'cmd1',
+                                type: 'command'
+                            }
+                        ],
+                        lazy: [],
+                        attributes: [],
+                        static_attributes: []
+                    }
+                ]
+            },
+            headers: {
+                'fiware-service': globalEnv.service,
+                'fiware-servicepath': globalEnv.servicePath
+            }
+        },
+        should: [
+            {
+                loglevel: 'fatal',
+                shouldName:
+                    'A - WHEN sending not provisioned object_ids (measures) through http IT should store commands into Context Broker',
+                type: 'single',
+                measure: {
+                    url: 'http://localhost:' + config.http.port + '/iot/json',
+                    method: 'POST',
+                    qs: {
+                        i: globalEnv.deviceId,
+                        k: globalEnv.apikey
+                    },
+                    json: {
+                        b: 10
+                    }
+                },
+                expectation: {
+                    id: globalEnv.entity_name,
+                    type: globalEnv.entity_type,
+                    b: {
+                        value: 10,
+                        type: 'string'
+                    },
+                    cmd1: {
+                        type: 'command'
+                    }
+                }
+            }
+        ]
+    },
     // 0300 - STATIC ATTRIBUTES TESTS
     {
         describeName:
diff --git a/test/functional/testUtils.js b/test/functional/testUtils.js
index 8f1859f8b..9074b4b4d 100644
--- a/test/functional/testUtils.js
+++ b/test/functional/testUtils.js
@@ -139,6 +139,8 @@ function groupToIoTAConfigType(group, service, subservice) {
                 type.type = group.entity_type;
             } else if (key === 'static_attributes') {
                 type.staticAttributes = group.static_attributes;
+            } else if (key === 'commands') {
+                type.commands = group.commands;
             } else if (key !== 'resource') {
                 type[key] = group[key];
             }

From e16ce236c2d9b61f1ba107d954c06a77e2be8149 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?=
 <fgalan@users.noreply.github.com>
Date: Mon, 18 Dec 2023 11:54:38 +0100
Subject: [PATCH 4/4] Update CHANGES_NEXT_RELEASE

---
 CHANGES_NEXT_RELEASE | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE
index 4bbeef13b..4075512b9 100644
--- a/CHANGES_NEXT_RELEASE
+++ b/CHANGES_NEXT_RELEASE
@@ -1,2 +1,2 @@
-- FIX: store commands from Group at Device level at provision device time
+- Fix: store commands from Group at Device level at provision device time
 - Log device id when BadTimestamp error