|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +RSpec.describe Superset::Sqllab::Execute do |
| 4 | + subject { described_class.new( |
| 5 | + database_id: database_id, |
| 6 | + query: query) } |
| 7 | + |
| 8 | + let(:database_id) { 1 } |
| 9 | + let(:query) { 'select id, category, country from sales order by id asc limit 2' } |
| 10 | + let(:response) { |
| 11 | + { |
| 12 | + "query_id"=>1111, |
| 13 | + "status"=>"success", |
| 14 | + "data"=> |
| 15 | + [ |
| 16 | + {"id"=>1, "category"=>"A", "country"=>"Australia"}, |
| 17 | + {"id"=>2, "category"=>"B", "country"=>"New Zealand"} |
| 18 | + ] |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + before do |
| 23 | + allow(subject).to receive(:response).and_return(response) |
| 24 | + end |
| 25 | + |
| 26 | + describe 'perform' do |
| 27 | + context 'with valid params' do |
| 28 | + it 'returns the new dashboard object' do |
| 29 | + expect(subject.perform).to eq(response["data"]) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + context 'with invalid params' do |
| 34 | + context 'when database_id is not an integer' do |
| 35 | + let(:database_id) { 'q' } |
| 36 | + |
| 37 | + it 'raises an error' do |
| 38 | + expect { subject.perform }.to raise_error(Superset::Sqllab::Execute::InvalidParameterError, |
| 39 | + "database_id integer is required") |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context 'when database_id is not present' do |
| 44 | + let(:database_id) { nil } |
| 45 | + |
| 46 | + it 'raises an error' do |
| 47 | + expect { subject.perform }.to raise_error(Superset::Sqllab::Execute::InvalidParameterError, |
| 48 | + "database_id integer is required") |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + context 'when query is not a string' do |
| 53 | + let(:query) { 1 } |
| 54 | + |
| 55 | + it 'raises an error' do |
| 56 | + expect { subject.perform }.to raise_error(Superset::Sqllab::Execute::InvalidParameterError, |
| 57 | + "query string is required") |
| 58 | + end |
| 59 | + end |
| 60 | + |
| 61 | + context 'when query is not present' do |
| 62 | + let(:query) { nil } |
| 63 | + |
| 64 | + it 'raises an error' do |
| 65 | + expect { subject.perform }.to raise_error(Superset::Sqllab::Execute::InvalidParameterError, |
| 66 | + "query string is required") |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + end |
| 71 | + end |
| 72 | +end |
0 commit comments