|
14 | 14 | it 'returns the guest token from the response' do
|
15 | 15 | expect(subject.guest_token).to eq('some-token')
|
16 | 16 | end
|
| 17 | + |
| 18 | + context 'when invalid rls clause is passed' do |
| 19 | + before { allow(subject).to receive(:rls_clause).and_return(rls_clause) } |
| 20 | + context 'when rls_clause is nil' do |
| 21 | + let(:rls_clause) { nil } |
| 22 | + it 'raises invalid parameter error' do |
| 23 | + expect{ subject.guest_token }.to raise_error(Superset::Request::InvalidParameterError, 'rls_clause should be an array. But it is NilClass') |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + context 'when rls_clause is not an array' do |
| 28 | + let(:rls_clause) { { "clause": "publisher = 'Nintendo'" } } |
| 29 | + it 'raises invalid parameter error' do |
| 30 | + expect{ subject.guest_token }.to raise_error(Superset::Request::InvalidParameterError, "rls_clause should be an array. But it is Hash") |
| 31 | + end |
| 32 | + end |
| 33 | + end |
17 | 34 | end
|
18 | 35 |
|
19 | 36 | describe '#params' do
|
20 |
| - before do |
21 |
| - allow(subject).to receive(:current_user).and_return(user) |
22 |
| - end |
| 37 | + context "with additional params" do |
| 38 | + before do |
| 39 | + allow(subject).to receive(:additional_params).and_return(additional_params) |
| 40 | + end |
23 | 41 |
|
24 |
| - context 'without a current_user' do |
25 |
| - let(:user) { nil } |
| 42 | + context 'without a current_user' do |
| 43 | + let(:additional_params) { {} } |
| 44 | + |
| 45 | + specify do |
| 46 | + expect(subject.params).to eq( |
| 47 | + { |
| 48 | + "resources": [ |
| 49 | + { |
| 50 | + "id": ss_dashboard_id, |
| 51 | + "type": "dashboard" } |
| 52 | + ], |
| 53 | + "rls": [], |
| 54 | + "user": { } |
| 55 | + } |
| 56 | + ) |
| 57 | + end |
| 58 | + end |
26 | 59 |
|
| 60 | + context 'with a current_user' do |
| 61 | + let(:additional_params) { {embedded_app_current_user_id: 1} } |
| 62 | + |
| 63 | + specify 'passes user id to superset' do |
| 64 | + expect(subject.params).to eq( |
| 65 | + { |
| 66 | + "resources": [ |
| 67 | + { |
| 68 | + "id": ss_dashboard_id, |
| 69 | + "type": "dashboard" } |
| 70 | + ], |
| 71 | + "rls": [], |
| 72 | + "user": { username: additional_params[:embedded_app_current_user_id].to_s }, |
| 73 | + "embedded_app_current_user_id": additional_params[:embedded_app_current_user_id] |
| 74 | + } |
| 75 | + ) |
| 76 | + end |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + context 'with rls clause' do |
| 81 | + before { allow(subject).to receive(:rls_clause).and_return(rls_clause) } |
| 82 | + let(:rls_clause) { [{ "clause": "publisher = 'Nintendo'" }] } |
27 | 83 | specify do
|
28 | 84 | expect(subject.params).to eq(
|
29 | 85 | {
|
|
32 | 88 | "id": ss_dashboard_id,
|
33 | 89 | "type": "dashboard" }
|
34 | 90 | ],
|
35 |
| - "rls": [], |
| 91 | + "rls": rls_clause, |
36 | 92 | "user": { }
|
37 | 93 | }
|
38 | 94 | )
|
39 | 95 | end
|
40 | 96 | end
|
41 | 97 |
|
42 |
| - context 'with a current_user' do |
43 |
| - let(:user) { double(id: 101) } |
44 |
| - |
45 |
| - specify 'passes user id to superset' do |
| 98 | + context 'with rls clause as empty array' do |
| 99 | + before { allow(subject).to receive(:rls_clause).and_return(rls_clause) } |
| 100 | + let(:rls_clause) { [] } |
| 101 | + specify do |
46 | 102 | expect(subject.params).to eq(
|
47 | 103 | {
|
48 | 104 | "resources": [
|
|
51 | 107 | "type": "dashboard" }
|
52 | 108 | ],
|
53 | 109 | "rls": [],
|
54 |
| - "user": { username: "101" } |
| 110 | + "user": { } |
55 | 111 | }
|
56 | 112 | )
|
57 | 113 | end
|
|
0 commit comments