spec/models/entity_spec.rb in maestrano-connector-rails-1.0.4 vs spec/models/entity_spec.rb in maestrano-connector-rails-1.1.0
- old
+ new
@@ -74,10 +74,14 @@
describe 'last_update_date_from_external_entity_hash' do
it { expect{ subject.last_update_date_from_external_entity_hash(nil) }.to raise_error('Not implemented') }
end
+ describe 'creation_date_from_external_entity_hash' do
+ it { expect{ subject.creation_date_from_external_entity_hash(nil) }.to raise_error('Not implemented') }
+ end
+
# Entity specific methods
describe 'singleton?' do
it 'is false by default' do
expect(subject.singleton?).to be false
end
@@ -164,11 +168,11 @@
end
end
# Connec! methods
describe 'connec_methods' do
- let(:sync) { create(:synchronization) }
+ let(:sync) { create(:synchronization, organization: organization) }
describe 'filter_connec_entities' do
it 'does nothing by default' do
expect(subject.filter_connec_entities({a: 2})).to eql({a: 2})
end
@@ -209,11 +213,11 @@
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)
+ subject.get_connec_entities(sync.updated_at)
end
end
context 'when there is no last sync' do
it 'performs a full get' do
@@ -224,34 +228,34 @@
context 'when there is a last sync' do
it 'performs a time limited get' do
uri_param = {"$filter" => "updated_at gt '#{sync.updated_at.iso8601}'"}.to_query
expect(connec_client).to receive(:get).with("#{connec_name.downcase.pluralize}?#{uri_param}")
- subject.get_connec_entities(sync)
+ subject.get_connec_entities(sync.updated_at)
end
end
context 'with options' do
it 'support filter option for full sync' do
subject.instance_variable_set(:@opts, {full_sync: true, :$filter => "code eq 'PEO12'"})
uri_param = {'$filter'=>'code eq \'PEO12\''}.to_query
expect(connec_client).to receive(:get).with("#{connec_name.downcase.pluralize}?#{uri_param}")
- subject.get_connec_entities(sync)
+ subject.get_connec_entities(sync.updated_at)
end
it 'support filter option for time limited sync' do
subject.instance_variable_set(:@opts, {:$filter => "code eq 'PEO12'"})
uri_param = {"$filter"=>"updated_at gt '#{sync.updated_at.iso8601}' and code eq 'PEO12'"}.to_query
expect(connec_client).to receive(:get).with("#{connec_name.downcase.pluralize}?#{uri_param}")
- subject.get_connec_entities(sync)
+ subject.get_connec_entities(sync.updated_at)
end
it 'support orderby option for time limited sync' do
subject.instance_variable_set(:@opts, {:$orderby => "name asc"})
uri_param = {"$orderby"=>"name asc", "$filter"=>"updated_at gt '#{sync.updated_at.iso8601}'"}.to_query
expect(connec_client).to receive(:get).with("#{connec_name.downcase.pluralize}?#{uri_param}")
- subject.get_connec_entities(sync)
+ subject.get_connec_entities(sync.updated_at)
end
end
context 'with pagination' do
before {
@@ -618,10 +622,11 @@
let(:id) { '56882' }
let(:date) { 2.hour.ago }
before {
allow(subject.class).to receive(:id_from_external_entity_hash).and_return(id)
allow(subject.class).to receive(:last_update_date_from_external_entity_hash).and_return(date)
+ allow(subject.class).to receive(:creation_date_from_external_entity_hash).and_return(date)
}
describe 'consolidate_and_map_data' do
context 'singleton' do
before {
@@ -724,12 +729,12 @@
let(:connec_human_name) { 'connec human name' }
let(:id1) { 'external-unfolded-id' }
let(:id2) { nil }
let(:connec_id1) { 'connec-id-1' }
let(:connec_id2) { 'connec-id-2' }
- let(:entity1) { {'id' => id1, 'name' => 'John', 'updated_at' => date} }
- let(:entity2) { {'id' => id2, 'name' => 'Jane', 'updated_at' => date} }
+ let(:entity1) { {'id' => id1, 'name' => 'John', 'updated_at' => date, 'created_at' => date} }
+ let(:entity2) { {'id' => id2, 'name' => 'Jane', 'updated_at' => date, 'created_at' => date} }
let(:entity_without_refs) { {} }
let(:entities) { [entity1, entity2] }
before {
allow(subject.class).to receive(:object_name_from_connec_entity_hash).and_return(connec_human_name)
allow(subject).to receive(:map_to_external).and_return({mapped: 'entity'})
@@ -786,10 +791,28 @@
expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1}])
end
end
end
+ context 'when before date_filtering_limit' do
+ before {
+ organization.update(date_filtering_limit: 5.minutes.ago)
+ }
+
+ it 'discards the entity' do
+ expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([])
+ end
+
+ context 'with full synchronization opts' do
+ let(:opts) { {full_sync: true} }
+
+ it 'keeps the entity' do
+ expect(subject.consolidate_and_map_connec_entities(entities, [], [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: idmap1}])
+ end
+ end
+ end
+
end
context 'when conflict' do
let(:entities) { [entity1] }
let(:external_entity_1) { {'id' => id1} }
@@ -890,9 +913,27 @@
end
end
context 'when last_push_to_connec is recent' do
before { idmap.update(last_push_to_connec: 2.second.ago) }
+
+ it 'discards the entity' do
+ expect(subject.consolidate_and_map_external_entities([entity], connec_name)).to eql([])
+ end
+
+ context 'with full synchronization opts' do
+ let(:opts) { {full_sync: true} }
+
+ it 'keeps the entity' do
+ expect(subject.consolidate_and_map_external_entities([entity], connec_name)).to eql([{entity: {mapped: 'ext_entity'}, idmap: idmap}])
+ end
+ end
+ end
+
+ context 'when before date_filtering_limit' do
+ before {
+ organization.update(date_filtering_limit: 5.minutes.ago)
+ }
it 'discards the entity' do
expect(subject.consolidate_and_map_external_entities([entity], connec_name)).to eql([])
end
\ No newline at end of file