@ -1239,8 +1239,9 @@ RSpec.describe LocationsController, type: :request do
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :location ) { FactoryBot . create ( :location , scheme : ) }
let! ( :location ) { FactoryBot . create ( :location , scheme : ) }
let ( :startdate ) { Time . utc ( 2021 , 1 , 2 ) }
let ( :deactivation_date ) { Time . utc ( 2022 , 10 , 10 ) }
let ( :deactivation_date ) { Time . utc ( 2022 , 10 , 10 ) }
let! ( :lettings_log ) { FactoryBot . create ( :lettings_log , :sh , location : , scheme : , startdate : , owning_organisation : user . organisation ) }
let ( :startdate ) { Time . utc ( 2022 , 10 , 11 ) }
before do
before do
Timecop . freeze ( Time . utc ( 2022 , 10 , 10 ) )
Timecop . freeze ( Time . utc ( 2022 , 10 , 10 ) )
@ -1282,7 +1283,30 @@ RSpec.describe LocationsController, type: :request do
expect ( response ) . to have_http_status ( :ok )
expect ( response ) . to have_http_status ( :ok )
expect ( page ) . to have_css ( " .govuk-notification-banner.govuk-notification-banner--success " )
expect ( page ) . to have_css ( " .govuk-notification-banner.govuk-notification-banner--success " )
location . reload
location . reload
expect ( location . deactivation_date ) . to eq ( deactivation_date )
expect ( location . location_deactivation_periods . count ) . to eq ( 1 )
expect ( location . location_deactivation_periods . first . deactivation_date ) . to eq ( deactivation_date )
end
context " and a log startdate is after location deactivation date " do
it " clears the location and scheme answers " do
expect ( lettings_log . location ) . to eq ( location )
expect ( lettings_log . scheme ) . to eq ( scheme )
lettings_log . reload
expect ( lettings_log . location ) . to eq ( nil )
expect ( lettings_log . scheme ) . to eq ( nil )
end
end
context " and a log startdate is before location deactivation date " do
let ( :startdate ) { Time . utc ( 2022 , 10 , 9 ) }
it " does not update the log " do
expect ( lettings_log . location ) . to eq ( location )
expect ( lettings_log . scheme ) . to eq ( scheme )
lettings_log . reload
expect ( lettings_log . location ) . to eq ( location )
expect ( lettings_log . scheme ) . to eq ( scheme )
end
end
end
end
end
@ -1368,19 +1392,18 @@ RSpec.describe LocationsController, type: :request do
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let ( :user ) { FactoryBot . create ( :user , :data_coordinator ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :scheme ) { FactoryBot . create ( :scheme , owning_organisation : user . organisation ) }
let! ( :location ) { FactoryBot . create ( :location , scheme : ) }
let! ( :location ) { FactoryBot . create ( :location , scheme : ) }
let ( :add_deactivations ) { location . location_deactivation_periods << location_deactivation_period }
before do
before do
Timecop . freeze ( Time . utc ( 2022 , 10 , 10 ) )
Timecop . freeze ( Time . utc ( 2022 , 10 , 10 ) )
sign_in user
sign_in user
location . deactivation_date = deactivation_date
add_deactivations
location . deactivation_date_type = deactivation_date_type
location . save!
location . save!
get " /schemes/ #{ scheme . id } /locations/ #{ location . id } "
get " /schemes/ #{ scheme . id } /locations/ #{ location . id } "
end
end
context " with active location " do
context " with active location " do
let ( :deactivation_date ) { nil }
let ( :add_deactivations ) { }
let ( :deactivation_date_type ) { nil }
it " renders deactivate this location " do
it " renders deactivate this location " do
expect ( response ) . to have_http_status ( :ok )
expect ( response ) . to have_http_status ( :ok )
@ -1389,8 +1412,7 @@ RSpec.describe LocationsController, type: :request do
end
end
context " with deactivated location " do
context " with deactivated location " do
let ( :deactivation_date ) { Time . utc ( 2022 , 10 , 9 ) }
let ( :location_deactivation_period ) { FactoryBot . create ( :location_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 10 , 9 ) ) }
let ( :deactivation_date_type ) { " other " }
it " renders reactivate this location " do
it " renders reactivate this location " do
expect ( response ) . to have_http_status ( :ok )
expect ( response ) . to have_http_status ( :ok )
@ -1399,8 +1421,7 @@ RSpec.describe LocationsController, type: :request do
end
end
context " with location that's deactivating soon " do
context " with location that's deactivating soon " do
let ( :deactivation_date ) { Time . utc ( 2022 , 10 , 12 ) }
let ( :location_deactivation_period ) { FactoryBot . create ( :location_deactivation_period , deactivation_date : Time . zone . local ( 2022 , 10 , 12 ) ) }
let ( :deactivation_date_type ) { " other " }
it " renders reactivate this location " do
it " renders reactivate this location " do
expect ( response ) . to have_http_status ( :ok )
expect ( response ) . to have_http_status ( :ok )