@ -160,9 +160,9 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
end
context " when user is support " do
let ( :user ) { create ( :user , :support ) }
let ( :user ) { create ( :user , :support , organisation : organisation_1 ) }
let ( :log ) { create ( :lettings_log ) }
let ( :log ) { create ( :lettings_log , created_by : user ) }
let ( :non_stock_organisation ) { create ( :organisation , holds_own_stock : false ) }
let ( :expected_opts ) do
@ -176,6 +176,48 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( expected_opts )
expect ( question . displayed_answer_options ( log , user ) ) . not_to include ( non_stock_organisation . id )
end
context " when an org has recently absorbed other orgs " do
let ( :merged_organisation ) { create ( :organisation , name : " Merged org " ) }
let ( :options ) do
{
" " = > " Select an option " ,
organisation_1 . id = > " first test org (active as of 2 February 2021) " ,
organisation_2 . id = > " second test org " ,
merged_organisation . id = > " Merged org (inactive as of 2 February 2023) " ,
}
end
before do
merged_organisation . update! ( merge_date : Time . zone . local ( 2023 , 2 , 2 ) , absorbing_organisation : organisation_1 )
organisation_1 . update! ( created_at : Time . zone . local ( 2021 , 2 , 2 ) )
end
it " shows merged organisation as an option " do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( options )
end
end
context " when user's org has absorbed other orgs during closed collection periods " do
let ( :merged_organisation ) { create ( :organisation , name : " Merged org " ) }
let ( :options ) do
{
" " = > " Select an option " ,
organisation_1 . id = > " first test org " ,
organisation_2 . id = > " second test org " ,
}
end
before do
Timecop . freeze ( Time . zone . local ( 2023 , 4 , 2 ) )
merged_organisation . update! ( merge_date : Time . zone . local ( 2021 , 6 , 2 ) , absorbing_organisation : user . organisation )
user . organisation . update! ( created_at : Time . zone . local ( 2021 , 2 , 2 ) )
end
it " shows merged organisation as an option " do
expect ( question . displayed_answer_options ( log , user ) ) . to eq ( options )
end
end
end
end