-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
521 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
81
modules/claims_api/spec/lib/claims_api/vnp_atchms_service_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
135 changes: 135 additions & 0 deletions
135
spec/support/vcr_cassettes/bgs/vnp_atchms_service/vnp_atchms_create/happy_path_base64.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.