Skip to content

Commit

Permalink
the other remove file tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwellnit committed Sep 11, 2024
1 parent e135141 commit 613ce34
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 30 deletions.
43 changes: 34 additions & 9 deletions spec/services/spot/derivatives/audio_derivatives_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,23 +333,48 @@

before do
allow(_file_set).to receive(:id).and_return("1234")
allow(File).to receive(:exist?).with('/tmp/derivative_1').and_return true

Check failure on line 336 in spec/services/spot/derivatives/audio_derivatives_service_spec.rb

View workflow job for this annotation

GitHub Actions / Lint + Test / Lint

Layout/TrailingWhitespace: Trailing whitespace detected.
allow(FileUtils).to receive(:rm_f).with('/tmp/derivative_1')
allow(mock_s3_client).to receive(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
allow(service).to receive(:transfer_s3_derivative).with('derivative_1', '1234-0-access.mp3')
service.rename_premade_derivative(derivative, index)
end

it 'should download the file from s3' do
expect(mock_s3_client).to have_received(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
end
context 'the file exists' do
before do
allow(File).to receive(:exist?).with('/tmp/derivative_1').and_return true
service.rename_premade_derivative(derivative, index)
end

it 'should download the file from s3' do
expect(mock_s3_client).to have_received(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
end

it 'should remove the temporary file' do
expect(FileUtils).to have_received(:rm_f).with('/tmp/derivative_1')
end

it 'should remove the temporary file' do
expect(FileUtils).to have_received(:rm_f).with('/tmp/derivative_1')
it 'should call to transfer the premade derivative' do
expect(service).to have_received(:transfer_s3_derivative).with('derivative_1', '1234-0-access.mp3')
end
end

it 'should call to transfer the premade derivative' do
expect(service).to have_received(:transfer_s3_derivative).with('derivative_1', '1234-0-access.mp3')
context 'the file does not exist' do
before do
allow(File).to receive(:exist?).with('/tmp/derivative_1').and_return false
service.rename_premade_derivative(derivative, index)
end

it 'should download the file from s3' do
expect(mock_s3_client).to have_received(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
end

it 'should not remove the temporary file' do
expect(FileUtils).to_not receive(:rm_f).with('/tmp/derivative_1')
end

it 'should call to transfer the premade derivative' do
expect(service).to have_received(:transfer_s3_derivative).with('derivative_1', '1234-0-access.mp3')
end
end
end

Expand Down
93 changes: 72 additions & 21 deletions spec/services/spot/derivatives/video_derivatives_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,24 +379,48 @@

before do
allow(_file_set).to receive(:id).and_return("1234")
allow(File).to receive(:exist?).with('/tmp/derivative_1').and_return true
allow(FileUtils).to receive(:rm_f).with('/tmp/derivative_1')
allow(mock_s3_client).to receive(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
allow(service).to receive(:get_video_resolution).with('/tmp/derivative_1').and_return [100, 200]
allow(service).to receive(:transfer_s3_derivative).with('derivative_1', '1234-0-access-200.mp4')
service.rename_premade_derivative(derivative, index)
end

it 'should download the file from s3' do
expect(mock_s3_client).to have_received(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
end
context 'the file exists' do
before do
allow(File).to receive(:exist?).with('/tmp/derivative_1').and_return true
service.rename_premade_derivative(derivative, index)
end

it 'should download the file from s3' do
expect(mock_s3_client).to have_received(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
end

it 'should remove the temporary file' do
expect(FileUtils).to have_received(:rm_f).with('/tmp/derivative_1')
end

it 'should remove the temporary file' do
expect(FileUtils).to have_received(:rm_f).with('/tmp/derivative_1')
it 'should call to transfer the premade derivative' do
expect(service).to have_received(:transfer_s3_derivative).with('derivative_1', '1234-0-access-200.mp4')
end
end

it 'should call to transfer the premade derivative' do
expect(service).to have_received(:transfer_s3_derivative).with('derivative_1', '1234-0-access-200.mp4')
context 'the file does not exist' do
before do
allow(File).to receive(:exist?).with('/tmp/derivative_1').and_return false
service.rename_premade_derivative(derivative, index)
end

it 'should download the file from s3' do
expect(mock_s3_client).to have_received(:get_object).with(key: derivative, bucket: aws_import_bucket, response_target: '/tmp/derivative_1')
end

it 'should remove the temporary file' do
expect(FileUtils).to_not receive(:rm_f).with('/tmp/derivative_1')
end

it 'should call to transfer the premade derivative' do
expect(service).to have_received(:transfer_s3_derivative).with('derivative_1', '1234-0-access-200.mp4')
end
end
end

Expand All @@ -418,32 +442,59 @@
end
end

context 'check_premade_derivatives returns true' do
context 'check_premade_derivatives returns false' do
before do
allow(service).to receive(:check_premade_derivatives).and_return(false)
allow(service).to receive(:get_derivative_resolution).with(filename, 1080).and_return('544x1080')
allow(service).to receive(:get_derivative_resolution).with(filename, 480).and_return('240x480')
allow(Hydra::Derivatives::VideoDerivatives).to receive(:create).with(filename, outputs: [output_high, output_low])
allow(_file_set).to receive(:id).and_return("1234")
allow(service).to receive(:upload_derivatives_to_s3).with(['1234-0-access-1080.mp4', '1234-1-access-480.mp4'], [derivative_path_high, derivative_path_low])
allow(File).to receive(:exist?).with(derivative_path_high).and_return true
allow(FileUtils).to receive(:rm_f).with(derivative_path_high)
allow(File).to receive(:exist?).with(derivative_path_low).and_return true
allow(FileUtils).to receive(:rm_f).with(derivative_path_low)
service.create_derivatives(filename)
end

it 'creates derivative files' do
expect(Hydra::Derivatives::VideoDerivatives).to have_received(:create).with(filename, outputs: [output_high, output_low])
end
context 'the files exist' do
before do
allow(File).to receive(:exist?).with(derivative_path_high).and_return true
allow(File).to receive(:exist?).with(derivative_path_low).and_return true
service.create_derivatives(filename)
end

it 'creates derivative files' do
expect(Hydra::Derivatives::VideoDerivatives).to have_received(:create).with(filename, outputs: [output_high, output_low])
end

it 'uploads derivatives to s3' do
expect(service).to have_received(:upload_derivatives_to_s3).with(['1234-0-access-1080.mp4', '1234-1-access-480.mp4'], [derivative_path_high, derivative_path_low])
end

it 'uploads derivatives to s3' do
expect(service).to have_received(:upload_derivatives_to_s3).with(['1234-0-access-1080.mp4', '1234-1-access-480.mp4'], [derivative_path_high, derivative_path_low])
it 'removes temporary files' do
[derivative_path_high, derivative_path_low].each do |path|
expect(FileUtils).to have_received(:rm_f).with(path)
end
end
end

it 'removes temporary files' do
[derivative_path_high, derivative_path_low].each do |path|
expect(FileUtils).to have_received(:rm_f).with(path)
context 'the files do not exist' do
before do
allow(File).to receive(:exist?).with(derivative_path_high).and_return false
allow(File).to receive(:exist?).with(derivative_path_low).and_return false
service.create_derivatives(filename)
end

it 'creates derivative files' do
expect(Hydra::Derivatives::VideoDerivatives).to have_received(:create).with(filename, outputs: [output_high, output_low])
end

it 'uploads derivatives to s3' do
expect(service).to have_received(:upload_derivatives_to_s3).with(['1234-0-access-1080.mp4', '1234-1-access-480.mp4'], [derivative_path_high, derivative_path_low])
end

it 'does not remove temporary files' do
[derivative_path_high, derivative_path_low].each do |path|
expect(FileUtils).to_not receive(:rm_f).with(path)
end
end
end
end
Expand Down

0 comments on commit 613ce34

Please sign in to comment.