-
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.
Api 34939 vnp atchms create (#16271)
* Add basic personCreate * Beginning of vnp_person_create refactor * Refactor spec describe/context/it * Move cassettes --------- Co-authored-by: Oren Mittman <[email protected]>
- Loading branch information
Showing
5 changed files
with
524 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,34 @@ | ||
# 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) | ||
opts.deep_symbolize_keys! | ||
txt = opts[: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 |
85 changes: 85 additions & 0 deletions
85
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,85 @@ | ||
# 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', run_at: '2024-04-01T18:48:27Z' do | ||
subject { described_class.new external_uid: 'xUid', external_key: 'xKey' } | ||
|
||
describe 'validation' do | ||
# 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 | ||
|
||
context 'when missing required params' do | ||
it 'raises an error' 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 | ||
end | ||
|
||
describe 'when submitting valid data' do | ||
context 'with a base64 string' 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 | ||
|
||
context 'with a file path' 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 | ||
end | ||
|
||
context 'when providing an invalid procId' do | ||
it 'raises an error' 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
...t/vcr_cassettes/claims_api/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.