Browse Source

CLDC-3363 Uneditable sales log redirect bug fix (#2353)

* feat: make check_collection_period log type specific

* feat: test check_collection_period routing
pull/2354/head^2
natdeanlewissoftwire 9 months ago committed by GitHub
parent
commit
43c0f457c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/controllers/form_controller.rb
  2. 104
      spec/requests/form_controller_spec.rb

4
app/controllers/form_controller.rb

@ -250,7 +250,9 @@ private
def check_collection_period
return unless @log
redirect_to lettings_log_path(@log) unless @log.collection_period_open_for_editing?
unless @log.collection_period_open_for_editing?
redirect_to @log.lettings? ? lettings_log_path(@log) : sales_log_path(@log)
end
end
CONFIRMATION_PAGE_IDS = %w[uprn_confirmation uprn_selection].freeze

104
spec/requests/form_controller_spec.rb

@ -358,6 +358,12 @@ RSpec.describe FormController, type: :request do
created_by: user,
)
end
let!(:sales_log) do
create(
:sales_log,
created_by: user,
)
end
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
@ -612,6 +618,104 @@ RSpec.describe FormController, type: :request do
expect(page).to have_content("There is a problem")
end
end
context "when allow_future_form_use? is enabled" do
before do
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(true)
end
context "when the tenancy start date is out of the editable collection year" do
let(:page_id) { "tenancy_start_date" }
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: page_id,
"startdate(3i)" => 1,
"startdate(2i)" => 1,
"startdate(1i)" => 1,
},
}
end
it "redirects to the review page for the log" do
post "/lettings-logs/#{lettings_log.id}/#{page_id.dasherize}", params: params
follow_redirect!
follow_redirect!
follow_redirect!
expect(page).to have_content("Review lettings log")
end
end
context "when the sale date is out of the editable collection year" do
let(:page_id) { "completion_date" }
let(:params) do
{
id: sales_log.id,
sales_log: {
page: page_id,
"saledate(3i)" => 1,
"saledate(2i)" => 1,
"saledate(1i)" => 1,
},
}
end
it "redirects to the review page for the log" do
post "/sales-logs/#{sales_log.id}/#{page_id.dasherize}", params: params
follow_redirect!
follow_redirect!
follow_redirect!
expect(page).to have_content("Review sales log")
end
end
end
context "when allow_future_form_use? is disabled" do
before do
allow(FeatureToggle).to receive(:allow_future_form_use?).and_return(false)
end
context "when the tenancy start date is out of the editable collection year" do
let(:page_id) { "tenancy_start_date" }
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: page_id,
"startdate(3i)" => 1,
"startdate(2i)" => 1,
"startdate(1i)" => 1,
},
}
end
it "validates the date correctly" do
post "/lettings-logs/#{lettings_log.id}/#{page_id.dasherize}", params: params
expect(page).to have_content("There is a problem")
end
end
context "when the sale date is out of the editable collection year" do
let(:page_id) { "completion_date" }
let(:params) do
{
id: sales_log.id,
sales_log: {
page: page_id,
"saledate(3i)" => 1,
"saledate(2i)" => 1,
"saledate(1i)" => 1,
},
}
end
it "validates the date correctly" do
post "/sales-logs/#{sales_log.id}/#{page_id.dasherize}", params: params
expect(page).to have_content("There is a problem")
end
end
end
end
context "with invalid organisation answers" do

Loading…
Cancel
Save