Skip to content

Commit f15392b

Browse files
committed
adjust params naming
1 parent 565674b commit f15392b

File tree

3 files changed

+60
-17
lines changed

3 files changed

+60
-17
lines changed

lib/superset/dashboard/embedded/put.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ module Superset
22
module Dashboard
33
module Embedded
44
class Put < Superset::Request
5-
attr_reader :dashboard_id, :embedded_domain
5+
attr_reader :dashboard_id, :allowed_domains
66

7-
def initialize(dashboard_id: , embedded_domain: )
7+
def initialize(dashboard_id: , allowed_domains: )
88
@dashboard_id = dashboard_id
9-
@embedded_domain = embedded_domain
9+
@allowed_domains = allowed_domains
1010
end
1111

1212
def response
13+
raise InvalidParameterError, 'dashboard_id integer is required' if dashboard_id.nil? || dashboard_id.class != Integer
14+
raise InvalidParameterError, 'allowed_domains array is required' if allowed_domains.nil? || allowed_domains.class != Array
15+
1316
@response ||= client.put(route, params)
1417
end
1518

1619
def params
17-
{ "allowed_domains": [embedded_domain] }
20+
{ "allowed_domains": allowed_domains }
1821
end
1922

2023
def uuid

lib/superset/services/duplicate_dashboard.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class DuplicateDashboard < Superset::Request
99

1010
DUPLICATED_DATASET_SUFFIX = ' (COPY)'
1111

12-
attr_reader :source_dashboard_id, :target_schema, :target_database_id, :embedded_domain
12+
attr_reader :source_dashboard_id, :target_schema, :target_database_id, :allowed_domains
1313

14-
def initialize(source_dashboard_id:, target_schema:, target_database_id: , embedded_domain: '')
14+
def initialize(source_dashboard_id:, target_schema:, target_database_id: , allowed_domains: nil)
1515
@source_dashboard_id = source_dashboard_id
1616
@target_schema = target_schema
1717
@target_database_id = target_database_id
18-
@embedded_domain = embedded_domain
18+
@allowed_domains = allowed_domains
1919
end
2020

2121
def perform
@@ -49,9 +49,9 @@ def perform
4949
private
5050

5151
def created_embedded_config
52-
return unless embedded_domain.present?
52+
return unless allowed_domains.present?
5353

54-
result = Dashboard::Embedded::Put.new(dashboard_id: new_dashboard.id, embedded_domain: embedded_domain).result
54+
result = Dashboard::Embedded::Put.new(dashboard_id: new_dashboard.id, allowed_domains: allowed_domains).result
5555
logger.info " Embedded Domain Added to New Dashboard #{new_dashboard.id}:"
5656
logger.info " Embedded Domain allowed_domains: #{result['allowed_domains']}"
5757
logger.info " Embedded Domain uuid: #{result['uuid']}"

spec/superset/dashboard/embedded/put_spec.rb

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
require 'spec_helper'
22

33
RSpec.describe Superset::Dashboard::Embedded::Put, type: :service do
4-
subject { described_class.new(dashboard_id: dashboard_id, embedded_domain: allowed_domain) }
4+
subject { described_class.new(dashboard_id: dashboard_id, allowed_domains: allowed_domains) }
55
let(:dashboard_id) { 1 }
66

77
describe 'with a dashboard that has embedded settings, ie has a result' do
8-
let(:allowed_domain) { ['http://test-domain.io/'] }
8+
let(:allowed_domains) { ['http://test-domain.io/'] }
99
let(:uuid) { '631bxxxx-xxxx-xxxx-xxxx-xxxxxxxxx247' }
1010
let(:response) do
1111
{
1212
'result' =>
1313
{
14-
"allowed_domains" => allowed_domain,
14+
"allowed_domains" => allowed_domains,
1515
"changed_by"=>{"first_name"=>"Jay", "id"=>9, "last_name"=>"Bee", "username"=>"4bf....3f5"},
1616
"changed_on" => "2023-10-30T03:06:51.437527",
1717
"dashboard_id" => "1",
@@ -20,13 +20,53 @@
2020
}.with_indifferent_access
2121
end
2222

23-
before do
24-
allow(subject).to receive(:response).and_return(response)
23+
context 'with params' do
24+
before { allow(subject).to receive(:response).and_return(response) }
25+
26+
context 'that are valid' do
27+
it 'returns uuid' do
28+
expect(subject.uuid).to eq(uuid)
29+
end
30+
end
31+
end
32+
33+
context 'where allowed_domains is not an array' do
34+
let(:allowed_domains) { 'http://test-domain.io/' }
35+
36+
before { allow(subject).to receive(:response).and_call_original }
37+
38+
it 'raises error' do
39+
expect { subject.response }.to raise_error(Superset::Request::InvalidParameterError, "allowed_domains array is required")
40+
end
2541
end
2642

27-
describe '#uuid' do
28-
it 'returns uuid' do
29-
expect(subject.uuid).to eq(uuid)
43+
context 'where allowed_domains is nil' do
44+
let(:allowed_domains) { nil }
45+
46+
before { allow(subject).to receive(:response).and_call_original }
47+
48+
it 'raises error' do
49+
expect { subject.response }.to raise_error(Superset::Request::InvalidParameterError, "allowed_domains array is required")
50+
end
51+
end
52+
53+
context 'where dashboard_id is nil' do
54+
let(:dashboard_id) { nil }
55+
56+
before { allow(subject).to receive(:response).and_call_original }
57+
58+
it 'raises error' do
59+
expect { subject.response }.to raise_error(Superset::Request::InvalidParameterError, "dashboard_id integer is required")
60+
end
61+
end
62+
63+
context 'where dashboard_id is not an int' do
64+
let(:dashboard_id) { 'asdf' }
65+
66+
before { allow(subject).to receive(:response).and_call_original }
67+
68+
it 'raises error' do
69+
expect { subject.response }.to raise_error(Superset::Request::InvalidParameterError, "dashboard_id integer is required")
3070
end
3171
end
3272
end

0 commit comments

Comments
 (0)