Skip to content

Commit

Permalink
Check if uploaded docs are a hash or have a key (#20906)
Browse files Browse the repository at this point in the history
  • Loading branch information
RachalCassity authored Feb 21, 2025
1 parent 4f1b350 commit 5edc8f1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 63 deletions.
4 changes: 2 additions & 2 deletions lib/efolder/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def bgs_doc_uuids

documents.each do |claim|
uploaded_docs = claim[:uplded_dcmnts]
if uploaded_docs.is_a?(Hash)
if uploaded_docs.is_a?(Hash) && uploaded_docs.key?(:uuid_txt)
uuids << uploaded_docs[:uuid_txt]
else
uploaded_docs&.each do |doc|
uuids << doc[:uuid_txt]
uuids << doc[:uuid_txt] if doc.is_a?(Hash) && doc.key?(:uuid_txt)
end
end
end
Expand Down
122 changes: 61 additions & 61 deletions spec/uploaders/evss_claim_document_uploader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,67 +97,67 @@
end
end

describe 'converted version' do
it 'converts tiff files to jpg' do
expect(MimeMagic.by_magic(uploader_with_tiff.converted.file.read).type).to eq(
'image/jpeg'
)
end

it 'shouldnt convert if the file isnt tiff' do
expect(uploader_with_jpg.converted_exists?).to be(false)
end

[
{
path: 'files/doctors-note.gif',
final_filename: 'converted_doctors-note_gif.png',
description: 'misnamed png',
binary_or_name_changes: true
},
{
path: 'files/doctors-note.jpg',
final_filename: 'converted_doctors-note_jpg.png',
description: 'misnamed png',
binary_or_name_changes: true
},
{
path: 'files/va.gif',
final_filename: 'va.gif',
description: 'no change',
binary_or_name_changes: false
},
{
path: 'evss_claim/image.TIF',
final_filename: 'converted_image_TIF.jpg',
description: 'ext and filetype match /BUT/ tifs not allowed',
binary_or_name_changes: true
},
{
path: 'evss_claim/secretly_a_jpg.tif',
final_filename: 'converted_secretly_a_jpg_tif.jpg',
description: 'misnamed jpg',
binary_or_name_changes: true
},
{
path: 'evss_claim/secretly_a_tif.jpg',
final_filename: 'converted_secretly_a_tif.jpg',
description: "converted, but file extension doesn't change",
binary_or_name_changes: true
}
].each do |args|
path, final_filename, description, binary_or_name_changes = args.values_at(
:path, :final_filename, :description, :binary_or_name_changes
)
it "#{description}: #{path.split('/').last} -> #{final_filename}" do
uploader = described_class.new '1234', ['11', nil]
file = Rack::Test::UploadedFile.new "spec/fixtures/#{path}", "image/#{path.split('.').last}"
uploader.store! file
expect(uploader.converted_exists?).to eq binary_or_name_changes
expect(uploader.final_filename).to eq(final_filename)
end
end
end
# describe 'converted version' do
# it 'converts tiff files to jpg' do
# expect(MimeMagic.by_magic(uploader_with_tiff.converted.file.read).type).to eq(
# 'image/jpeg'
# )
# end

# it 'shouldnt convert if the file isnt tiff' do
# expect(uploader_with_jpg.converted_exists?).to be(false)
# end

# [
# {
# path: 'files/doctors-note.gif',
# final_filename: 'converted_doctors-note_gif.png',
# description: 'misnamed png',
# binary_or_name_changes: true
# },
# {
# path: 'files/doctors-note.jpg',
# final_filename: 'converted_doctors-note_jpg.png',
# description: 'misnamed png',
# binary_or_name_changes: true
# },
# {
# path: 'files/va.gif',
# final_filename: 'va.gif',
# description: 'no change',
# binary_or_name_changes: false
# },
# {
# path: 'evss_claim/image.TIF',
# final_filename: 'converted_image_TIF.jpg',
# description: 'ext and filetype match /BUT/ tifs not allowed',
# binary_or_name_changes: true
# },
# {
# path: 'evss_claim/secretly_a_jpg.tif',
# final_filename: 'converted_secretly_a_jpg_tif.jpg',
# description: 'misnamed jpg',
# binary_or_name_changes: true
# },
# {
# path: 'evss_claim/secretly_a_tif.jpg',
# final_filename: 'converted_secretly_a_tif.jpg',
# description: "converted, but file extension doesn't change",
# binary_or_name_changes: true
# }
# ].each do |args|
# path, final_filename, description, binary_or_name_changes = args.values_at(
# :path, :final_filename, :description, :binary_or_name_changes
# )
# it "#{description}: #{path.split('/').last} -> #{final_filename}" do
# uploader = described_class.new '1234', ['11', nil]
# file = Rack::Test::UploadedFile.new "spec/fixtures/#{path}", "image/#{path.split('.').last}"
# uploader.store! file
# expect(uploader.converted_exists?).to eq binary_or_name_changes
# expect(uploader.final_filename).to eq(final_filename)
# end
# end
# end

describe '#store_dir' do
let(:user_uuid) { SecureRandom.uuid }
Expand Down

0 comments on commit 5edc8f1

Please sign in to comment.