spec/models/entity_spec.rb in maestrano-connector-rails-1.3.4 vs spec/models/entity_spec.rb in maestrano-connector-rails-1.3.5

- old
+ new

@@ -4,11 +4,11 @@ describe 'class methods' do subject { Maestrano::Connector::Rails::Entity } # IdMap methods - describe 'idmaps mehtods' do + describe 'idmaps methods' do before { allow(subject).to receive(:connec_entity_name).and_return('Ab') allow(subject).to receive(:external_entity_name).and_return('Ab') } let(:n_hash) { {connec_entity: 'ab', external_entity: 'ab'} } @@ -109,13 +109,13 @@ 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) + describe 'count_and_first' do + it 'returns the array size and the first element' do + expect(subject.count_and_first([*1..27])).to eql(count: 27, first: 1) end end describe 'public_connec_entity_name' do it 'returns the pluralized connec_entity_name' do @@ -450,11 +450,11 @@ } it 'does one call' do expect(connec_client).to receive(:batch).once subject.push_entities_to_connec_to(entities, connec_name) - end + end end context 'when more than 100 entities' do before { 100.times do @@ -698,10 +698,16 @@ msg = 'Large corporations use our integrated platform to provide a fully customized environment to their clients, increasing revenue, engagement and gaining insight on client behavior through our Big Data technology. Large corporations use our integrated platform to provide a fully customized environment to their clients, increasing revenue, engagement and gaining insight on client behavior through our Big Data technology.' allow(subject).to receive(:create_external_entity).and_raise(msg) subject.push_entity_to_external(entity_with_idmap2, external_name) expect(idmap2.reload.message).to include(msg.truncate(255)) end + + it 'can raise a custom exception' do + allow(subject).to receive(:update_external_entity).and_raise(Maestrano::Connector::Rails::Exceptions::EntityNotFoundError.new) + subject.push_entity_to_external(entity_with_idmap1, external_name) + expect(idmap1.reload.message).to include("The external_name record has been deleted in External app.") + end end end describe 'create_external_entity' do let(:organization) { create(:organization) } @@ -722,17 +728,17 @@ 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 { allow(subject.class).to receive(:singleton?).and_return(true) } - + it 'returns the consolidate_and_map_singleton method result' do expect(subject).to receive(:consolidate_and_map_singleton).with({}, {}).and_return({result: 1}) expect(subject.consolidate_and_map_data({}, {})).to eql({result: 1}) end end @@ -942,22 +948,22 @@ before { allow(subject.class).to receive(:last_update_date_from_external_entity_hash).and_return(external_date) } context 'with connec one more recent' do - let(:external_date) { 1.year.ago } - let(:date) { 1.day.ago } + let(:external_date) { 1.year.ago } + let(:date) { 1.day.ago } it 'keeps the entity and discards the external one' do expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([{entity: {mapped: 'entity'}, idmap: Maestrano::Connector::Rails::IdMap.first, id_refs_only_connec_entity: id_refs_only_connec_entity}]) expect(external_entities).to be_empty end end context 'with external one more recent' do - let(:external_date) { 1.month.ago } - let(:date) { 1.year.ago } + let(:external_date) { 1.month.ago } + let(:date) { 1.year.ago } it 'discards the entity and keep the external one' do expect(subject.consolidate_and_map_connec_entities(entities, external_entities, [], external_name)).to eql([]) expect(external_entities).to_not be_empty end @@ -1050,6 +1056,6 @@ end end end -end \ No newline at end of file +end