From b9696dfa96951d4251a2fdca701910b3296ed7d5 Mon Sep 17 00:00:00 2001 From: Sang Truong Date: Thu, 6 Jan 2022 04:53:18 +0700 Subject: [PATCH] BUGFIX:MSF-22702 - Show error message if gd_encoded_params or gd_encoded_hidden_params is not specified --- lib/gooddata/helpers/global_helpers_params.rb | 2 ++ spec/unit/helpers/global_helpers_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/gooddata/helpers/global_helpers_params.rb b/lib/gooddata/helpers/global_helpers_params.rb index 6b977e351..ef084ee09 100644 --- a/lib/gooddata/helpers/global_helpers_params.rb +++ b/lib/gooddata/helpers/global_helpers_params.rb @@ -61,6 +61,8 @@ def encode_hidden_params(params) def decode_params(params, options = {}) key = ENCODED_PARAMS_KEY.to_s hidden_key = ENCODED_HIDDEN_PARAMS_KEY.to_s + raise "Mandatory parameter '#{key}' or '#{hidden_key}' of type 'HashType' needs to be specified" if params[key].nil? && params[hidden_key].nil? + data_params = params[key] || '{}' hidden_data_params = if params.key?(hidden_key) && params[hidden_key].nil? "{\"#{hidden_key}\" : null}" diff --git a/spec/unit/helpers/global_helpers_spec.rb b/spec/unit/helpers/global_helpers_spec.rb index 1118a487c..4866956cb 100644 --- a/spec/unit/helpers/global_helpers_spec.rb +++ b/spec/unit/helpers/global_helpers_spec.rb @@ -62,8 +62,8 @@ end it 'should encode params and preserve the nil in hidden' do - x = GoodData::Helpers.decode_params(GoodData::Helpers::ENCODED_HIDDEN_PARAMS_KEY.to_s => nil) - expect(x).to eq("gd_encoded_hidden_params" => nil) + x = GoodData::Helpers.decode_params(GoodData::Helpers::ENCODED_HIDDEN_PARAMS_KEY.to_s => nil, GoodData::Helpers::ENCODED_PARAMS_KEY.to_s => '{"d":{"b": "c"}}') + expect(x).to eq({"d"=>{"b"=>"c"}, "gd_encoded_hidden_params"=>nil}) end it 'should encode params and preserve the nil in hidden' do