Browse Source

CLDC-3172 Update routing for staircase transactions (#2203)

* Update routing for LaNominations

* Update routing for buyer previous

* Extract a method

* lint
pull/2222/head
kosiakkatrina 11 months ago committed by GitHub
parent
commit
7a9291dac9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      app/models/form/sales/pages/buyer_previous.rb
  2. 6
      app/models/form/sales/pages/la_nominations.rb
  3. 4
      app/models/sales_log.rb
  4. 57
      spec/models/form/sales/pages/buyer_previous_spec.rb
  5. 53
      spec/models/form/sales/pages/la_nominations_spec.rb

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

@ -10,4 +10,10 @@ class Form::Sales::Pages::BuyerPrevious < ::Form::Page
Form::Sales::Questions::BuyerPrevious.new(nil, nil, self, joint_purchase: @joint_purchase), Form::Sales::Questions::BuyerPrevious.new(nil, nil, self, joint_purchase: @joint_purchase),
] ]
end end
def routed_to?(log, _current_user)
return false if log.is_staircase? && log.form.start_year_after_2024?
super
end
end end

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

@ -9,4 +9,10 @@ class Form::Sales::Pages::LaNominations < ::Form::Page
Form::Sales::Questions::LaNominations.new(nil, nil, self), Form::Sales::Questions::LaNominations.new(nil, nil, self),
] ]
end end
def routed_to?(log, _current_user)
return false if log.staircase == 1 && log.form.start_year_after_2024?
super
end
end end

4
app/models/sales_log.rb

@ -477,4 +477,8 @@ class SalesLog < Log
def nationality2_uk_or_prefers_not_to_say? def nationality2_uk_or_prefers_not_to_say?
nationality_all_buyer2_group&.zero? || nationality_all_buyer2_group == 826 nationality_all_buyer2_group&.zero? || nationality_all_buyer2_group == 826
end end
def is_staircase?
staircase == 1
end
end end

57
spec/models/form/sales/pages/buyer_previous_spec.rb

@ -3,11 +3,21 @@ require "rails_helper"
RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase:) } subject(:page) { described_class.new(page_id, page_definition, subsection, joint_purchase:) }
let(:log) { create(:sales_log, :completed) }
let(:page_id) { "example" } let(:page_id) { "example" }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
let(:form) { instance_double(Form) }
let(:joint_purchase) { false } let(:joint_purchase) { false }
before do
allow(subsection).to receive(:depends_on).and_return(nil)
allow(subsection).to receive(:enabled?).and_return(true)
allow(subsection).to receive(:form).and_return(form)
allow(form).to receive(:depends_on_met).and_return(true)
end
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end end
@ -41,4 +51,51 @@ RSpec.describe Form::Sales::Pages::BuyerPrevious, type: :model do
expect(page.depends_on).to eq([{ "joint_purchase?" => false }]) expect(page.depends_on).to eq([{ "joint_purchase?" => false }])
end end
end end
context "with 23/24 log" do
before do
Timecop.freeze(Time.zone.local(2023, 4, 2))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
it "has correct routed to" do
log.staircase = 1
expect(page.routed_to?(log, nil)).to eq(true)
end
end
context "with 24/25 log" do
before do
Timecop.freeze(Time.zone.local(2024, 4, 2))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
it "has correct routed to when staircase is yes" do
log.staircase = 1
expect(page.routed_to?(log, nil)).to eq(false)
end
it "has correct routed to when staircase is nil" do
log.staircase = nil
expect(page.routed_to?(log, nil)).to eq(true)
end
it "has correct routed to when staircase is no" do
log.staircase = 2
expect(page.routed_to?(log, nil)).to eq(true)
end
it "has correct routed to when staircase is don't know" do
log.staircase = 3
expect(page.routed_to?(log, nil)).to eq(true)
end
end
end end

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

@ -3,10 +3,16 @@ require "rails_helper"
RSpec.describe Form::Sales::Pages::LaNominations, type: :model do RSpec.describe Form::Sales::Pages::LaNominations, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) } subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:log) { create(:sales_log, :completed) }
let(:page_id) { nil } let(:page_id) { nil }
let(:page_definition) { nil } let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) } let(:subsection) { instance_double(Form::Subsection) }
before do
allow(subsection).to receive(:depends_on).and_return(nil)
end
it "has correct subsection" do it "has correct subsection" do
expect(page.subsection).to eq(subsection) expect(page.subsection).to eq(subsection)
end end
@ -26,4 +32,51 @@ RSpec.describe Form::Sales::Pages::LaNominations, type: :model do
it "has the correct description" do it "has the correct description" do
expect(page.description).to be_nil expect(page.description).to be_nil
end end
context "with 23/24 log" do
before do
Timecop.freeze(Time.zone.local(2023, 4, 2))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
it "has correct routed to" do
log.staircase = 1
expect(page.routed_to?(log, nil)).to eq(true)
end
end
context "with 24/25 log" do
before do
Timecop.freeze(Time.zone.local(2024, 4, 2))
Singleton.__init__(FormHandler)
end
after do
Timecop.return
end
it "has correct routed to when staircase is yes" do
log.staircase = 1
expect(page.routed_to?(log, nil)).to eq(false)
end
it "has correct routed to when staircase is nil" do
log.staircase = nil
expect(page.routed_to?(log, nil)).to eq(true)
end
it "has correct routed to when staircase is no" do
log.staircase = 2
expect(page.routed_to?(log, nil)).to eq(true)
end
it "has correct routed to when staircase is don't know" do
log.staircase = 3
expect(page.routed_to?(log, nil)).to eq(true)
end
end
end end

Loading…
Cancel
Save