spec/models/entity_spec.rb in maestrano-connector-rails-1.1.2 vs spec/models/entity_spec.rb in maestrano-connector-rails-1.2.0

- old
+ new

@@ -108,10 +108,16 @@ end describe 'connec_matching_fields' do it { expect(subject.connec_matching_fields).to be_nil } end + + describe 'count_entities' do + it 'returns the array size' do + expect(subject.count_entities([*1..27])).to eql(27) + end + end end describe 'instance methods' do let!(:organization) { create(:organization, uid: 'cld-123') } let!(:connec_client) { Maestrano::Connec::Client[organization.tenant].new(organization.uid) } @@ -187,11 +193,11 @@ it { expect(subject.get_connec_entities(nil)).to eql([]) } end describe 'when skip_connec' do - let(:opts) { {skip_connec: true} } + let(:opts) { {__skip_connec: true} } it { expect(subject.get_connec_entities(nil)).to eql([]) } end describe 'with response' do context 'for a singleton resource' do @@ -209,10 +215,23 @@ context 'for a non singleton resource' do before { allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: []}.to_json, {})) } + context 'with limit and skip opts' do + let(:opts) { {__skip: 100, __limit: 50} } + before { + allow(connec_client).to receive(:get).and_return(ActionDispatch::Response.new(200, {}, {people: [], pagination: {next: "https://api-connec.maestrano.com/api/v2/cld-dkg601/people?%24skip=10&%24top=10"}}.to_json, {}), ActionDispatch::Response.new(200, {}, {people: []}.to_json, {})) + } + + it 'performs a size limited date and do not paginate' do + uri_param = {"$filter" => "updated_at gt '#{sync.updated_at.iso8601}'", "$skip" => 100, "$top" => 50}.to_query + expect(connec_client).to receive(:get).once.with("#{connec_name.downcase.pluralize}?#{uri_param}") + subject.get_connec_entities(sync.updated_at) + end + end + context 'when opts[:full_sync] is true' do let(:opts) { {full_sync: true} } it 'performs a full get' do expect(connec_client).to receive(:get).with("#{connec_name.downcase.pluralize}?") subject.get_connec_entities(sync.updated_at) @@ -472,10 +491,10 @@ expect(subject.get_external_entities_wrapper(nil)).to eql([]) end end context 'when skip external' do - let(:opts) { {skip_external: true} } + let(:opts) { {__skip_external: true} } it 'returns an empty array and does not call get_external_entities' do expect(subject).to_not receive(:get_connec_entities) expect(subject.get_external_entities_wrapper(nil)).to eql([]) end \ No newline at end of file