spec/models/entity_spec.rb in maestrano-connector-rails-0.2.12 vs spec/models/entity_spec.rb in maestrano-connector-rails-0.2.13
- old
+ new
@@ -372,12 +372,12 @@
before {
allow(subject).to receive(:object_name_from_external_entity_hash).and_return(human_name)
}
it 'creates an idmap and returns the mapped entity with its new idmap' do
- subject.consolidate_and_map_data([], entities, organization)
- expect(entities).to eql([{entity: mapped_entity, idmap: Maestrano::Connector::Rails::IdMap.last}])
+ mapped_entities = subject.consolidate_and_map_data([], entities, organization)
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: Maestrano::Connector::Rails::IdMap.last}]})
end
it 'save the name in the idmap' do
subject.consolidate_and_map_data([], entities, organization)
expect(Maestrano::Connector::Rails::IdMap.last.name).to eql(human_name)
@@ -386,23 +386,23 @@
context 'when entity has an idmap with a last_push_to_connec more recent than date' do
let!(:idmap) { create(:idmap, external_entity: external_name, external_id: id, organization: organization, last_push_to_connec: 2.minute.ago) }
it 'discards the entity' do
- subject.consolidate_and_map_data([], entities, organization)
- expect(entities).to eql([])
+ mapped_entities = subject.consolidate_and_map_data([], entities, organization)
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: []})
end
end
context 'when entity has an idmap with a last_push_to_connec older than date' do
context 'with no conflict' do
let!(:idmap) { create(:idmap, external_entity: external_name, external_id: id, organization: organization, last_push_to_connec: 2.day.ago) }
it 'returns the mapped entity with its idmap' do
- subject.consolidate_and_map_data([], entities, organization)
- expect(entities).to eql([{entity: mapped_entity, idmap: idmap}])
+ mapped_entities = subject.consolidate_and_map_data([], entities, organization)
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: idmap}]})
end
end
context 'with conflict' do
let(:connec_id) { '34uuu-778aa' }
@@ -414,39 +414,39 @@
context 'with connec_preemption opt' do
context 'set to true' do
let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.day.ago} }
it 'discards the entity' do
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
- expect(entities).to eql([])
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: []})
end
end
context 'set to false' do
let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.second.ago} }
it 'returns the mapped entity with its idmap' do
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
- expect(entities).to eql([{entity: mapped_entity, idmap: idmap}])
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: idmap}]})
end
end
end
context 'without opt' do
context 'with a more recent connec entity' do
let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.second.ago} }
it 'discards the entity' do
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
- expect(entities).to eql([])
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: true})
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: []})
end
end
context 'with a more recent external_entity' do
let(:connec_entity) { {'id' => connec_id, 'first_name' => 'Richard', 'updated_at' => 1.year.ago} }
it 'returns the mapped entity with its idmap' do
- subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
- expect(entities).to eql([{entity: mapped_entity, idmap: idmap}])
+ mapped_entities = subject.consolidate_and_map_data([connec_entity], entities, organization, {connec_preemption: false})
+ expect(mapped_entities).to eql({connec_entities: [], external_entities: [{entity: mapped_entity, idmap: idmap}]})
end
end
end
end
\ No newline at end of file