@@ -2065,6 +2065,112 @@ def expect_prefilled(form_id)
20652065 expect ( dependents . first [ 'dateOfBirth' ] ) . to be_nil
20662066 end
20672067 end
2068+
2069+ context 'with address prefill' do
2070+ let ( :user ) { create ( :evss_user , :loa3 ) }
2071+ let ( :form_profile ) do
2072+ FormProfiles ::VA686c674v2 . new ( user :, form_id : '686C-674-V2' )
2073+ end
2074+ let ( :contact_info_service ) { instance_double ( VAProfileRedis ::V2 ::ContactInformation ) }
2075+ let ( :dependent_service ) { instance_double ( BGS ::DependentService ) }
2076+ let ( :email_double ) { instance_double ( VAProfile ::Models ::Email , email_address : 'test@example.com' ) }
2077+ let ( :home_phone_double ) { instance_double ( VAProfile ::Models ::Telephone , formatted_phone : '5035551234' ) }
2078+ let ( :mobile_phone_double ) { instance_double ( VAProfile ::Models ::Telephone , formatted_phone : '5035555678' ) }
2079+
2080+ before do
2081+ # Mock VAProfile contact info for both user and form profile usage
2082+ allow ( VAProfileRedis ::V2 ::ContactInformation ) . to receive ( :for_user ) . with ( user ) . and_return (
2083+ contact_info_service
2084+ )
2085+ allow ( contact_info_service ) . to receive_messages ( email : email_double , home_phone : home_phone_double ,
2086+ mobile_phone : mobile_phone_double )
2087+
2088+ # Mock dependent service to avoid BGS calls
2089+ allow ( BGS ::DependentService ) . to receive ( :new ) . with ( user ) . and_return ( dependent_service )
2090+ allow ( dependent_service ) . to receive ( :get_dependents ) . and_return ( { persons : [ ] } )
2091+
2092+ # Mock BID awards service
2093+ allow_any_instance_of ( BID ::Awards ::Service ) . to receive ( :get_awards_pension ) . and_return (
2094+ OpenStruct . new ( body : { 'awards_pension' => { 'is_in_receipt_of_pension' => false } } )
2095+ )
2096+ end
2097+
2098+ context 'with domestic address' do
2099+ let ( :domestic_address ) do
2100+ build ( :va_profile_address ,
2101+ :mailing ,
2102+ :domestic ,
2103+ address_line1 : '123 Main St' ,
2104+ address_line2 : 'Apt 4B' ,
2105+ address_line3 : 'Building C' ,
2106+ city : 'Portland' ,
2107+ state_code : 'OR' ,
2108+ zip_code : '97201' ,
2109+ country_code_iso3 : 'USA' )
2110+ end
2111+
2112+ it 'prefills address with zip_code when available' do
2113+ allow ( contact_info_service ) . to receive ( :mailing_address ) . and_return ( domestic_address )
2114+
2115+ result = form_profile . prefill
2116+
2117+ expect ( result [ :form_data ] ) . to have_key ( 'veteranContactInformation' )
2118+ vet_contact = result [ :form_data ] [ 'veteranContactInformation' ]
2119+ expect ( vet_contact ) . to have_key ( 'veteranAddress' )
2120+ vet_address = vet_contact [ 'veteranAddress' ]
2121+ expect ( vet_address [ 'street' ] ) . to eq ( '123 Main St' )
2122+ expect ( vet_address [ 'street2' ] ) . to eq ( 'Apt 4B' )
2123+ expect ( vet_address [ 'street3' ] ) . to eq ( 'Building C' )
2124+ expect ( vet_address [ 'city' ] ) . to eq ( 'Portland' )
2125+ expect ( vet_address [ 'state' ] ) . to eq ( 'OR' )
2126+ expect ( vet_address [ 'postalCode' ] ) . to eq ( '97201' )
2127+ expect ( vet_address [ 'country' ] ) . to eq ( 'USA' )
2128+ end
2129+ end
2130+
2131+ context 'with international address' do
2132+ let ( :international_address ) do
2133+ build ( :va_profile_address ,
2134+ :mailing ,
2135+ :international ,
2136+ address_line1 : '10 Downing Street' ,
2137+ city : 'London' ,
2138+ province : 'Greater London' ,
2139+ international_postal_code : 'SW1A 2AA' ,
2140+ country_code_iso3 : 'GBR' ,
2141+ zip_code : nil ,
2142+ state_code : nil )
2143+ end
2144+
2145+ it 'prefills address with international_postal_code when zip_code is nil' do
2146+ allow ( contact_info_service ) . to receive ( :mailing_address ) . and_return ( international_address )
2147+
2148+ result = form_profile . prefill
2149+
2150+ expect ( result [ :form_data ] ) . to have_key ( 'veteranContactInformation' )
2151+ vet_contact = result [ :form_data ] [ 'veteranContactInformation' ]
2152+ expect ( vet_contact ) . to have_key ( 'veteranAddress' )
2153+ vet_address = vet_contact [ 'veteranAddress' ]
2154+ expect ( vet_address [ 'street' ] ) . to eq ( '10 Downing Street' )
2155+ expect ( vet_address [ 'city' ] ) . to eq ( 'London' )
2156+ expect ( vet_address [ 'postalCode' ] ) . to eq ( 'SW1A 2AA' )
2157+ expect ( vet_address [ 'country' ] ) . to eq ( 'GBR' )
2158+ expect ( vet_address [ 'state' ] ) . to be_nil
2159+ end
2160+ end
2161+
2162+ context 'when mailing address is blank' do
2163+ it 'does not prefill address' do
2164+ allow ( contact_info_service ) . to receive ( :mailing_address ) . and_return ( nil )
2165+
2166+ result = form_profile . prefill
2167+
2168+ expect ( result [ :form_data ] ) . to have_key ( 'veteranContactInformation' )
2169+ # veteranContactInformation will have other fields but not veteranAddress
2170+ expect ( result [ :form_data ] [ 'veteranContactInformation' ] ) . not_to have_key ( 'veteranAddress' )
2171+ end
2172+ end
2173+ end
20682174 end
20692175 end
20702176
@@ -2280,7 +2386,7 @@ def expect_prefilled(form_id)
22802386
22812387 describe 'loading 10-7959C form mappings' do
22822388 it "doesn't raise an IOError" do
2283- expect { FormProfile . load_form_mapping ( '10-7959C' ) } . not_to raise_error ( IOError )
2389+ expect { FormProfile . load_form_mapping ( '10-7959C' ) } . not_to raise_error
22842390 end
22852391
22862392 it 'loads the correct data' do
0 commit comments