|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +RSpec.describe Superset::Services::DashboardReport do |
| 4 | + let(:dashboard_ids) { [1, 2] } |
| 5 | + let(:service) { described_class.new(dashboard_ids: dashboard_ids) } |
| 6 | + |
| 7 | + describe '#perform' do |
| 8 | + let(:dashboard_response) do |
| 9 | + { |
| 10 | + 'dashboard_title' => 'Test Dashboard', |
| 11 | + 'tags' => [{'name' => 'tag1'}, {'name' => 'tag2'}], |
| 12 | + 'json_metadata' => { |
| 13 | + 'native_filter_configuration' => [ |
| 14 | + { |
| 15 | + 'type' => 'NATIVE_FILTER', |
| 16 | + 'targets' => [{'datasetId' => 100}] |
| 17 | + } |
| 18 | + ], |
| 19 | + 'chart_configuration' => [{}, {}] # 2 charts |
| 20 | + }.to_json |
| 21 | + } |
| 22 | + end |
| 23 | + |
| 24 | + let(:datasets_response) do |
| 25 | + [ |
| 26 | + {id: 1, schema: 'schema1', title: 'Dataset 1'}, |
| 27 | + {id: 2, schema: 'schema1', title: 'Dataset 2'} |
| 28 | + ] |
| 29 | + end |
| 30 | + |
| 31 | + before do |
| 32 | + allow_any_instance_of(Superset::Dashboard::Get).to receive(:result).and_return(dashboard_response) |
| 33 | + allow_any_instance_of(Superset::Dashboard::Get).to receive(:url).and_return('http://example.com/dashboard/1') |
| 34 | + allow_any_instance_of(Superset::Dashboard::Datasets::List).to receive(:rows_hash).and_return(datasets_response) |
| 35 | + end |
| 36 | + |
| 37 | + context 'when report_on_data_sovereignty_only is true' do |
| 38 | + it 'returns data sovereignty issues only' do |
| 39 | + result = service.perform |
| 40 | + binding.pry |
| 41 | + expect(result).to be_an(Array) |
| 42 | + expect(result).to all(include(:reasons, :dashboard)) |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'when report_on_data_sovereignty_only is false' do |
| 47 | + let(:service) { described_class.new(dashboard_ids: dashboard_ids, report_on_data_sovereignty_only: false) } |
| 48 | + |
| 49 | + it 'returns full dashboard report' do |
| 50 | + result = service.perform |
| 51 | + expect(result).to be_an(Array) |
| 52 | + expect(result.first).to include( |
| 53 | + :dashboard_id, |
| 54 | + :dashboard_title, |
| 55 | + :dashboard_url, |
| 56 | + :dashboard_tags, |
| 57 | + :filters, |
| 58 | + :charts, |
| 59 | + :datasets |
| 60 | + ) |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + describe '#data_sovereignty_issues' do |
| 66 | + context 'when filter dataset is not in chart datasets' do |
| 67 | + let(:dashboard_response) do |
| 68 | + { |
| 69 | + 'dashboard_title' => 'Test Dashboard', |
| 70 | + 'tags' => [], |
| 71 | + 'json_metadata' => { |
| 72 | + 'native_filter_configuration' => [ |
| 73 | + { |
| 74 | + 'type' => 'NATIVE_FILTER', |
| 75 | + 'targets' => [{'datasetId' => 999}] |
| 76 | + } |
| 77 | + ], |
| 78 | + 'chart_configuration' => [] |
| 79 | + }.to_json |
| 80 | + } |
| 81 | + end |
| 82 | + |
| 83 | + let(:datasets_response) do |
| 84 | + [ |
| 85 | + {id: 1, schema: 'schema1', title: 'Dataset 1'} |
| 86 | + ] |
| 87 | + end |
| 88 | + |
| 89 | + before do |
| 90 | + allow_any_instance_of(Superset::Dashboard::Get).to receive(:result).and_return(dashboard_response) |
| 91 | + allow_any_instance_of(Superset::Dashboard::Get).to receive(:url).and_return('http://example.com/dashboard/1') |
| 92 | + allow_any_instance_of(Superset::Dashboard::Datasets::List).to receive(:rows_hash).and_return(datasets_response) |
| 93 | + allow_any_instance_of(Superset::Dataset::Get).to receive(:result) |
| 94 | + allow_any_instance_of(Superset::Dataset::Get).to receive(:id).and_return(999) |
| 95 | + allow_any_instance_of(Superset::Dataset::Get).to receive(:title).and_return('Unknown Dataset') |
| 96 | + end |
| 97 | + |
| 98 | + it 'reports warning for unknown filter datasets' do |
| 99 | + result = service.perform |
| 100 | + expect(result.first[:reasons]).to include(a_string_matching(/WARNING: One or more filter datasets/)) |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + context 'when multiple schemas are found' do |
| 105 | + let(:datasets_response) do |
| 106 | + [ |
| 107 | + {id: 1, schema: 'schema1', title: 'Dataset 1'}, |
| 108 | + {id: 2, schema: 'schema2', title: 'Dataset 2'} |
| 109 | + ] |
| 110 | + end |
| 111 | + |
| 112 | + before do |
| 113 | + allow_any_instance_of(Superset::Dashboard::Get).to receive(:result).and_return( |
| 114 | + { |
| 115 | + 'dashboard_title' => 'Test Dashboard', |
| 116 | + 'tags' => [], |
| 117 | + 'json_metadata' => { |
| 118 | + 'native_filter_configuration' => [], |
| 119 | + 'chart_configuration' => [{}, {}] |
| 120 | + }.to_json |
| 121 | + } |
| 122 | + ) |
| 123 | + allow_any_instance_of(Superset::Dashboard::Get).to receive(:url).and_return('http://example.com/dashboard/1') |
| 124 | + allow_any_instance_of(Superset::Dashboard::Datasets::List).to receive(:rows_hash).and_return(datasets_response) |
| 125 | + end |
| 126 | + |
| 127 | + it 'reports error for multiple schemas' do |
| 128 | + result = service.perform |
| 129 | + expect(result.first[:reasons]).to include(a_string_matching(/ERROR: Multiple distinct chart dataset schemas/)) |
| 130 | + end |
| 131 | + end |
| 132 | + end |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +end |
0 commit comments