Browse Source

Display merge date for managing organisations question (#2063)

pull/2075/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
403ad05e42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/models/form/lettings/questions/managing_organisation.rb
  2. 22
      spec/models/form/lettings/questions/managing_organisation_spec.rb

12
app/models/form/lettings/questions/managing_organisation.rb

@ -35,13 +35,21 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
user.organisation.managing_agents + log.owning_organisation.managing_agents
else
user.organisation.managing_agents
end.pluck(:id, :name).to_h
end
user.organisation.absorbed_organisations.each do |absorbed_org|
opts[absorbed_org.id] = "#{absorbed_org.name} (inactive as of #{absorbed_org.merge_date.to_fs(:govuk_date)})"
end
opts.merge(orgs)
orgs.each do |org|
opts[org.id] = if org.merge_date.present?
"#{org.name} (inactive as of #{org.merge_date.to_fs(:govuk_date)})"
else
org.name
end
end
opts
end
def displayed_answer_options(log, user)

22
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -119,6 +119,28 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end
end
context "when org owns stock and has merged managing agents" do
let(:options) do
{
"" => "Select an option",
log.managing_organisation.id => "Managing org 1",
log_owning_org.id => "Owning org (Owning organisation)",
org_rel1.child_organisation.id => "Managing org 2 (inactive as of 2 August 2023)",
org_rel2.child_organisation.id => "Managing org 3 (inactive as of 2 August 2023)",
}
end
before do
org_rel1.child_organisation.update!(merge_date: Time.zone.local(2023, 8, 2), absorbing_organisation_id: log_owning_org.id)
org_rel2.child_organisation.update!(merge_date: Time.zone.local(2023, 8, 2), absorbing_organisation_id: log_owning_org.id)
end
it "shows current managing agent at top, followed by the current owning organisation (with hint), followed by the managing agents of the current owning organisation" do
log_owning_org.update!(holds_own_stock: true)
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
context "when org does not own stock" do
let(:options) do
{

Loading…
Cancel
Save