spec/models/entity_spec.rb in maestrano-connector-rails-0.3.6 vs spec/models/entity_spec.rb in maestrano-connector-rails-0.3.7

- old
+ new

@@ -201,11 +201,11 @@ allow(client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {person: []}.to_json, {})) allow(subject.class).to receive(:singleton?).and_return(true) } it 'calls get with a singularize url' do - expect(client).to receive(:get).with("/#{connec_name.downcase}") + expect(client).to receive(:get).with("/#{connec_name.downcase}?") subject.get_connec_entities(client, nil, organization) end end context 'for a non singleton resource' do @@ -213,26 +213,46 @@ allow(client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: []}.to_json, {})) } context 'when opts[:full_sync] is true' do it 'performs a full get' do - expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}") - subject.get_connec_entities(client, nil, organization, {full_sync: true}) + expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}?") + subject.get_connec_entities(client, sync, organization, {full_sync: true}) end end context 'when there is no last sync' do it 'performs a full get' do - expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}") + expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}?") subject.get_connec_entities(client, nil, organization) end end context 'when there is a last sync' do it 'performs a time limited get' do - uri_param = URI.encode("$filter=updated_at gt '#{sync.updated_at.iso8601}'") + uri_param = {"$filter" => "updated_at gt '#{sync.updated_at.iso8601}'"}.to_query expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}?#{uri_param}") subject.get_connec_entities(client, sync, organization) + end + end + + context 'with options' do + it 'support filter option for full sync' do + uri_param = {'$filter'=>'code eq \'PEO12\''}.to_query + expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}?#{uri_param}") + subject.get_connec_entities(client, sync, organization, {full_sync: true, :$filter => "code eq 'PEO12'"}) + end + + it 'support filter option for time limited sync' do + uri_param = {"$filter"=>"updated_at gt '#{sync.updated_at.iso8601}' and code eq 'PEO12'"}.to_query + expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}?#{uri_param}") + subject.get_connec_entities(client, sync, organization, {:$filter => "code eq 'PEO12'"}) + end + + it 'support orderby option for time limited sync' do + uri_param = {"$orderby"=>"name asc", "$filter"=>"updated_at gt '#{sync.updated_at.iso8601}'"}.to_query + expect(client).to receive(:get).with("/#{connec_name.downcase.pluralize}?#{uri_param}") + subject.get_connec_entities(client, sync, organization, {:$orderby => "name asc"}) end end context 'with pagination' do before { \ No newline at end of file