From 8b9ebe9bf2523b0a5bdd3391fc4b5660eacf2f3c Mon Sep 17 00:00:00 2001
From: IGetmanets <igetmanets@luxoft.com>
Date: Thu, 17 Feb 2022 17:18:17 +0200
Subject: [PATCH] Script for issue 3859

---
 ..._in_response_during_erroneous_response.lua | 81 +++++++++++++++++++
 test_sets/Defects/Defects_release_8_1.txt     |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 test_scripts/Defects/8_1/3859_CreateInteractionChoiceSet_info_in_response_during_erroneous_response.lua

diff --git a/test_scripts/Defects/8_1/3859_CreateInteractionChoiceSet_info_in_response_during_erroneous_response.lua b/test_scripts/Defects/8_1/3859_CreateInteractionChoiceSet_info_in_response_during_erroneous_response.lua
new file mode 100644
index 0000000000..93683eebe0
--- /dev/null
+++ b/test_scripts/Defects/8_1/3859_CreateInteractionChoiceSet_info_in_response_during_erroneous_response.lua
@@ -0,0 +1,81 @@
+---------------------------------------------------------------------------------------------------
+-- Issue: https://github.com/smartdevicelink/sdl_core/issues/3859
+---------------------------------------------------------------------------------------------------
+-- Description: Check that SDL transfers the error message from the HMI response to the mobile app
+
+-- Steps:
+-- 1. HMI and SDL are started
+-- 2. Mobile app is registered and activated
+-- 3. Mobile app requests CreateInteractionChoiceSet RPC
+-- 4. SDL sends VR.AddCommand(type = "Choice") request to the HMI
+-- 5. HMI responds with erroneous code and error message to the VR.AddCommand(type = "Choice") request
+-- SDL does:
+-- 1. process the VR.AddCommand response from HMI
+-- 2. send the CreateInteractionChoiceSet response to the mobile app with received error code and message
+---------------------------------------------------------------------------------------------------
+
+--[[ Required Shared libraries ]]
+local runner = require('user_modules/script_runner')
+local common = require('user_modules/sequences/actions')
+
+--[[ Test Configuration ]]
+runner.testSettings.isSelfIncluded = false
+
+--[[ Local Variables ]]
+local requestParams = {
+  interactionChoiceSetID = 1001,
+  choiceSet = {
+    {
+      choiceID = 1001,
+      menuName ="Choice1001",
+      vrCommands = {
+        "Choice1001"
+      }
+    }
+  }
+}
+local errorCodes = {
+  "DISALLOWED",
+  "REJECTED",
+  "ABORTED",
+  "IGNORED",
+  "IN_USE",
+  "TIMED_OUT",
+  "INVALID_DATA",
+  "CHAR_LIMIT_EXCEEDED",
+  "INVALID_ID",
+  "DUPLICATE_NAME",
+  "GENERIC_ERROR",
+  "UNSUPPORTED_REQUEST",
+  "USER_DISALLOWED",
+  "READ_ONLY"
+}
+
+--[[ Local Functions ]]
+local function createInteractionChoiceSet(resultCode)
+  local errorMessage = "Error message"
+
+  local cid = common.getMobileSession():SendRPC("CreateInteractionChoiceSet", requestParams)
+  common.getHMIConnection():ExpectRequest("VR.AddCommand")
+  :Do(function(_, data)
+      common.getHMIConnection():SendError(data.id, data.method, resultCode, "Error message")
+    end)
+  common.getMobileSession():ExpectResponse(cid, { success = false, resultCode = resultCode, info = errorMessage })
+  common.getMobileSession():ExpectNotification("OnHashChange")
+  :Times(0)
+end
+
+--[[ Scenario ]]
+runner.Title("Preconditions")
+runner.Step("Clean environment", common.preconditions)
+runner.Step("Start SDL, HMI, connect Mobile, start Session", common.start)
+runner.Step("Register App", common.registerApp)
+runner.Step("Activate App", common.activateApp)
+
+runner.Title("Test")
+for _, code in ipairs(errorCodes) do
+  runner.Step("CreateInteractionChoiceSet with result code:" .. code, createInteractionChoiceSet, { code })
+end
+
+runner.Title("Postconditions")
+runner.Step("Stop SDL", common.postconditions)
diff --git a/test_sets/Defects/Defects_release_8_1.txt b/test_sets/Defects/Defects_release_8_1.txt
index 8c05385e14..c690bc25c1 100644
--- a/test_sets/Defects/Defects_release_8_1.txt
+++ b/test_sets/Defects/Defects_release_8_1.txt
@@ -24,3 +24,4 @@
 ./test_scripts/Defects/8_1/3845/3845_4_PerformAudioPassThru_custom_success_codes_in_error_structure_to_ui.lua
 ./test_scripts/Defects/8_1/3845/3845_5_PerformAudioPassThru_custom_success_codes_in_error_structure_to_tts.lua
 ./test_scripts/Defects/8_1/3845/3845_6_PerformAudioPassThru_custom_success_codes_in_error_structure_to_tts_and_ui.lua
+./test_scripts/Defects/8_1/3859_CreateInteractionChoiceSet_info_in_response_during_erroneous_response.lua