Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i729 Specs #729

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions spec/actors/hyrax/actors/asset_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,63 @@
require 'rails_helper'

RSpec.describe Hyrax::Actors::AssetActor do
it "has tests" do
skip "Add your tests here"
let(:asset) { build(:asset, :with_physical_digital_and_essence_track, user: admin, intended_children_count: intended_children_count) }
let(:env) { Hyrax::Actors::Environment.new(asset, Ability.new(admin), attrs) }
let(:admin) { create(:admin_user) }
let(:attrs) { {} }
let(:intended_children_count) { 3 }
let(:terminator) { Hyrax::Actors::Terminator.new }

subject(:middleware) do
stack = ActionDispatch::MiddlewareStack.new.tap do |middleware|
middleware.use described_class
end
stack.build(terminator)
end

shared_examples 'setting validation status' do |method|
context 'when the asset has all of its intended children' do
let(:intended_children_count) { 3 }

it 'sets the status to "valid"' do
expect(asset.validation_status_for_aapb).to be_empty

middleware.public_send(method, env)

expect(asset.validation_status_for_aapb).to eq(['valid'])
end
end

context 'when the asset is missing children' do
let(:intended_children_count) { 5 }

it 'sets the status to "missing child record(s)"' do
expect(asset.validation_status_for_aapb).to be_empty

middleware.public_send(method,env)

expect(asset.validation_status_for_aapb).to eq(['missing child record(s)'])
end
end
end

describe '#create' do
it 'calls #set_validation_status' do
expect(middleware).to receive(:set_validation_status).once

middleware.create(env)
end

include_examples 'setting validation status', :create
end

describe '#update' do
it 'calls #set_validation_status' do
expect(middleware).to receive(:set_validation_status).once

middleware.update(env)
end

include_examples 'setting validation status', :update
end
end
2 changes: 2 additions & 0 deletions spec/models/asset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
it { is_expected.to have_property(:promo_description).with_predicate('http://pbcore.org#hasPromoDescription') }
it { is_expected.to have_property(:clip_description).with_predicate('http://pbcore.org#hasClipDescription') }
it { is_expected.to have_property(:producing_organization).with_predicate(::RDF::Vocab::DC11.creator) }
it { is_expected.to have_property(:intended_children_count).with_predicate('http://ams2.wgbh-mla.org/resource#intendedChildrenCount') }
it { is_expected.to have_property(:validation_status_for_aapb).with_predicate('http://ams2.wgbh-mla.org/resource#validationStatusForAapb') }
end

context "with AdminData" do
Expand Down
18 changes: 17 additions & 1 deletion spec/models/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:asset_ids) { assets.map(&:id) }
let(:invalid_ids) { [ 'cpb-aacip-11111111111', 'blerg'] }
let(:pushed_ids) { [] } # overwrite in contexts below
let(:error_messages) { subject.errors[:pushed_id_csv].join("\n") }

subject { build(:push, pushed_id_csv: pushed_ids.join(',')) }

Expand All @@ -18,7 +19,6 @@

context 'when some IDs do not exist in the repository' do
let(:pushed_ids) { asset_ids + invalid_ids }
let(:error_messages) { subject.errors[:pushed_id_csv].join("\n") }

before { subject.validate }

Expand All @@ -36,5 +36,21 @@
end
end
end

context 'when the IDs exists, but some are missing children' do
let(:asset_missing_children_1) { create(:asset, validation_status_for_aapb: [Asset::VALIDATION_STATUSES[:missing_children]]) }
let(:asset_missing_children_2) { create(:asset, validation_status_for_aapb: [Asset::VALIDATION_STATUSES[:missing_children]]) }
let(:pushed_ids) { [asset_missing_children_1.id, asset_missing_children_2.id] + asset_ids }

it { is_expected.to be_invalid }

it 'lists only the Asset IDs missing children in the error message' do
subject.valid?

expect(error_messages).to include('The following IDs are missing child record(s):')
expect(error_messages).to include(asset_missing_children_1.id, asset_missing_children_2.id)
expect(error_messages).not_to include(*asset_ids)
end
end
end
end
18 changes: 18 additions & 0 deletions spec/models/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,22 @@
end
end
end

describe '#intended_children_count' do
let(:asset) { create(:asset, :with_physical_digital_and_essence_track, intended_children_count: '3') }

it 'indexes as an Integer' do
expect(asset_solr_doc.intended_children_count).to eq(asset.intended_children_count.to_i)
end
end

describe '#validation_status_for_aapb' do
let(:asset) { create(:asset, :with_physical_digital_and_essence_track, validation_status_for_aapb: ['test']) }

it 'indexes the value as an Array' do
# Use #to_a since asset.validation_status_for_aapb is an ActiveTriples::Relation, which causes the
# test to fail when compared directly with asset_solr_doc.validation_status_for_aapb
expect(asset_solr_doc.validation_status_for_aapb).to eq(asset.validation_status_for_aapb.to_a)
end
end
end
12 changes: 8 additions & 4 deletions spec/parsers/pbcore_xml_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
describe '#create_works' do
subject(:xml_parser) { described_class.new(importer) }
let(:importer) { FactoryBot.create(:bulkrax_importer_pbcore_xml) }
let(:entry) { FactoryBot.create(:bulkrax_entry, importerexporter: importer) }

before do
Bulkrax.field_mappings['PbcoreXmlParser'] = {
'bulkrax_identifier' => { from: ['pbcoreIdentifier'], source_identifier: true }
}
allow(Bulkrax::PbcoreXmlEntry).to receive_message_chain(:where, :first_or_create!).and_return(entry)
allow(entry).to receive(:id)
allow(Bulkrax::ImportWorkJob).to receive(:perform_later)
end

Expand All @@ -39,7 +36,14 @@
expect(xml_parser.total).to eq(1)
expect(xml_parser.collections_total).to eq(0)
end

it 'counts the correct number of intended children' do
xml_parser.create_works

entry = importer.entries.find_by(identifier: 'Asset-cpb-aacip-20-000000hr-1')
expect(entry.raw_metadata['intended_children_count']).to eq(5)
end
end
end
end
end
end