Skip to content

Commit

Permalink
Stop adding successful results to errors array when creating virtual …
Browse files Browse the repository at this point in the history
…objects

Refs sul-dlss/argo#1728
  • Loading branch information
mjgiarlo committed Dec 6, 2019
1 parent 7f42d93 commit f855e23
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/jobs/create_virtual_objects_job.rb
Expand Up @@ -13,7 +13,10 @@ def perform(virtual_objects:, background_job_result:)
virtual_objects.each do |virtual_object|
parent_id, child_ids = virtual_object.values_at(:parent_id, :child_ids)
# Update the constituent relationship between the parent and child druids
errors << ConstituentService.new(parent_druid: parent_id).add(child_druids: child_ids)
result = ConstituentService.new(parent_druid: parent_id).add(child_druids: child_ids)
# Do not add `nil`s to the errors array as they signify successful
# creation of the virtual object
errors << result if result.present?
rescue ActiveFedora::ObjectNotFoundError, Rubydora::FedoraInvalidRequest, Dor::Exception => e
errors << { parent_id => [e.message] }
rescue StandardError => e
Expand Down
36 changes: 36 additions & 0 deletions spec/jobs/create_virtual_objects_job_spec.rb
Expand Up @@ -62,4 +62,40 @@
expect(result.output[:errors].first[parent_id]).to match_array(['One thing was not combinable', 'And another'])
end
end

context 'with a mix of errors and successful results' do
let(:other_child1_id) { 'druid:bar' }
let(:other_child2_id) { 'druid:baz' }
let(:other_parent_id) { 'druid:foo' }
let(:virtual_objects) do
[
{ parent_id: parent_id, child_ids: [child1_id, child2_id] },
{ parent_id: other_parent_id, child_ids: [other_child1_id, other_child2_id] }
]
end

before do
allow(ConstituentService).to receive(:new).with(parent_druid: other_parent_id).and_return(service)
allow(service).to receive(:add).and_return(nil, parent_id => ['One thing was not combinable', 'And another'])
described_class.perform_now(virtual_objects: virtual_objects,
background_job_result: result)
end

it 'marks the job as processing' do
expect(result).to have_received(:processing!).once
end

it 'invokes the constituent service to do the virtual object creation' do
expect(service).to have_received(:add).with(child_druids: [child1_id, child2_id]).once
expect(service).to have_received(:add).with(child_druids: [other_child1_id, other_child2_id]).once
end

it 'marks the job as complete' do
expect(result).to be_complete
end

it 'has output with errors' do
expect(result.output[:errors].first[parent_id]).to match_array(['One thing was not combinable', 'And another'])
end
end
end

0 comments on commit f855e23

Please sign in to comment.