Skip to content

Commit

Permalink
LGY Document Uploader (#9257)
Browse files Browse the repository at this point in the history
* adding doc upload

* standalone doc uploader

* adding specs

* updating specs
  • Loading branch information
kathleencrawford authored Mar 7, 2022
1 parent c4ae750 commit 086ce89
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
28 changes: 28 additions & 0 deletions app/controllers/v0/coe_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ def documents
render json: { data: { attributes: documents.body } }, status: :ok
end

def document_upload
load_user

attachments.each do |attachment|
file_extension = attachment['file_type']

if %w[jpg jpeg png pdf].include? file_extension.downcase
file_data = attachment['file']
index = file_data.index(';base64,') || 0
file_data = file_data[index + 8..] if index.positive?

document_data = {
'documentType' => file_extension,
'description' => attachment['document_type'],
'contentsBase64' => file_data,
'fileName' => attachment['file_name']
}

response = lgy_service.post_document(payload: document_data)
render(json: response.status)
end
end
end

private

def lgy_service
Expand All @@ -46,6 +70,10 @@ def filtered_params
params.require(:lgy_coe_claim).permit(:form)
end

def attachments
params[:files]
end

def stats_key
'api.lgy_coe'
end
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,9 @@
namespace :coe do
get 'status'
get 'download_coe'
post 'submit_coe_claim'
get 'documents'
post 'submit_coe_claim'
post 'document_upload'
end
end

Expand Down
20 changes: 20 additions & 0 deletions spec/requests/v0/lgy_coe_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,25 @@
end
end
end

describe 'POST v0/coe/document_upload' do
context 'when uploading attachments' do
it 'uploads the file successfully' do
VCR.use_cassette 'lgy/document_upload' do
attachments = {
'files' => [{
'file' => Base64.encode64(File.read('spec/fixtures/files/lgy_file.pdf')),
'document_type' => 'VA home loan documents',
'file_type' => 'pdf',
'file_name' => 'lgy_file.pdf'
}]
}

post('/v0/coe/document_upload', params: attachments)
expect(response.status).to eq 200
end
end
end
end
end
end
Loading

0 comments on commit 086ce89

Please sign in to comment.