Skip to content

Commit

Permalink
Change how we represent UK addresses to BIS
Browse files Browse the repository at this point in the history
Before this PR, if the veteran provided an `international_postal_code` (i.e. GBR), we used an `IsoCountryCodes` class to automatically expand that to "United Kingdom of Great Britain and Northern Ireland", which exceeds BIS's 50 character limit for countries by two characters.  No other country exceeds the 50 character limt.  BIS told me that they use "United Kingdom" for the UK.  This PR adds in that exception, along with some minor refactoring.
  • Loading branch information
data-doge committed Jun 7, 2023
1 parent b3d79f4 commit bb8e62a
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 12 deletions.
36 changes: 24 additions & 12 deletions app/models/bgs_dependents/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,16 @@ def generate_address(address)
address['military_post_office_type_code'] = address.delete('city')
end

if address['veteran_address']
vet_address = address['veteran_address']
adjust_address_lines(vet_address)
end

adjust_address_lines(address)
adjust_address_lines_for!(address: address['veteran_address']) if address['veteran_address']

if address['international_postal_code'].present?
country = address['country_name']
address['country_name'] = IsoCountryCodes.find(country).name if country.present? && country.size == 3
end
adjust_address_lines_for!(address:)
adjust_country_name_for!(address:)

address
end

# BGS will not accept address lines longer than 20 characters
def adjust_address_lines(address)
# BGS will not accept address lines longer than 20 characters
def adjust_address_lines_for!(address:)
all_lines = "#{address['address_line1']} #{address['address_line2']} #{address['address_line3']}"
new_lines = all_lines.gsub(/\s+/, ' ').scan(/.{1,19}(?: |$)/).map(&:strip)

Expand All @@ -121,6 +114,25 @@ def adjust_address_lines(address)
address['address_line3'] = new_lines[2]
end

# This method converts ISO 3166-1 Alpha-3 country codes to ISO 3166-1 country names.
def adjust_country_name_for!(address:)
return if address['international_postal_code'].blank?

country_name = address['country_name']
return if country_name.blank? || country_name.size != 3

# The ISO 3166-1 country name for GBR exceeds BIS's (formerly, BGS) 50 char limit. No other country name exceeds
# this limit. For GBR, BIS expects "United Kingdom" instead. BIS has suggested using one of their web services
# to get the correct country names, rather than relying on the IsoCountryCodes gem below. It may be worth
# pursuing that some day. Until then, the following short-term improvement suffices.
address['country_name'] =
if country_name.to_s == 'GBR'
'United Kingdom'
else
IsoCountryCodes.find(country_name).name
end
end

def create_address_params(proc_id, participant_id, payload)
address = generate_address(payload)

Expand Down
54 changes: 54 additions & 0 deletions spec/lib/bgs/vnp_veteran_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,59 @@
end
end
end

context 'veteran has UK address' do
it "uses 'United Kingdom' for the country name instead of the full ISO 3166-1 name" do
# rubocop:disable Layout/LineLength
all_flows_payload['dependents_application']['veteran_contact_information']['veteran_address']['country_name'] = 'GBR'
all_flows_payload['veteran_contact_information']['veteran_address']['country_name'] = 'GBR'
all_flows_payload['dependents_application']['veteran_contact_information']['veteran_address']['city'] = 'APO'
all_flows_payload['veteran_contact_information']['veteran_address']['city'] = 'APO'
all_flows_payload['dependents_application']['veteran_contact_information']['veteran_address']['international_postal_code'] = '67400'
all_flows_payload['veteran_contact_information']['veteran_address']['international_postal_code'] = '67400'
# rubocop:enable Layout/LineLength

expected_address = { cntry_nm: 'United Kingdom' }

VCR.use_cassette('bgs/vnp_veteran/create') do
expect_any_instance_of(BGS::Service).to receive(:create_address)
.with(a_hash_including(expected_address))
.and_call_original
BGS::VnpVeteran.new(
proc_id: '12345',
payload: all_flows_payload,
user: user_object,
claim_type: '130DPNEBNADJ'
).create
end
end
end

context "veteran has APO address that isn't in the UK" do
it 'uses IsoCountryCodes to determine the country name' do
# rubocop:disable Layout/LineLength
all_flows_payload['dependents_application']['veteran_contact_information']['veteran_address']['country_name'] = 'ATA'
all_flows_payload['veteran_contact_information']['veteran_address']['country_name'] = 'ATA'
all_flows_payload['dependents_application']['veteran_contact_information']['veteran_address']['city'] = 'APO'
all_flows_payload['veteran_contact_information']['veteran_address']['city'] = 'APO'
all_flows_payload['dependents_application']['veteran_contact_information']['veteran_address']['international_postal_code'] = '67400'
all_flows_payload['veteran_contact_information']['veteran_address']['international_postal_code'] = '67400'
# rubocop:enable Layout/LineLength

expected_address = { cntry_nm: 'Antarctica' }

VCR.use_cassette('bgs/vnp_veteran/create') do
expect_any_instance_of(BGS::Service).to receive(:create_address)
.with(a_hash_including(expected_address))
.and_call_original
BGS::VnpVeteran.new(
proc_id: '12345',
payload: all_flows_payload,
user: user_object,
claim_type: '130DPNEBNADJ'
).create
end
end
end
end
end
114 changes: 114 additions & 0 deletions spec/support/vcr_cassettes/bgs/vnp_veteran/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,120 @@ http_interactions:
xmlns:ns0="http://ptcpntAddrsService.services.vonapp.vba.va.gov/"><return><vnpPtcpntAddrsId>117658</vnpPtcpntAddrsId><efctvDt>2020-09-21T20:57:44Z</efctvDt><vnpPtcpntId>151031</vnpPtcpntId><vnpProcId>12345</vnpProcId><addrsOneTxt>8200
Doby LN</addrsOneTxt><cityNm>Pasadena</cityNm><cntryNm>USA</cntryNm><emailAddrsTxt>foo@foo.com</emailAddrsTxt><jrnDt>2020-09-21T20:57:44Z</jrnDt><jrnLctnId>281</jrnLctnId><jrnObjId>VAgovAPI</jrnObjId><jrnStatusTypeCd>U</jrnStatusTypeCd><jrnUserId>VAgovAPI</jrnUserId><postalCd>CA</postalCd><prvncNm>CA</prvncNm><ptcpntAddrsTypeNm>Mailing</ptcpntAddrsTypeNm><sharedAddrsInd>N</sharedAddrsInd><zipPrefixNbr>21122</zipPrefixNbr></return></ns0:vnpPtcpntAddrsCreateResponse></S:Body></S:Envelope>
recorded_at: Mon, 21 Sep 2020 20:57:45 GMT
- request:
method: post
uri: https://internal-dsva-vagov-dev-fwdproxy-1893365470.us-gov-west-1.elb.amazonaws.com:4447/VnpPtcpntAddrsWebServiceBean/VnpPtcpntAddrsService
body:
encoding: UTF-8
string: |-
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://ptcpntAddrsService.services.vonapp.vba.va.gov/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>VAgovAPI</wsse:Username>
</wsse:UsernameToken>
<vaws:VaServiceHeaders xmlns:vaws="http://vbawebservices.vba.va.gov/vawss">
<vaws:CLIENT_MACHINE>192.168.0.95</vaws:CLIENT_MACHINE>
<vaws:STN_ID>281</vaws:STN_ID>
<vaws:applicationName>VAgovAPI</vaws:applicationName>
<vaws:ExternalUid>62312614648539760</vaws:ExternalUid>
<vaws:ExternalKey>abraham.lincoln@vets.gov</vaws:ExternalKey>
</vaws:VaServiceHeaders>
</wsse:Security>
</env:Header><env:Body><tns:vnpPtcpntAddrsCreate><arg0><efctvDt>2020-09-21T20:57:44Z</efctvDt><vnpPtcpntId>151031</vnpPtcpntId><vnpProcId>12345</vnpProcId><ptcpntAddrsTypeNm>Mailing</ptcpntAddrsTypeNm><sharedAddrsInd>N</sharedAddrsInd><addrsOneTxt>8200 Doby LN</addrsOneTxt><addrsTwoTxt xsi:nil="true"/><addrsThreeTxt xsi:nil="true"/><cityNm>APO</cityNm><cntryNm>GBR</cntryNm><postalCd>CA</postalCd><mltyPostalTypeCd xsi:nil="true"/><mltyPostOfficeTypeCd xsi:nil="true"/><zipPrefixNbr>21122</zipPrefixNbr><prvncNm>CA</prvncNm><emailAddrsTxt>foo@foo.com</emailAddrsTxt><jrnDt>2020-09-21T20:57:44Z</jrnDt><jrnLctnId>281</jrnLctnId><jrnStatusTypeCd>U</jrnStatusTypeCd><jrnUserId>VAgovAPI</jrnUserId><jrnObjId>VAgovAPI</jrnObjId></arg0></tns:vnpPtcpntAddrsCreate></env:Body></env:Envelope>
headers:
Host:
- ".vba.va.gov"
Soapaction:
- '"vnpPtcpntAddrsCreate"'
Content-Type:
- text/xml;charset=UTF-8
Content-Length:
- '1675'
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept:
- "*/*"
User-Agent:
- Ruby
response:
status:
code: 200
message: OK
headers:
Date:
- Mon, 21 Sep 2020 20:57:45 GMT
Server:
- Apache
X-Frame-Options:
- SAMEORIGIN
Transfer-Encoding:
- chunked
Content-Type:
- text/xml; charset=utf-8
body:
encoding: UTF-8
string: <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><work:WorkContext
xmlns:work="http://oracle.com/weblogic/soap/workarea/">rO0ABXdKABR3ZWJsb2dpYy5hcHAudm5wLWVhcgAAANYAAAAjd2VibG9naWMud29ya2FyZWEuU3RyaW5nV29ya0NvbnRleHQABTIuMC44AAA=</work:WorkContext></env:Header><S:Body><ns0:vnpPtcpntAddrsCreateResponse
xmlns:ns0="http://ptcpntAddrsService.services.vonapp.vba.va.gov/"><return><vnpPtcpntAddrsId>117658</vnpPtcpntAddrsId><efctvDt>2020-09-21T20:57:44Z</efctvDt><vnpPtcpntId>151031</vnpPtcpntId><vnpProcId>12345</vnpProcId><addrsOneTxt>8200
Doby LN</addrsOneTxt><cityNm>APO</cityNm><cntryNm>GBR</cntryNm><emailAddrsTxt>foo@foo.com</emailAddrsTxt><jrnDt>2020-09-21T20:57:44Z</jrnDt><jrnLctnId>281</jrnLctnId><jrnObjId>VAgovAPI</jrnObjId><jrnStatusTypeCd>U</jrnStatusTypeCd><jrnUserId>VAgovAPI</jrnUserId><postalCd>CA</postalCd><prvncNm>CA</prvncNm><ptcpntAddrsTypeNm>Mailing</ptcpntAddrsTypeNm><sharedAddrsInd>N</sharedAddrsInd><zipPrefixNbr>21122</zipPrefixNbr></return></ns0:vnpPtcpntAddrsCreateResponse></S:Body></S:Envelope>
recorded_at: Mon, 21 Sep 2020 20:57:45 GMT
- request:
method: post
uri: https://internal-dsva-vagov-dev-fwdproxy-1893365470.us-gov-west-1.elb.amazonaws.com:4447/VnpPtcpntAddrsWebServiceBean/VnpPtcpntAddrsService
body:
encoding: UTF-8
string: |-
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://ptcpntAddrsService.services.vonapp.vba.va.gov/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>VAgovAPI</wsse:Username>
</wsse:UsernameToken>
<vaws:VaServiceHeaders xmlns:vaws="http://vbawebservices.vba.va.gov/vawss">
<vaws:CLIENT_MACHINE>192.168.0.95</vaws:CLIENT_MACHINE>
<vaws:STN_ID>281</vaws:STN_ID>
<vaws:applicationName>VAgovAPI</vaws:applicationName>
<vaws:ExternalUid>62312614648539760</vaws:ExternalUid>
<vaws:ExternalKey>abraham.lincoln@vets.gov</vaws:ExternalKey>
</vaws:VaServiceHeaders>
</wsse:Security>
</env:Header><env:Body><tns:vnpPtcpntAddrsCreate><arg0><efctvDt>2020-09-21T20:57:44Z</efctvDt><vnpPtcpntId>151031</vnpPtcpntId><vnpProcId>12345</vnpProcId><ptcpntAddrsTypeNm>Mailing</ptcpntAddrsTypeNm><sharedAddrsInd>N</sharedAddrsInd><addrsOneTxt>8200 Doby LN</addrsOneTxt><addrsTwoTxt xsi:nil="true"/><addrsThreeTxt xsi:nil="true"/><cityNm>APO</cityNm><cntryNm>ATA</cntryNm><postalCd>CA</postalCd><mltyPostalTypeCd xsi:nil="true"/><mltyPostOfficeTypeCd xsi:nil="true"/><zipPrefixNbr>21122</zipPrefixNbr><prvncNm>CA</prvncNm><emailAddrsTxt>foo@foo.com</emailAddrsTxt><jrnDt>2020-09-21T20:57:44Z</jrnDt><jrnLctnId>281</jrnLctnId><jrnStatusTypeCd>U</jrnStatusTypeCd><jrnUserId>VAgovAPI</jrnUserId><jrnObjId>VAgovAPI</jrnObjId></arg0></tns:vnpPtcpntAddrsCreate></env:Body></env:Envelope>
headers:
Host:
- ".vba.va.gov"
Soapaction:
- '"vnpPtcpntAddrsCreate"'
Content-Type:
- text/xml;charset=UTF-8
Content-Length:
- '1675'
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept:
- "*/*"
User-Agent:
- Ruby
response:
status:
code: 200
message: OK
headers:
Date:
- Mon, 21 Sep 2020 20:57:45 GMT
Server:
- Apache
X-Frame-Options:
- SAMEORIGIN
Transfer-Encoding:
- chunked
Content-Type:
- text/xml; charset=utf-8
body:
encoding: UTF-8
string: <?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><env:Header><work:WorkContext
xmlns:work="http://oracle.com/weblogic/soap/workarea/">rO0ABXdKABR3ZWJsb2dpYy5hcHAudm5wLWVhcgAAANYAAAAjd2VibG9naWMud29ya2FyZWEuU3RyaW5nV29ya0NvbnRleHQABTIuMC44AAA=</work:WorkContext></env:Header><S:Body><ns0:vnpPtcpntAddrsCreateResponse
xmlns:ns0="http://ptcpntAddrsService.services.vonapp.vba.va.gov/"><return><vnpPtcpntAddrsId>117658</vnpPtcpntAddrsId><efctvDt>2020-09-21T20:57:44Z</efctvDt><vnpPtcpntId>151031</vnpPtcpntId><vnpProcId>12345</vnpProcId><addrsOneTxt>8200
Doby LN</addrsOneTxt><cityNm>APO</cityNm><cntryNm>ATA</cntryNm><emailAddrsTxt>foo@foo.com</emailAddrsTxt><jrnDt>2020-09-21T20:57:44Z</jrnDt><jrnLctnId>281</jrnLctnId><jrnObjId>VAgovAPI</jrnObjId><jrnStatusTypeCd>U</jrnStatusTypeCd><jrnUserId>VAgovAPI</jrnUserId><postalCd>CA</postalCd><prvncNm>CA</prvncNm><ptcpntAddrsTypeNm>Mailing</ptcpntAddrsTypeNm><sharedAddrsInd>N</sharedAddrsInd><zipPrefixNbr>21122</zipPrefixNbr></return></ns0:vnpPtcpntAddrsCreateResponse></S:Body></S:Envelope>
recorded_at: Mon, 21 Sep 2020 20:57:45 GMT
- request:
method: get
uri: https://internal-dsva-vagov-dev-fwdproxy-1893365470.us-gov-west-1.elb.amazonaws.com:4447/RORoutingServiceWS/RORoutingService?WSDL
Expand Down

0 comments on commit bb8e62a

Please sign in to comment.