Skip to content

Commit

Permalink
Add service call
Browse files Browse the repository at this point in the history
  • Loading branch information
acovrig committed Apr 8, 2024
1 parent 25e1f3b commit a6bc15d
Show file tree
Hide file tree
Showing 5 changed files with 521 additions and 0 deletions.
33 changes: 33 additions & 0 deletions modules/claims_api/lib/bgs_service/vnp_atchms_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module ClaimsApi
class VnpAtchmsService < ClaimsApi::LocalBGS
# Takes an object with a minimum of (other fields are camelized and passed to BGS):
# vnp_proc_id: BGS procID
# atchms_file_nm: File name
# atchms_descp: File description
# atchms_txt: Base64 encoded file or file path
def vnp_atchms_create(opts)
validate_opts! opts, %w[vnp_proc_id atchms_file_nm atchms_descp atchms_txt]

convert_file! opts
opts = jrn.merge(opts)
arg_strg = convert_nil_values(opts)
body = Nokogiri::XML::DocumentFragment.parse "<arg0>#{arg_strg}</arg0>"
make_request(endpoint: 'VnpAtchmsWebServiceBean/VnpAtchmsService', action: 'vnpAtchmsCreate', body:,
key: 'return')
end

private

def convert_file!(opts)
txt = opts.deep_symbolize_keys[:atchms_txt]
raise ArgumentError, 'File must be a string' unless txt.is_a? String

if File.exist?(txt)
file = File.read(txt)
opts['atchms_txt'] = Base64.encode64 file
end
end
end
end
81 changes: 81 additions & 0 deletions modules/claims_api/spec/lib/claims_api/vnp_atchms_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

require 'rails_helper'
require 'bgs_service/vnp_atchms_service'
require Rails.root.join('modules', 'claims_api', 'spec', 'support', 'bgs_client_helpers.rb')

metadata = {
bgs: {
service: 'vnp_atchms_service',
operation: 'vnp_atchms_create'
}
}

describe ClaimsApi::VnpAtchmsService, metadata do
describe '#vnp_atchms_create' do
subject { described_class.new external_uid: 'xUid', external_key: 'xKey' }

# get a proc_id from vnp_proc_create
let(:vnp_proc_id) { '3854593' }
let(:expected_response) do
{ vnp_proc_id:,
atchms_file_nm: 'test.pdf',
atchms_descp: 'test' }
end

describe 'vnp_atchms_create' do
it 'validates data' do
data = { asdf: 'qwerty' }
expect { subject.vnp_atchms_create(data) }.to(raise_error do |error|
expect(error).to be_a(ArgumentError)
expect(error.message).to eq('Missing required keys: vnp_proc_id, atchms_file_nm, atchms_descp, atchms_txt')
end)
end

describe 'valid data with base64', run_at: '2024-04-01T18:48:27Z' do
it 'creates a attachment from data' do
data = {
vnp_proc_id:,
atchms_file_nm: 'test.pdf',
atchms_descp: 'test',
atchms_txt: 'base64here'
}
use_bgs_cassette('happy_path_base64') do
result = subject.vnp_atchms_create(data)
expect((expected_response.to_a & result.to_a).to_h).to eq expected_response
end
end
end

describe 'valid data with a path', run_at: '2024-04-01T18:48:27Z' do
it 'creates a attachment from data' do
data = {
vnp_proc_id:,
atchms_file_nm: 'test.pdf',
atchms_descp: 'test',
atchms_txt: Rails.root.join('modules', 'claims_api', 'spec', 'fixtures', 'extras.pdf').to_s
}
use_bgs_cassette('happy_path_file') do
result = subject.vnp_atchms_create(data)
expect((expected_response.to_a & result.to_a).to_h).to eq expected_response
end
end
end

describe 'invalid procId', run_at: '2024-04-01T18:48:27Z' do
it 'raises an error', run_at: '2024-04-01T18:48:27Z' do
data = {
vnp_proc_id: '1234abc',
atchms_file_nm: 'test.pdf',
atchms_descp: 'test',
atchms_txt: 'base64here'
}

use_bgs_cassette('invalid_procId') do
expect { subject.vnp_atchms_create(data) }.to raise_error(Common::Exceptions::ServiceError)
end
end
end
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6bc15d

Please sign in to comment.