Skip to content

Commit

Permalink
WIP: specs, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
fcd1 committed Dec 3, 2024
1 parent ea103cf commit ab54cce
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ group :development, :test do

# simplecov for test coverage
gem 'simplecov', '~> 0.22', require: false

gem 'factory_bot_rails'
end

group :development do
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ GEM
drb (2.2.1)
erubi (1.13.0)
execjs (2.9.1)
factory_bot (6.5.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.4)
factory_bot (~> 6.5)
railties (>= 5.0.0)
ffi (1.16.3)
globalid (1.2.1)
activesupport (>= 6.1)
Expand Down Expand Up @@ -372,6 +377,7 @@ DEPENDENCIES
capistrano-rvm (~> 0.1)
coffee-rails (~> 4.2)
devise
factory_bot_rails
jquery-rails
listen
mysql2
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/deposits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ def resubmit
resubmit_deposit.ingest_confirmed = endpoint.confirm_ingest
resubmit_deposit.content_path = path_to_deposit_contents
resubmit_deposit.save
response.status = 201
render json: { item_pid: endpoint.adapter_item_identifier,
ingest_into_hyacinth: !(HYACINTH_CONFIG[:bypass_ingest] or COLLECTIONS[:slug][endpoint.collection_slug][:bypass_hyacinth_ingest])}
end

private
Expand Down
23 changes: 23 additions & 0 deletions spec/controllers/deposits_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,27 @@
expect(endpoint).to be_a(Sword::Endpoints::ProquestEndpoint)
end
end

describe 'resubmit' do
before(:example) do
the_endpoint = double("the_endpoint")
allow(the_endpoint).to receive(:deposit_title) { "This is the title" }
allow(the_endpoint).to receive(:handle_deposit) {['a.txt', 'b.txt'] }
allow(the_endpoint).to receive(:documents_to_deposit) {['a.txt', 'b.txt'] }
allow(the_endpoint).to receive(:adapter_item_identifier) { 'ac:12345678' }
allow(the_endpoint).to receive(:asset_pids) { ['ac:10000000', 'ac:987654321'] }
allow(the_endpoint).to receive(:confirm_ingest) { true }
allow(controller).to receive(:get_endpoint) { the_endpoint }
allow_any_instance_of(Sword::Endpoints::ProquestEndpoint).to receive(:handle_deposit).and_return(the_endpoint)
end

it 'creates new Deposit after re-ingest into Hyacinth' do
deposit = create(:deposit)
id = deposit.id
allow(controller).to receive(:params).and_return( { id: 1 } )
expect(Deposit.count).to eq(1)
subject.resubmit
expect(Deposit.count).to eq(2)
end
end
end
8 changes: 8 additions & 0 deletions spec/factories/deposit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryBot.define do
factory :deposit do
title { "This is a factory title" }
item_in_hyacinth { "ac:123456789" }
collection_slug { "test-pq" }
depositor_user_id { "depositor_user_id" }
end
end
2 changes: 2 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")

config.include FactoryBot::Syntax::Methods
end
20 changes: 20 additions & 0 deletions spec/sword/adapters/hyacinth_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,24 @@
end
end
end

describe 'expected_and_retrieved_asset_pids_match?' do
before(:example) do
http_success = double("http_success")
allow(http_success).to receive(:is_a?) { true }
allow(http_success).to receive(:body) { JSON.generate({'ordered_child_digital_objects' => [ { 'pid' => 'ac:12344321'} ] } ) }
allow_any_instance_of(Net::HTTP).to receive(:start).and_return(http_success)
end
it "returns true if pids match" do
subject.instance_variable_set(:@asset_pids, ['ac:12344321'])
res = subject.expected_and_retrieved_asset_pids_match?
expect(res).to be(true)
end

it "returns false if pids don't match" do
subject.instance_variable_set(:@asset_pids, ['ac:123456789'])
res = subject.expected_and_retrieved_asset_pids_match?
expect(res).to be(false)
end
end
end
19 changes: 19 additions & 0 deletions spec/sword/endpoints/mets_to_hyacinth_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,23 @@
# add check here about calling @mets_parser.parse
end
end

describe 'confirm_ingest' do
before(:example) do
@mets_endpoint = Sword::Endpoints::MetsToHyacinthEndpoint.new('sample_collection_slug',
'sample_depositor_user_id')
@hyacinth_adapter = double("hyacinth_adapter")
@mets_endpoint.instance_variable_set(:@hyacinth_adapter, @hyacinth_adapter)
end

it 'returns false if expected_and_retrieved_asset_pids_match? returns false' do
allow(@hyacinth_adapter).to receive(:expected_and_retrieved_asset_pids_match?) { false }
expect(@mets_endpoint.confirm_ingest).to be(false)
end

it 'returns true if expected_and_retrieved_asset_pids_match? return true' do
allow(@hyacinth_adapter).to receive(:expected_and_retrieved_asset_pids_match?) { true }
expect(@mets_endpoint.confirm_ingest).to be(true)
end
end
end

0 comments on commit ab54cce

Please sign in to comment.