@ -545,4 +545,166 @@ RSpec.describe Imports::LettingsLogsFieldImportService do
end
end
end
context " when updating homeless fields " do
let ( :field ) { " homeless " }
before do
Imports :: LettingsLogsImportService . new ( storage_service , logger ) . create_logs ( fixture_directory )
lettings_log_file . rewind
lettings_log_xml . at_xpath ( " //xmlns:Q14b1 " ) . content = " 1 "
lettings_log_xml . at_xpath ( " //xmlns:Q13 " ) . content = " 11 "
lettings_log . update! ( values_updated_at : nil )
end
context " and the lettings log already has a value for homeless (yes) and rp_homeless " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log . update! ( homeless : 11 , reasonpref : 1 , rp_homeless : 1 )
end
it " logs that homeless and rp_homeless already has a value and does not update homeless fields " do
expect ( logger ) . to receive ( :info ) . with ( / lettings log \ d+ has a value for homeless and rp_homeless, skipping update / )
import_service . send ( :update_homelessness , lettings_log_xml )
lettings_log . reload
expect ( lettings_log . homeless ) . to eq ( 11 )
expect ( lettings_log . reasonpref ) . to eq ( 1 )
expect ( lettings_log . rp_homeless ) . to eq ( 1 )
expect ( lettings_log . values_updated_at ) . to be_nil
end
end
context " and the lettings log already has a value for homeless (no) and rp_homeless " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log . update! ( homeless : 1 , reasonpref : 1 , rp_homeless : 1 )
end
it " logs that homeless and rp_homeless already has a value and does not update homeless fields " do
expect ( logger ) . to receive ( :info ) . with ( / lettings log \ d+ has a value for homeless and rp_homeless, skipping update / )
import_service . send ( :update_homelessness , lettings_log_xml )
lettings_log . reload
expect ( lettings_log . homeless ) . to eq ( 1 )
expect ( lettings_log . reasonpref ) . to eq ( 1 )
expect ( lettings_log . rp_homeless ) . to eq ( 1 )
expect ( lettings_log . values_updated_at ) . to be_nil
end
end
context " and the lettings log already has a value for homeless and reasonpref(no or don't know) " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log . update! ( homeless : 11 , reasonpref : 2 , rp_homeless : nil )
end
it " logs that homeless and reasonpref already has a value and does not update homeless " do
expect ( logger ) . to receive ( :info ) . with ( / lettings log \ d+ has a value for homeless and reasonpref is not yes, skipping update / )
import_service . send ( :update_homelessness , lettings_log_xml )
lettings_log . reload
expect ( lettings_log . homeless ) . to eq ( 11 )
expect ( lettings_log . reasonpref ) . to eq ( 2 )
expect ( lettings_log . rp_homeless ) . to eq ( nil )
expect ( lettings_log . values_updated_at ) . to be_nil
end
end
context " and the lettings log has a value for homeless and reasonpref(yes) " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log . update! ( homeless : 11 , reasonpref : 1 , rp_insan_unsat : nil )
end
it " only updates rp_homeless " do
expect ( logger ) . to receive ( :info ) . with ( / updating lettings log \ d+'s rp_homeless value to 1 / )
import_service . send ( :update_homelessness , lettings_log_xml )
lettings_log . reload
expect ( lettings_log . homeless ) . to eq ( 11 )
expect ( lettings_log . reasonpref ) . to eq ( 1 )
expect ( lettings_log . rp_homeless ) . to eq ( 1 )
expect ( lettings_log . values_updated_at ) . not_to be_nil
end
end
context " and the lettings log has no values for homeless and rp_homeless and reasonpref is Yes " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log . update! ( homeless : nil , reasonpref : 1 , rp_homeless : 0 )
end
it " updates homeless and rp_homeless " do
expect ( logger ) . to receive ( :info ) . with ( / updating lettings log \ d+'s homeless value to 11 / )
expect ( logger ) . to receive ( :info ) . with ( / updating lettings log \ d+'s rp_homeless value to 1 / )
import_service . send ( :update_homelessness , lettings_log_xml )
lettings_log . reload
expect ( lettings_log . homeless ) . to eq ( 11 )
expect ( lettings_log . reasonpref ) . to eq ( 1 )
expect ( lettings_log . rp_homeless ) . to eq ( 1 )
expect ( lettings_log . values_updated_at ) . not_to be_nil
end
end
context " and the lettings log has no values for homeless and reasonpref is Yes " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log . update! ( homeless : nil , reasonpref : 1 , rp_homeless : 1 )
end
it " updates homeless " do
expect ( logger ) . to receive ( :info ) . with ( / updating lettings log \ d+'s homeless value to 11 / )
import_service . send ( :update_homelessness , lettings_log_xml )
lettings_log . reload
expect ( lettings_log . homeless ) . to eq ( 11 )
expect ( lettings_log . reasonpref ) . to eq ( 1 )
expect ( lettings_log . rp_homeless ) . to eq ( 1 )
expect ( lettings_log . values_updated_at ) . not_to be_nil
end
end
context " and the lettings log has no values for homeless and reasonpref is No " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log . update! ( homeless : nil , reasonpref : 2 , rp_homeless : nil )
end
it " updates homeless " do
expect ( logger ) . to receive ( :info ) . with ( / updating lettings log \ d+'s homeless value to 11 / )
import_service . send ( :update_homelessness , lettings_log_xml )
lettings_log . reload
expect ( lettings_log . homeless ) . to eq ( 11 )
expect ( lettings_log . reasonpref ) . to eq ( 2 )
expect ( lettings_log . rp_homeless ) . to eq ( nil )
expect ( lettings_log . values_updated_at ) . not_to be_nil
end
end
context " and the new values do not set rp_homeless " do
let ( :lettings_log ) { LettingsLog . find_by ( old_id : lettings_log_id ) }
before do
lettings_log_xml . at_xpath ( " //xmlns:Q14b1 " ) . content = " "
lettings_log_xml . at_xpath ( " //xmlns:Q13 " ) . content = " 1 "
end
it " skips update for any fields " do
expect ( logger ) . to receive ( :info ) . with ( / lettings log \ d+ reimport values are not homeless - 11 and rp_homeless - yes, skipping update / )
expect { import_service . send ( :update_homelessness , lettings_log_xml ) }
. not_to ( change { lettings_log . reload . homeless } )
expect ( lettings_log . values_updated_at ) . to be_nil
end
end
end
end