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

spec/lib/dor/text_extraction/file_fetcher_spec.rb: consider mocking HTTP request to pres cat, instead of preservation-client content retrieval method #1379

Open
jmartin-sul opened this issue Oct 1, 2024 · 0 comments

Comments

@jmartin-sul
Copy link
Member

Can we mock the GET request that's ultimately being made in this test:

before do
allow(objects_client).to receive(:content) do |*args|
filepath = args.first.fetch(:filepath)
args.first.fetch(:on_data).call("Content for: #{filepath}")
end
end
it 'writes the file' do
file_fetcher.write_file_with_retries(filename:, location:)
expect(Preservation::Client).to have_received(:configure)
expect(logger).to have_received(:info).once
expect(objects_client).to have_received(:content).once # success first time!
expect(File.read(file_path)).to eq("Content for: #{filename}")
end

so that content and the on_data stuff could get exercised a slightly more natural/integration-y manner? Seems in principle like it should be straight-forward, so maybe worth 30-ish minutes of experimentation?

follow on from PR review: https://github.com/sul-dlss/common-accessioning/pull/1349/files/21fc07f6f19c9b5a7bfc3669f4d7522891b1db5e#diff-c0ea167b0c3e814c9391cef8720e8ee89460221bee8afdeb4b407e3506f8512b (wanted to get this merged and timebox this (possible) touchup)

(i originally suggested this because i was at first stumped at how the test can know on_data will get called exactly once, then realized it's because the pres client content method gets mocked by the current test, not that the mocking is terribly unrealistic, hence the suggestion to timebox and give up if difficult)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant