Browse Source

Don't display available from if it doesn't exist (#2059)

test-merge-dpo-emails
kosiakkatrina 1 year ago committed by GitHub
parent
commit
3b88f2a390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/form/lettings/questions/stock_owner.rb
  2. 4
      app/models/form/sales/questions/owning_organisation_id.rb
  3. 27
      spec/models/form/lettings/questions/stock_owner_spec.rb
  4. 28
      spec/models/form/sales/questions/owning_organisation_id_spec.rb

4
app/models/form/lettings/questions/stock_owner.rb

@ -32,8 +32,8 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question
Organisation.where(holds_own_stock: true).find_each do |org|
if org.merge_date.present?
answer_opts[org.id] = "#{org.name} (inactive as of #{org.merge_date.to_fs(:govuk_date)})" if org.merge_date >= FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
elsif org.absorbed_organisations.merged_during_open_collection_period.exists?
answer_opts[org.id] = "#{org.name} (active as of #{org.created_at.to_fs(:govuk_date)})"
elsif org.absorbed_organisations.merged_during_open_collection_period.exists? && org.available_from.present?
answer_opts[org.id] = "#{org.name} (active as of #{org.available_from.to_fs(:govuk_date)})"
else
answer_opts[org.id] = org.name
end

4
app/models/form/sales/questions/owning_organisation_id.rb

@ -33,8 +33,8 @@ class Form::Sales::Questions::OwningOrganisationId < ::Form::Question
Organisation.where(holds_own_stock: true).find_each do |org|
if org.merge_date.present?
answer_opts[org.id] = "#{org.name} (inactive as of #{org.merge_date.to_fs(:govuk_date)})" if org.merge_date >= FormHandler.instance.start_date_of_earliest_open_for_editing_collection_period
elsif org.absorbed_organisations.merged_during_open_collection_period.exists?
answer_opts[org.id] = "#{org.name} (active as of #{org.created_at.to_fs(:govuk_date)})"
elsif org.absorbed_organisations.merged_during_open_collection_period.exists? && org.available_from.present?
answer_opts[org.id] = "#{org.name} (active as of #{org.available_from.to_fs(:govuk_date)})"
else
answer_opts[org.id] = org.name
end

27
spec/models/form/lettings/questions/stock_owner_spec.rb

@ -221,6 +221,33 @@ RSpec.describe Form::Lettings::Questions::StockOwner, 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 "and org has recently absorbed other orgs and does not have available from date" do
let(:merged_organisation) { create(:organisation, name: "Merged org") }
let(:org) { create(:organisation, name: "User org") }
let(:options) do
{
"" => "Select an option",
org.id => "User org",
user.organisation.id => user.organisation.name,
log.owning_organisation.id => log.owning_organisation.name,
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: org)
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end
it "shows merged organisation as an option" do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
end
end

28
spec/models/form/sales/questions/owning_organisation_id_spec.rb

@ -224,7 +224,7 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
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))
organisation_1.update!(created_at: Time.zone.local(2021, 3, 2), available_from: Time.zone.local(2021, 2, 2))
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
@ -257,6 +257,32 @@ RSpec.describe Form::Sales::Questions::OwningOrganisationId, type: :model do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
context "when an existing 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",
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), available_from: nil)
Timecop.freeze(Time.zone.local(2023, 11, 10))
end
after do
Timecop.return
end
it "does not show abailable from for absorbing organisation" do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
end
end

Loading…
Cancel
Save