Skip to content

Commit

Permalink
Api 34939 vnp atchms create (#16271)
Browse files Browse the repository at this point in the history
* 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
acovrig and nihil2501 authored Apr 10, 2024
1 parent 7b520a8 commit 72ee8db
Show file tree
Hide file tree
Showing 5 changed files with 524 additions and 0 deletions.
34 changes: 34 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,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 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,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

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

Loading

0 comments on commit 72ee8db

Please sign in to comment.