@ -12,7 +12,10 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
let ( :owning_org ) { create ( :organisation , :with_old_visible_id ) }
let ( :owning_org ) { create ( :organisation , :with_old_visible_id ) }
let ( :managing_org ) { create ( :organisation , :with_old_visible_id , rent_periods : [ 4 , 1 ] ) }
let ( :managing_org ) { create ( :organisation , :with_old_visible_id , rent_periods : [ 4 , 1 ] ) }
let ( :scheme ) { create ( :scheme , :with_old_visible_id , owning_organisation : owning_org ) }
let ( :scheme ) { create ( :scheme , :with_old_visible_id , owning_organisation : owning_org ) }
let ( :location ) { create ( :location , :with_old_visible_id , scheme : ) }
let ( :postcode_first_part ) { " AA1 " . freeze }
let ( :postcode_second_part ) { " 1AA " . freeze }
let ( :postcode ) { " #{ postcode_first_part } #{ postcode_second_part } " }
let ( :location ) { create ( :location , :with_old_visible_id , scheme : , postcode : ) }
let ( :setup_section_params ) do
let ( :setup_section_params ) do
{
{
@ -88,7 +91,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
. to_return ( status : 200 , body : " { \" status \" :200, \" result \" :{ \" admin_district \" : \" Manchester \" , \" codes \" :{ \" admin_district \" : \" E08000003 \" }}} " , headers : { } )
. to_return ( status : 200 , body : " { \" status \" :200, \" result \" :{ \" admin_district \" : \" Manchester \" , \" codes \" :{ \" admin_district \" : \" E08000003 \" }}} " , headers : { } )
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 9 , BUILDING_NAME : " result address line 1 " , POST_TOWN : " result town or city " , POSTCODE : " AA1 1AA " , UPRN : " 12345 " } } ] } . to_json , headers : { } )
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 9 , BUILDING_NAME : " result address line 1 " , POST_TOWN : " result town or city " , POSTCODE : postcode , UPRN : " 12345 " } } ] } . to_json , headers : { } )
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ uprn / )
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ uprn / )
. to_return ( status : 200 , body : ' { " status " : 200 , " results " : [ { " DPA " : {
. to_return ( status : 200 , body : ' { " status " : 200 , " results " : [ { " DPA " : {
@ -101,7 +104,7 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
" DEPENDENT_THOROUGHFARE_NAME " : " data " ,
" DEPENDENT_THOROUGHFARE_NAME " : " data " ,
" THOROUGHFARE_NAME " : " thing " ,
" THOROUGHFARE_NAME " : " thing " ,
" POST_TOWN " : " London " ,
" POST_TOWN " : " London " ,
" POSTCODE " : " SE2 6RT "
" POSTCODE " : " ' + postcode + ' "
} } ] } ' , headers : { } )
} } ] } ' , headers : { } )
end
end
@ -1484,183 +1487,247 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end
end
describe " UPRN and address fields " do
describe " UPRN and address fields " do
context " with a general needs log " do
% i [
context " when a valid UPRN is given " do
general_needs
context " and address fields are not given " do
supported_housing
let ( :attributes ) { setup_section_params . merge ( { field_4 : 1 , field_18 : " 123456789012 " } ) }
] . each do | needs_type |
context " with a #{ needs_type . to_s . tr ( '_' , ' ' ) } log " do
it " does not add errors " do
let ( :base_attributes ) do
parser . valid?
setup_section_params . merge ( {
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
field_4 : needs_type == :supported_housing ? 2 : 1 ,
expect ( parser . errors [ field ] ) . to be_empty
field_5 : needs_type == :supported_housing ? " S #{ scheme . id } " : nil ,
end
field_6 : needs_type == :supported_housing ? location . old_visible_id : nil ,
end
} . compact )
end
end
context " when an invalid UPRN is given " do
context " and address fields are not given " do
let ( :attributes ) { setup_section_params . merge ( { field_4 : 1 , field_18 : " 1234567890123 " } ) }
it " adds an appropriate error to the UPRN field " do
parser . valid?
expect ( parser . errors [ :field_18 ] ) . to eql ( [ " UPRN must be 12 digits or less. " ] )
end
it " adds errors to missing key address fields " do
parser . valid?
expect ( parser . errors [ :field_19 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " address line 1. " ) ] )
expect ( parser . errors [ :field_21 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " town or city. " ) ] )
expect ( parser . errors [ :field_23 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " part 1 of postcode. " ) ] )
expect ( parser . errors [ :field_24 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " part 2 of postcode. " ) ] )
end
end
end
context " and address fields are given " do
context " when a valid UPRN is given " do
let ( :attributes ) { setup_section_params . merge ( { field_4 : 1 , field_18 : " 1234567890123 " , field_19 : " address line 1 " , field_21 : " town or city " , field_23 : " AA1 " , field_24 : " 1AA " } ) }
context " and address fields are not given " do
let ( :attributes ) { base_attributes . merge ( { field_18 : " 123456789012 " } ) }
it " adds an error to the UPRN field only " do
it " does not add errors " do
parser . valid?
parser . valid?
expect ( parser . errors [ :field_18 ] ) . to eql ( [ " UPRN must be 12 digits or less. " ] )
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
% i [ field_19 field_21 field_23 field_24 ] . each do | field |
expect ( parser . errors [ field ] ) . to be_empty
expect ( parser . errors [ field ] ) . to be_empty
end
end
end
end
it " does not do an address search " do
parser . valid?
expect ( a_request ( :any , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / ) ) . not_to have_been_made
end
end
end
context " when no UPRN is given " do
context " and no address fields are given " do
let ( :attributes ) { setup_section_params . merge ( { field_4 : 1 } ) }
it " adds appropriate errors to UPRN and key address fields " do
parser . valid?
expect ( parser . errors [ :field_18 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . errors [ :field_19 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . errors [ :field_21 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . errors [ :field_23 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . errors [ :field_24 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
end
end
context " and some key address field is missing " do
if needs_type == :supported_housing
let ( :attributes ) { setup_section_params . merge ( { field_4 : 1 , field_21 : " town or city " , field_23 : " AA1 " , field_24 : " 1AA " } ) }
context " and the postcode associated with the UPRN does not match the postcode associated with the location " do
before do
it " adds errors to UPRN and the missing key address field " do
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ uprn / )
parser . valid?
. to_return ( status : 200 , body : ' { " status " : 200 , " results " : [ { " DPA " : {
expect ( parser . errors [ :field_18 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
" PO_BOX_NUMBER " : " fake " ,
expect ( parser . errors [ :field_19 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
" ORGANISATION_NAME " : " org " ,
expect ( parser . errors [ :field_21 ] ) . to be_empty
" DEPARTMENT_NAME " : " name " ,
expect ( parser . errors [ :field_23 ] ) . to be_empty
" SUB_BUILDING_NAME " : " building " ,
expect ( parser . errors [ :field_24 ] ) . to be_empty
" BUILDING_NAME " : " name " ,
" BUILDING_NUMBER " : " number " ,
" DEPENDENT_THOROUGHFARE_NAME " : " data " ,
" THOROUGHFARE_NAME " : " thing " ,
" POST_TOWN " : " London " ,
" POSTCODE " : " BB2 2BB "
} } ] } ' , headers : { } )
end
it " adds an appropriate error to the UPRN field " do
parser . valid?
expect ( parser . errors [ :field_18 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.uprn.postcode_does_not_match_scheme_location_postcode " ) ] )
end
end
end
end
end
end
end
context " and all key address fields are present " do
context " when an invalid UPRN is given " do
let ( :attributes ) { setup_section_params . merge ( { field_4 : 1 , field_18 : nil , field_19 : " address line 1 " , field_21 : " town or city " , field_23 : " AA1 " , field_24 : " 1AA " } ) }
context " and address fields are not given " do
let ( :attributes ) { base_attributes . merge ( { field_18 : " 1234567890123 " } ) }
context " and an address can be found with a high enough match rating " do
before do
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 7 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : " AA1 1AA " , UPRN : " 1 " } } ] } . to_json , headers : { } )
end
it " does not add errors " do
it " adds an appropriate error to the UPRN field " do
parser . valid?
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . errors [ :field_18 ] ) . to eql ( [ " UPRN must be 12 digits or less. " ] )
expect ( parser . errors [ field ] ) . to be_empty
end
end
end
it " does not set manual address input " do
it " adds errors to missing key address fields " do
parser . valid?
parser . valid?
expect ( parser . log . manual_address_entry_selected ) . to be_falsey
expect ( parser . errors [ :field_19 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " address line 1. " ) ] )
expect ( parser . errors [ :field_21 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " town or city. " ) ] )
expect ( parser . errors [ :field_23 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " part 1 of postcode. " ) ] )
expect ( parser . errors [ :field_24 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.not_answered " , question : " part 2 of postcode. " ) ] )
end
end
end
end
context " when no address can be found " do
context " and address fields are given " do
before do
let ( :attributes ) { base_attributes . merge ( { field_18 : " 1234567890123 " , field_19 : " address line 1 " , field_21 : " town or city " , field_23 : postcode_first_part , field_24 : postcode_second_part } ) }
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
. to_return ( status : 200 , body : { results : [ ] } . to_json , headers : { } )
end
it " does not add errors " do
it " adds an error to the UPRN field only " do
parser . valid?
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . errors [ :field_18 ] ) . to eql ( [ " UPRN must be 12 digits or less. " ] )
% i [ field_19 field_21 field_23 field_24 ] . each do | field |
expect ( parser . errors [ field ] ) . to be_empty
expect ( parser . errors [ field ] ) . to be_empty
end
end
end
end
it " sets manual address input " do
it " does not do an address search " do
parser . valid?
parser . valid?
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
expect ( a_request ( :any , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / ) ) . not_to have_been_made
expect ( parser . log . address_line1 ) . to eq ( " address line 1 " )
expect ( parser . log . town_or_city ) . to eq ( " town or city " )
expect ( parser . log . postcode_full ) . to eq ( " AA1 1AA " )
end
end
end
end
end
context " when a single address with not a high enough match rating is returned " do
context " when no UPRN is given " do
before do
context " and no address fields are given " do
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
let ( :attributes ) { base_attributes . merge ( { field_4 : 1 } ) }
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 6 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : " AA1 1AA " , UPRN : " 1 " } } ] } . to_json , headers : { } )
end
it " does not add error s" do
it " adds appropriate errors to UPRN and key address fields " do
parser . valid?
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . errors [ :field_18 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . errors [ field ] ) . to be_empty
expect ( parser . errors [ :field_19 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
end
expect ( parser . errors [ :field_21 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . errors [ :field_23 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . errors [ :field_24 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
end
end
end
context " and some key address field is missing " do
let ( :attributes ) { base_attributes . merge ( { field_21 : " town or city " , field_23 : postcode_first_part , field_24 : postcode_second_part } ) }
it " sets manual address input " do
it " adds errors to UPRN and the missing key address field " do
parser . valid?
parser . valid?
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
expect ( parser . errors [ :field_18 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . log . address_line1 ) . to eq ( " address line 1 " )
expect ( parser . errors [ :field_19 ] ) . to eql ( [ I18n . t ( " validations.lettings.2026.bulk_upload.address.not_answered " ) ] )
expect ( parser . log . town_or_city ) . to eq ( " town or city " )
expect ( parser . errors [ :field_21 ] ) . to be_empty
expect ( parser . log . postcode_full ) . to eq ( " AA1 1AA " )
expect ( parser . errors [ :field_23 ] ) . to be_empty
expect ( parser . errors [ :field_24 ] ) . to be_empty
end
end
end
end
context " when no addresses have a high enough match rating " do
context " and all key address fields are present " do
before do
let ( :attributes ) { base_attributes . merge ( { field_18 : nil , field_19 : " address line 1 " , field_21 : " town or city " , field_23 : postcode_first_part , field_24 : postcode_second_part } ) }
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 6 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : " AA1 1AA " , UPRN : " 1 " } } , { DPA : { MATCH : 0 . 8 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : " BB2 2BB " , UPRN : " 2 " } } ] } . to_json , headers : { } )
context " and an address can be found with a high enough match rating " do
before do
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 7 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : postcode , UPRN : " 1 " } } ] } . to_json , headers : { } )
end
it " does not add errors " do
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . errors [ field ] ) . to be_empty
end
end
it " does not set manual address input " do
parser . valid?
expect ( parser . log . manual_address_entry_selected ) . to be_falsey
end
end
end
it " does not add errors " do
context " when no address can be found " do
parser . valid?
before do
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
expect ( parser . errors [ field ] ) . to be_empty
. to_return ( status : 200 , body : { results : [ ] } . to_json , headers : { } )
end
it " does not add errors " do
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . errors [ field ] ) . to be_empty
end
end
it " sets manual address input " do
parser . valid?
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
expect ( parser . log . address_line1 ) . to eq ( " address line 1 " )
expect ( parser . log . town_or_city ) . to eq ( " town or city " )
expect ( parser . log . postcode_full ) . to eq ( postcode )
end
if needs_type == :supported_housing
context " and the postcode entered manually does not match the postcode associated with the location " do
let ( :attributes ) { base_attributes . merge ( { field_18 : nil , field_19 : " address line 1 " , field_21 : " town or city " , field_23 : " BB2 " , field_24 : " 2BB " } ) }
it " adds appropriate errors to postcode and LA fields " do
parser . valid?
expect ( parser . errors [ :field_23 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
expect ( parser . errors [ :field_24 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
expect ( parser . errors [ :field_25 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
end
end
end
end
end
end
it " sets manual address input " do
context " when a single address with not a high enough match rating is returned " do
parser . valid?
before do
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 6 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : postcode , UPRN : " 1 " } } ] } . to_json , headers : { } )
expect ( parser . log . address_line1 ) . to eq ( " address line 1 " )
end
expect ( parser . log . town_or_city ) . to eq ( " town or city " )
expect ( parser . log . postcode_full ) . to eq ( " AA1 1AA " )
it " does not add errors " do
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . errors [ field ] ) . to be_empty
end
end
it " sets manual address input " do
parser . valid?
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
expect ( parser . log . address_line1 ) . to eq ( " address line 1 " )
expect ( parser . log . town_or_city ) . to eq ( " town or city " )
expect ( parser . log . postcode_full ) . to eq ( postcode )
end
if needs_type == :supported_housing
context " and the postcode entered manually does not match the postcode associated with the location " do
let ( :attributes ) { base_attributes . merge ( { field_18 : nil , field_19 : " address line 1 " , field_21 : " town or city " , field_23 : " BB2 " , field_24 : " 2BB " } ) }
it " adds appropriate errors to postcode and LA fields " do
parser . valid?
expect ( parser . errors [ :field_23 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
expect ( parser . errors [ :field_24 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
expect ( parser . errors [ :field_25 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
end
end
end
end
end
end
end
end
end
context " with a supported housing log " do
context " when no addresses have a high enough match rating " do
context " when neither UPRN nor address fields are provided " do
before do
let ( :attributes ) { setup_section_params . merge ( { field_4 : 2 , field_5 : " S #{ scheme . id } " , field_6 : location . old_visible_id , field_18 : nil , field_19 : nil , field_21 : nil , field_23 : nil , field_24 : nil } ) }
stub_request ( :get , / api \ .os \ .uk \/ search \/ places \/ v1 \/ find / )
. to_return ( status : 200 , body : { results : [ { DPA : { MATCH : 0 . 6 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : postcode , UPRN : " 1 " } } , { DPA : { MATCH : 0 . 8 , BUILDING_NAME : " " , POST_TOWN : " " , POSTCODE : " BB2 2BB " , UPRN : " 2 " } } ] } . to_json , headers : { } )
end
it " does not add errors " do
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . errors [ field ] ) . to be_empty
end
end
it " does not add missing field errors " do
it " sets manual address input " do
parser . valid?
parser . valid?
% i [ field_18 field_19 field_20 field_21 field_22 field_23 field_24 ] . each do | field |
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
expect ( parser . errors [ field ] ) . to be_empty
expect ( parser . log . manual_address_entry_selected ) . to be_truthy
expect ( parser . log . address_line1 ) . to eq ( " address line 1 " )
expect ( parser . log . town_or_city ) . to eq ( " town or city " )
expect ( parser . log . postcode_full ) . to eq ( postcode )
end
if needs_type == :supported_housing
context " and the postcode entered manually does not match the postcode associated with the location " do
let ( :attributes ) { base_attributes . merge ( { field_18 : nil , field_19 : " address line 1 " , field_21 : " town or city " , field_23 : " BB2 " , field_24 : " 2BB " } ) }
it " adds appropriate errors to postcode and LA fields " do
parser . valid?
expect ( parser . errors [ :field_23 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
expect ( parser . errors [ :field_24 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
expect ( parser . errors [ :field_25 ] ) . to eql ( [ I18n . t ( " validations.lettings.property.postcode_full.does_not_match_scheme_location_postcode " ) ] )
end
end
end
end
end
end
end
end
end
end
@ -1869,87 +1936,79 @@ RSpec.describe BulkUpload::Lettings::Year2026::RowParser do
end
end
end
end
describe " # uprn " do
describe " address-related fields " do
let ( :attributes ) { { bulk_upload : , field_4 : 1 , field_18 : " 12 " } }
% i [
general_needs
supported_housing
] . each do | needs_type |
context " with a #{ needs_type . to_s . tr ( '_' , ' ' ) } log " do
let ( :base_attributes ) do
{
bulk_upload : ,
field_4 : needs_type == :supported_housing ? 2 : 1 ,
field_5 : needs_type == :supported_housing ? " S #{ scheme . id } " : nil ,
field_6 : needs_type == :supported_housing ? location . old_visible_id : nil ,
} . compact
end
describe " # uprn " do
let ( :attributes ) { base_attributes . merge ( { field_18 : " 12 " } ) }
it " sets to given value " do
it " sets to given value " do
expect ( parser . log . uprn ) . to eql ( " 12 " )
expect ( parser . log . uprn ) . to eql ( " 12 " )
end
end
end
end
describe " # uprn_known " do
describe " # uprn_known " do
context " when uprn specified " do
context " when uprn specified " do
let ( :attributes ) { { bulk_upload : , field_4 : 1 , field_18 : " 12 " } }
let ( :attributes ) { base_attributes . merge ( { field_18 : " 12 " } ) }
it " sets to 1 " do
it " sets to 1 " do
expect ( parser . log . uprn_known ) . to be ( 1 )
expect ( parser . log . uprn_known ) . to be ( 1 )
expect ( parser . log . uprn_confirmed ) . to be ( 1 )
expect ( parser . log . uprn_confirmed ) . to be ( 1 )
end
end
end
end
context " when uprn blank " do
context " when uprn blank " do
let ( :attributes ) { { bulk_upload : , field_4 : 1 , field_18 : " " } }
let ( :attributes ) { base_attributes . merge ( { field_18 : " " } ) }
it " sets to 0 " do
it " sets to 0 " do
expect ( parser . log . uprn_known ) . to be ( 0 )
expect ( parser . log . uprn_known ) . to be ( 0 )
end
end
end
end
end
end
describe " # address_line1 " do
describe " # address_line1 " do
let ( :attributes ) { { bulk_upload : , field_4 : 1 , field_19 : " 123 Sesame Street " } }
let ( :attributes ) { base_attributes . merge ( { field_19 : " 123 Sesame Street " } ) }
it " sets to given value " do
it " sets to given value " do
expect ( parser . log . address_line1 ) . to eql ( " 123 Sesame Street " )
expect ( parser . log . address_line1 ) . to eql ( " 123 Sesame Street " )
end
end
end
end
describe " # address_line2 " do
describe " # address_line2 " do
let ( :attributes ) { { bulk_upload : , field_4 : 1 , field_20 : " Cookie Town " } }
let ( :attributes ) { base_attributes . merge ( { field_20 : " Cookie Town " } ) }
it " sets to given value " do
it " sets to given value " do
expect ( parser . log . address_line2 ) . to eql ( " Cookie Town " )
expect ( parser . log . address_line2 ) . to eql ( " Cookie Town " )
end
end
end
end
describe " # town_or_city " do
describe " # town_or_city " do
let ( :attributes ) { { bulk_upload : , field_4 : 1 , field_21 : " London " } }
let ( :attributes ) { base_attributes . merge ( { field_21 : " London " } ) }
it " sets to given value " do
it " sets to given value " do
expect ( parser . log . town_or_city ) . to eql ( " London " )
expect ( parser . log . town_or_city ) . to eql ( " London " )
end
end
end
end
describe " # county " do
describe " # county " do
let ( :attributes ) { { bulk_upload : , field_4 : 1 , field_22 : " Greater London " } }
let ( :attributes ) { base_attributes . merge ( { field_22 : " Greater London " } ) }
it " sets to given value " do
it " sets to given value " do
expect ( parser . log . county ) . to eql ( " Greater London " )
expect ( parser . log . county ) . to eql ( " Greater London " )
end
end
end
end
describe " address related fields for supported housing logs " do
context " when address data is provided for a supported housing log " do
let ( :attributes ) { { bulk_upload : , field_4 : 2 , field_18 : nil , field_19 : " Flat 1 " , field_20 : " Example Place " , field_21 : " London " , field_22 : " Greater London " , field_23 : " SW1A " , field_24 : " 1AA " } }
it " is not set on the log " do
expect ( parser . log . uprn ) . to be_nil
expect ( parser . log . uprn_known ) . to be_nil
expect ( parser . log . address_line1 ) . to be_nil
expect ( parser . log . address_line1_as_entered ) . to be_nil
expect ( parser . log . address_line2 ) . to be_nil
expect ( parser . log . address_line2_as_entered ) . to be_nil
expect ( parser . log . town_or_city ) . to be_nil
expect ( parser . log . town_or_city_as_entered ) . to be_nil
expect ( parser . log . county ) . to be_nil
expect ( parser . log . county_as_entered ) . to be_nil
expect ( parser . log . postcode_full ) . to be_nil
expect ( parser . log . postcode_full_as_entered ) . to be_nil
expect ( parser . log . la ) . to be_nil
expect ( parser . log . la_as_entered ) . to be_nil
expect ( parser . log . address_line1_input ) . to be_nil
expect ( parser . log . postcode_full_input ) . to be_nil
expect ( parser . log . select_best_address_match ) . to be_nil
end
end
end
end
end
end