Browse Source

CLDC-4402: simplify p5

CLDC-4402-audit-start-year-2024-or-later-usage-2
Rebecca Jesson 3 weeks ago
parent
commit
e6949c03d1
  1. 2
      app/models/form/sales/pages/deposit.rb
  2. 6
      app/models/form/sales/pages/deposit_discount.rb
  3. 2
      app/models/form/sales/pages/la_nominations.rb
  4. 2
      app/models/form/sales/pages/last_accommodation.rb
  5. 2
      app/models/form/sales/pages/last_accommodation_la.rb
  6. 17
      app/models/form/sales/pages/managing_organisation.rb
  7. 2
      app/models/validations/sales/soft_validations.rb
  8. 30
      spec/models/form/sales/pages/deposit_discount_spec.rb
  9. 110
      spec/models/form/sales/pages/deposit_spec.rb
  10. 46
      spec/models/form/sales/pages/la_nominations_spec.rb
  11. 24
      spec/models/form/sales/pages/last_accommodation_la_spec.rb
  12. 24
      spec/models/form/sales/pages/last_accommodation_spec.rb
  13. 79
      spec/models/form/sales/pages/managing_organisation_spec.rb

2
app/models/form/sales/pages/deposit.rb

@ -15,7 +15,7 @@ class Form::Sales::Pages::Deposit < ::Form::Page
def routed_to?(log, _user)
return false unless super
return true if log.ownershipsch == 2 || (log.ownershipsch == 3 && log.mortgageused == 1)
return false if log.stairowned_100? != @optional && form.start_year_2024_or_later?
return false if log.stairowned_100? != @optional
log.ownershipsch == 1
end

6
app/models/form/sales/pages/deposit_discount.rb

@ -11,10 +11,6 @@ class Form::Sales::Pages::DepositDiscount < ::Form::Page
end
def depends_on
if form.start_year_2024_or_later?
[{ "social_homebuy?" => true, "stairowned_100?" => @optional }]
else
[{ "social_homebuy?" => true }]
end
[{ "social_homebuy?" => true, "stairowned_100?" => @optional }]
end
end

2
app/models/form/sales/pages/la_nominations.rb

@ -12,7 +12,7 @@ class Form::Sales::Pages::LaNominations < ::Form::Page
end
def routed_to?(log, _current_user)
return false if log.staircase == 1 && form.start_year_2024_or_later?
return false if log.staircase == 1
super
end

2
app/models/form/sales/pages/last_accommodation.rb

@ -13,7 +13,7 @@ class Form::Sales::Pages::LastAccommodation < ::Form::Page
end
def routed_to?(log, _user)
return false if form.start_year_2024_or_later? && log.discounted_ownership_sale?
return false if log.discounted_ownership_sale?
super
end

2
app/models/form/sales/pages/last_accommodation_la.rb

@ -16,7 +16,7 @@ class Form::Sales::Pages::LastAccommodationLa < ::Form::Page
end
def routed_to?(log, _user)
return false if form.start_year_2024_or_later? && log.discounted_ownership_sale?
return false if log.discounted_ownership_sale?
super
end

17
app/models/form/sales/pages/managing_organisation.rb

@ -13,19 +13,12 @@ class Form::Sales::Pages::ManagingOrganisation < ::Form::Page
def routed_to?(log, current_user)
return false unless current_user
if form.start_year_2024_or_later?
organisation = current_user.support? ? log.owning_organisation : current_user.organisation
organisation = current_user.support? ? log.owning_organisation : current_user.organisation
return false unless organisation
return false if log.owning_organisation != organisation && !organisation.holds_own_stock?
return true unless organisation.holds_own_stock?
return false unless organisation
return false if log.owning_organisation != organisation && !organisation.holds_own_stock?
return true unless organisation.holds_own_stock?
organisation.managing_agents.count >= 1
else
return false unless current_user.support?
return false unless log.owning_organisation
log.owning_organisation.managing_agents.count >= 1
end
organisation.managing_agents.count >= 1
end
end

2
app/models/validations/sales/soft_validations.rb

@ -129,7 +129,7 @@ module Validations::Sales::SoftValidations
def grant_outside_common_range?
return unless grant && type && saledate
return if form.start_year_2024_or_later? && [21, 8].include?(type)
return if [21, 8].include?(type)
!grant.between?(9_000, 16_000)
end

30
spec/models/form/sales/pages/deposit_discount_spec.rb

@ -1,6 +1,8 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::DepositDiscount, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection, optional: false) }
let(:page_id) { "discount" }
@ -8,7 +10,7 @@ RSpec.describe Form::Sales::Pages::DepositDiscount, type: :model do
let(:subsection) { instance_double(Form::Subsection) }
before do
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1)))
allow(subsection).to receive(:form).and_return(instance_double(Form, start_date: current_collection_start_date))
end
it "has correct subsection" do
@ -29,7 +31,7 @@ RSpec.describe Form::Sales::Pages::DepositDiscount, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "social_homebuy?" => true }],
[{ "social_homebuy?" => true, "stairowned_100?" => false }],
)
end
@ -38,30 +40,8 @@ RSpec.describe Form::Sales::Pages::DepositDiscount, type: :model do
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "social_homebuy?" => true }],
)
end
end
context "when it's a 2024 form" do
before do
allow(subsection).to receive(:form).and_return(instance_double(Form, start_year_2024_or_later?: true, start_date: Time.zone.local(2024, 4, 1)))
end
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "social_homebuy?" => true, "stairowned_100?" => false }],
[{ "social_homebuy?" => true, "stairowned_100?" => true }],
)
end
context "and optional" do
subject(:page) { described_class.new(page_id, page_definition, subsection, optional: true) }
it "has correct depends_on" do
expect(page.depends_on).to eq(
[{ "social_homebuy?" => true, "stairowned_100?" => true }],
)
end
end
end
end

110
spec/models/form/sales/pages/deposit_spec.rb

@ -1,12 +1,14 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Deposit, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection, ownershipsch: 1, optional:) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, enabled?: true, depends_on: true, id: "shared_ownership_initial_purchase") }
let(:form) { instance_double(Form, start_year_2024_or_later?: false, start_date: Time.zone.local(2023, 4, 1), depends_on_met: true, start_year_2026_or_later?: false) }
let(:form) { instance_double(Form, start_date: current_collection_start_date, depends_on_met: true, start_year_2026_or_later?: true) }
let(:optional) { false }
before do
@ -29,11 +31,7 @@ RSpec.describe Form::Sales::Pages::Deposit, type: :model do
expect(page.description).to be_nil
end
context "when routing with start year after 2024" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(true)
end
context "when routing" do
context "and optional is false" do
context "and the log is shared ownership, not social homembuy and stairowned is not 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) }
@ -128,104 +126,4 @@ RSpec.describe Form::Sales::Pages::Deposit, type: :model do
end
end
end
context "when routing with start year before 2024" do
before do
allow(form).to receive(:start_year_2024_or_later?).and_return(false)
end
context "and optional is false" do
context "and the log is shared ownership, not social homembuy and stairowned is not 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is shared ownership, not social homembuy and stairowned is 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is shared ownership, social homebuy and stairowned is not 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is shared ownership, social homebuy and stairowned is 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is discounted ownership" do
let(:log) { build(:sales_log, ownershipsch: 2, type: 18) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is outright ownership and mortgage used is yes" do
let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 1) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and ownership is outright sale and mortgage used is not yes" do
let(:log) { build(:sales_log, ownershipsch: 3, mortgageused: 2) }
it "doesn't route to the page" do
expect(page).not_to be_routed_to(log, nil)
end
end
end
context "and optional is true" do
let(:optional) { true }
context "and the log is shared ownership, not social homembuy and stairowned is not 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 70) }
it "does routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is shared ownership, not social homembuy and stairowned is 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 16, stairowned: 100) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is shared ownership, social homebuy and stairowned is not 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 80) }
it "does routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
context "and the log is shared ownership, social homebuy and stairowned is 100" do
let(:log) { build(:sales_log, ownershipsch: 1, type: 18, stairowned: 100) }
it "routes to the page" do
expect(page).to be_routed_to(log, nil)
end
end
end
end
end

46
spec/models/form/sales/pages/la_nominations_spec.rb

@ -1,14 +1,15 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::LaNominations, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:log) { build(:sales_log, :completed) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:start_year_2024_or_later) { false }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: start_year_2024_or_later) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
let(:subsection) { instance_double(Form::Subsection, form:) }
before do
@ -31,36 +32,23 @@ RSpec.describe Form::Sales::Pages::LaNominations, type: :model do
expect(page.description).to be_nil
end
context "with 23/24 log" do
let(:start_year_2024_or_later) { false }
it "has correct routed to" do
log.staircase = 1
expect(page.routed_to?(log, nil)).to be(true)
end
it "has correct routed to when staircase is yes" do
log.staircase = 1
expect(page.routed_to?(log, nil)).to be(false)
end
context "with 24/25 log" do
let(:start_year_2024_or_later) { true }
it "has correct routed to when staircase is yes" do
log.staircase = 1
expect(page.routed_to?(log, nil)).to be(false)
end
it "has correct routed to when staircase is nil" do
log.staircase = nil
expect(page.routed_to?(log, nil)).to be(true)
end
it "has correct routed to when staircase is nil" do
log.staircase = nil
expect(page.routed_to?(log, nil)).to be(true)
end
it "has correct routed to when staircase is no" do
log.staircase = 2
expect(page.routed_to?(log, nil)).to be(true)
end
it "has correct routed to when staircase is no" do
log.staircase = 2
expect(page.routed_to?(log, nil)).to be(true)
end
it "has correct routed to when staircase is don't know" do
log.staircase = 3
expect(page.routed_to?(log, nil)).to be(true)
end
it "has correct routed to when staircase is don't know" do
log.staircase = 3
expect(page.routed_to?(log, nil)).to be(true)
end
end

24
spec/models/form/sales/pages/last_accommodation_la_spec.rb

@ -1,12 +1,13 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::LastAccommodationLa, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:start_year_2024_or_later) { false }
let(:form) { instance_double(Form, depends_on_met: true, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: start_year_2024_or_later) }
let(:form) { instance_double(Form, depends_on_met: true, start_date: current_collection_start_date) }
let(:subsection) { instance_double(Form::Subsection, form:, depends_on: nil, enabled?: true) }
let(:log) { build(:sales_log, :completed) }
@ -32,22 +33,13 @@ RSpec.describe Form::Sales::Pages::LastAccommodationLa, type: :model do
}])
end
it "is routed to" do
log.ownershipsch = 2
it "is routed to for non discounted sale logs" do
log.update!(ownershipsch: 1)
expect(page).to be_routed_to(log, nil)
end
context "with 2024 form" do
let(:start_year_2024_or_later) { true }
it "is routed to for 2024 non discounted sale logs" do
log.update!(ownershipsch: 1)
expect(page).to be_routed_to(log, nil)
end
it "is not routed to for 2024 discounted sale logs" do
log.update!(ownershipsch: 2)
expect(page).not_to be_routed_to(log, nil)
end
it "is not routed to for discounted sale logs" do
log.update!(ownershipsch: 2)
expect(page).not_to be_routed_to(log, nil)
end
end

24
spec/models/form/sales/pages/last_accommodation_spec.rb

@ -1,14 +1,15 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::LastAccommodation, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:log) { build(:sales_log, :completed) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:start_year_2024_or_later) { false }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: start_year_2024_or_later) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
let(:subsection) { instance_double(Form::Subsection, form:, depends_on: nil) }
it "has correct subsection" do
@ -31,22 +32,13 @@ RSpec.describe Form::Sales::Pages::LastAccommodation, type: :model do
expect(page.depends_on).to be_nil
end
it "is routed to" do
log.ownershipsch = 2
it "is routed to for non discounted sale logs" do
log.update!(ownershipsch: 1)
expect(page).to be_routed_to(log, nil)
end
context "with 2024 form" do
let(:start_year_2024_or_later) { true }
it "is routed to for 2024 non discounted sale logs" do
log.update!(ownershipsch: 1)
expect(page).to be_routed_to(log, nil)
end
it "is not routed to for 2024 discounted sale logs" do
log.update!(ownershipsch: 2)
expect(page).not_to be_routed_to(log, nil)
end
it "is not routed to for discounted sale logs" do
log.update!(ownershipsch: 2)
expect(page).not_to be_routed_to(log, nil)
end
end

79
spec/models/form/sales/pages/managing_organisation_spec.rb

@ -1,12 +1,14 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::ManagingOrganisation, type: :model do
include CollectionTimeHelper
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection, form:) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2023, 4, 1), start_year_2024_or_later?: false) }
let(:form) { instance_double(Form, start_date: current_collection_start_date) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
@ -28,82 +30,9 @@ RSpec.describe Form::Sales::Pages::ManagingOrganisation, type: :model do
expect(page.depends_on).to be_nil
end
describe "#routed_to? with 2023 logs" do
let(:log) { create(:sales_log) }
let(:organisation) { create(:organisation) }
context "when user nil" do
it "is not shown" do
expect(page.routed_to?(log, nil)).to be(false)
end
end
context "when user is not support" do
let(:user) { create(:user) }
it "is not shown" do
expect(page.routed_to?(log, nil)).to be(false)
end
end
context "when support" do
let(:user) { create(:user, :support) }
context "when owning_organisation not set" do
let(:log) { create(:sales_log, owning_organisation: nil) }
it "is not shown" do
expect(page.routed_to?(log, user)).to be(false)
end
end
context "with 0 managing_agents" do
it "is not shown" do
expect(page.routed_to?(log, user)).to be(false)
end
end
context "with >1 managing_agents" do
before do
create(:organisation_relationship, parent_organisation: log.owning_organisation)
create(:organisation_relationship, parent_organisation: log.owning_organisation)
end
it "is shown" do
expect(page.routed_to?(log, user)).to be(true)
end
end
context "with 1 managing_agents" do
let(:managing_agent) { create(:organisation) }
before do
create(
:organisation_relationship,
child_organisation: managing_agent,
parent_organisation: log.owning_organisation,
)
end
it "is shown" do
expect(page.routed_to?(log, user)).to be(true)
end
end
end
context "when not support" do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) }
it "is not shown" do
expect(page.routed_to?(log, user)).to be(false)
end
end
end
describe "#routed_to? with 2024 logs" do
describe "#routed_to?" do
let(:log) { create(:sales_log) }
let(:organisation) { create(:organisation) }
let(:form) { instance_double(Form, start_date: Time.zone.local(2024, 4, 1), start_year_2024_or_later?: true) }
context "when user nil" do
it "is not shown" do

Loading…
Cancel
Save