Browse Source

CLDC-3264: Setup to allow using future form on staging for testing

pull/2279/head
Rachael Booth 2 years ago
parent
commit
4aead1b035
  1. 6
      app/controllers/bulk_upload_lettings_logs_controller.rb
  2. 8
      app/controllers/bulk_upload_sales_logs_controller.rb
  3. 12
      app/models/form_handler.rb
  4. 6
      app/models/forms/bulk_upload_lettings/prepare_your_file.rb
  5. 5
      app/models/forms/bulk_upload_lettings/year.rb
  6. 6
      app/models/forms/bulk_upload_sales/prepare_your_file.rb
  7. 6
      app/models/forms/bulk_upload_sales/year.rb
  8. 2
      app/models/validations/date_validations.rb
  9. 4
      app/models/validations/sales/setup_validations.rb
  10. 2
      app/models/validations/setup_validations.rb
  11. 21
      app/services/feature_toggle.rb
  12. 28
      spec/features/bulk_upload_lettings_logs_spec.rb
  13. 22
      spec/features/bulk_upload_sales_logs_spec.rb

6
app/controllers/bulk_upload_lettings_logs_controller.rb

@ -3,7 +3,7 @@ class BulkUploadLettingsLogsController < ApplicationController
before_action :validate_data_protection_agrement_signed! before_action :validate_data_protection_agrement_signed!
def start def start
if in_crossover_period? if have_choice_of_year?
redirect_to bulk_upload_lettings_log_path(id: "year") redirect_to bulk_upload_lettings_log_path(id: "year")
else else
redirect_to bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: current_year }) redirect_to bulk_upload_lettings_log_path(id: "prepare-your-file", form: { year: current_year })
@ -34,8 +34,8 @@ private
FormHandler.instance.current_collection_start_year FormHandler.instance.current_collection_start_year
end end
def in_crossover_period? def have_choice_of_year?
return true if FeatureToggle.force_crossover? return true if FeatureToggle.allow_future_form_use?
FormHandler.instance.lettings_in_crossover_period? FormHandler.instance.lettings_in_crossover_period?
end end

8
app/controllers/bulk_upload_sales_logs_controller.rb

@ -3,7 +3,7 @@ class BulkUploadSalesLogsController < ApplicationController
before_action :validate_data_protection_agrement_signed! before_action :validate_data_protection_agrement_signed!
def start def start
if in_crossover_period? if have_choice_of_year?
redirect_to bulk_upload_sales_log_path(id: "year") redirect_to bulk_upload_sales_log_path(id: "year")
else else
redirect_to bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: current_year }) redirect_to bulk_upload_sales_log_path(id: "prepare-your-file", form: { year: current_year })
@ -31,11 +31,11 @@ private
end end
def current_year def current_year
FormHandler.instance.forms["current_sales"].start_date.year FormHandler.instance.current_collection_start_year
end end
def in_crossover_period? def have_choice_of_year?
return true if FeatureToggle.force_crossover? return true if FeatureToggle.allow_future_form_use?
FormHandler.instance.sales_in_crossover_period? FormHandler.instance.sales_in_crossover_period?
end end

12
app/models/form_handler.rb

@ -32,10 +32,22 @@ class FormHandler
forms["previous_lettings"] forms["previous_lettings"]
end end
def next_lettings_form
forms["next_lettings"]
end
def current_sales_form def current_sales_form
forms["current_sales"] forms["current_sales"]
end end
def previous_sales_form
forms["previous_sales"]
end
def next_sales_form
forms["next_sales"]
end
def sales_forms def sales_forms
@sales_forms ||= { @sales_forms ||= {
"current_sales" => Form.new(nil, current_collection_start_year, SALES_SECTIONS, "sales"), "current_sales" => Form.new(nil, current_collection_start_year, SALES_SECTIONS, "sales"),

6
app/models/forms/bulk_upload_lettings/prepare_your_file.rb

@ -18,7 +18,7 @@ module Forms
end end
def back_path def back_path
if in_crossover_period? if have_choice_of_year?
Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year: }) Rails.application.routes.url_helpers.bulk_upload_lettings_log_path(id: "year", form: { year: })
else else
Rails.application.routes.url_helpers.lettings_logs_path Rails.application.routes.url_helpers.lettings_logs_path
@ -65,8 +65,8 @@ module Forms
private private
def in_crossover_period? def have_choice_of_year?
return true if FeatureToggle.force_crossover? return true if FeatureToggle.allow_future_form_use?
FormHandler.instance.lettings_in_crossover_period? FormHandler.instance.lettings_in_crossover_period?
end end

5
app/models/forms/bulk_upload_lettings/year.rb

@ -36,8 +36,9 @@ module Forms
def possible_years def possible_years
[ [
FormHandler.instance.lettings_forms["current_lettings"].start_date.year, FormHandler.instance.lettings_forms["current_lettings"].start_date.year,
FormHandler.instance.lettings_forms["previous_lettings"].start_date.year, (FormHandler.instance.previous_lettings_form.start_date.year if FormHandler.instance.lettings_in_crossover_period?),
] (FormHandler.instance.next_lettings_form.start_date.year if FeatureToggle.allow_future_form_use?),
].compact
end end
end end
end end

6
app/models/forms/bulk_upload_sales/prepare_your_file.rb

@ -17,7 +17,7 @@ module Forms
end end
def back_path def back_path
if in_crossover_period? if have_choice_of_year?
Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: }) Rails.application.routes.url_helpers.bulk_upload_sales_log_path(id: "year", form: { year: })
else else
Rails.application.routes.url_helpers.sales_logs_path Rails.application.routes.url_helpers.sales_logs_path
@ -63,8 +63,8 @@ module Forms
private private
def in_crossover_period? def have_choice_of_year?
return true if FeatureToggle.force_crossover? return true if FeatureToggle.allow_future_form_use?
FormHandler.instance.sales_in_crossover_period? FormHandler.instance.sales_in_crossover_period?
end end

6
app/models/forms/bulk_upload_sales/year.rb

@ -34,7 +34,11 @@ module Forms
private private
def possible_years def possible_years
[FormHandler.instance.sales_forms["current_sales"].start_date.year, FormHandler.instance.sales_forms["previous_sales"].start_date.year] [
FormHandler.instance.current_sales_form.start_date.year,
(FormHandler.instance.previous_sales_form.start_date.year if FormHandler.instance.sales_in_crossover_period?),
(FormHandler.instance.next_sales_form.start_date.year if FeatureToggle.allow_future_form_use?),
].compact
end end
end end
end end

2
app/models/validations/date_validations.rb

@ -34,7 +34,7 @@ module Validations::DateValidations
def validate_startdate(record) def validate_startdate(record)
return unless record.startdate && date_valid?("startdate", record) return unless record.startdate && date_valid?("startdate", record)
if FeatureToggle.startdate_two_week_validation_enabled? && record.startdate > Time.zone.today + 14.days if !FeatureToggle.allow_future_form_use? && record.startdate > Time.zone.today + 14.days
record.errors.add :startdate, I18n.t("validations.setup.startdate.later_than_14_days_after") record.errors.add :startdate, I18n.t("validations.setup.startdate.later_than_14_days_after")
end end

4
app/models/validations/sales/setup_validations.rb

@ -3,7 +3,7 @@ module Validations::Sales::SetupValidations
include CollectionTimeHelper include CollectionTimeHelper
def validate_saledate_collection_year(record) def validate_saledate_collection_year(record)
return unless record.saledate && date_valid?("saledate", record) && FeatureToggle.saledate_collection_window_validation_enabled? return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use?
first_collection_start_date = if record.saledate_was.present? first_collection_start_date = if record.saledate_was.present?
editable_collection_start_date editable_collection_start_date
@ -17,7 +17,7 @@ module Validations::Sales::SetupValidations
end end
def validate_saledate_two_weeks(record) def validate_saledate_two_weeks(record)
return unless record.saledate && date_valid?("saledate", record) && FeatureToggle.saledate_two_week_validation_enabled? return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use?
if record.saledate > Time.zone.today + 14.days if record.saledate > Time.zone.today + 14.days
record.errors.add :saledate, I18n.t("validations.setup.saledate.later_than_14_days_after") record.errors.add :saledate, I18n.t("validations.setup.saledate.later_than_14_days_after")

2
app/models/validations/setup_validations.rb

@ -3,7 +3,7 @@ module Validations::SetupValidations
include CollectionTimeHelper include CollectionTimeHelper
def validate_startdate_setup(record) def validate_startdate_setup(record)
return unless record.startdate && date_valid?("startdate", record) && FeatureToggle.startdate_collection_window_validation_enabled? return unless record.startdate && date_valid?("startdate", record) && !FeatureToggle.allow_future_form_use?
first_collection_start_date = if record.startdate_was.present? first_collection_start_date = if record.startdate_was.present?
editable_collection_start_date editable_collection_start_date

21
app/services/feature_toggle.rb

@ -1,19 +1,6 @@
class FeatureToggle class FeatureToggle
# Disable check on preview apps to allow for testing of future forms def self.allow_future_form_use?
def self.saledate_collection_window_validation_enabled? Rails.env.development? || Rails.env.review? || Rails.env.staging?
Rails.env.production? || Rails.env.test? || Rails.env.staging?
end
def self.startdate_collection_window_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging?
end
def self.startdate_two_week_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging?
end
def self.saledate_two_week_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end
def self.bulk_upload_duplicate_log_check_enabled? def self.bulk_upload_duplicate_log_check_enabled?
@ -24,10 +11,6 @@ class FeatureToggle
!Rails.env.development? !Rails.env.development?
end end
def self.force_crossover?
false
end
def self.deduplication_flow_enabled? def self.deduplication_flow_enabled?
true true
end end

28
spec/features/bulk_upload_lettings_logs_spec.rb

@ -22,11 +22,14 @@ RSpec.describe "Bulk upload lettings log" do
# rubocop:disable RSpec/AnyInstance # rubocop:disable RSpec/AnyInstance
context "when during crossover period" do context "when during crossover period" do
before do before do
allow(FeatureToggle).to receive(:force_crossover?).and_return(true) Timecop.freeze(2023, 6, 1)
end
after do
Timecop.return
end end
it "shows journey with year option" do it "shows journey with year option" do
Timecop.freeze(2023, 6, 1) do
visit("/lettings-logs") visit("/lettings-logs")
expect(page).to have_link("Upload lettings logs in bulk") expect(page).to have_link("Upload lettings logs in bulk")
click_link("Upload lettings logs in bulk") click_link("Upload lettings logs in bulk")
@ -72,12 +75,18 @@ RSpec.describe "Bulk upload lettings log" do
expect(page).to have_content("Upload lettings logs in bulk") expect(page).to have_content("Upload lettings logs in bulk")
end end
end end
end
# rubocop:enable RSpec/AnyInstance # rubocop:enable RSpec/AnyInstance
context "when not it crossover period" do context "when not it crossover period" do
before do
Timecop.freeze(2024, 1, 1)
end
after do
Timecop.return
end
it "shows journey with year option" do it "shows journey with year option" do
Timecop.freeze(2024, 1, 1) do
visit("/lettings-logs") visit("/lettings-logs")
expect(page).to have_link("Upload lettings logs in bulk") expect(page).to have_link("Upload lettings logs in bulk")
click_link("Upload lettings logs in bulk") click_link("Upload lettings logs in bulk")
@ -88,11 +97,17 @@ RSpec.describe "Bulk upload lettings log" do
expect(page).to have_content("Upload your file") expect(page).to have_content("Upload your file")
end end
end end
end
context "when the collection year isn't 22/23" do context "when the collection year isn't 22/23" do
before do
Timecop.freeze(2024, 1, 1)
end
after do
Timecop.return
end
it "shows journey without the needstype" do it "shows journey without the needstype" do
Timecop.freeze(2024, 1, 1) do
visit("/lettings-logs") visit("/lettings-logs")
expect(page).to have_link("Upload lettings logs in bulk") expect(page).to have_link("Upload lettings logs in bulk")
click_link("Upload lettings logs in bulk") click_link("Upload lettings logs in bulk")
@ -111,5 +126,4 @@ RSpec.describe "Bulk upload lettings log" do
click_button("Upload") click_button("Upload")
end end
end end
end
end end

22
spec/features/bulk_upload_sales_logs_spec.rb

@ -22,11 +22,14 @@ RSpec.describe "Bulk upload sales log" do
# rubocop:disable RSpec/AnyInstance # rubocop:disable RSpec/AnyInstance
context "when during crossover period" do context "when during crossover period" do
before do before do
allow(FeatureToggle).to receive(:force_crossover?).and_return(true) Timecop.freeze(2023, 5, 1)
end
after do
Timecop.return
end end
it "shows journey with year option" do it "shows journey with year option" do
Timecop.freeze(2023, 5, 1) do
visit("/sales-logs") visit("/sales-logs")
expect(page).to have_link("Upload sales logs in bulk") expect(page).to have_link("Upload sales logs in bulk")
click_link("Upload sales logs in bulk") click_link("Upload sales logs in bulk")
@ -69,12 +72,18 @@ RSpec.describe "Bulk upload sales log" do
expect(page).to have_content("Upload sales logs in bulk") expect(page).to have_content("Upload sales logs in bulk")
end end
end end
end
# rubocop:enable RSpec/AnyInstance # rubocop:enable RSpec/AnyInstance
context "when not it crossover period" do context "when not in crossover period" do
xit "shows journey with year option" do before do
Timecop.freeze(2023, 10, 1) do Timecop.freeze(2024, 2, 1)
end
after do
Timecop.return
end
it "shows journey without year option" do
visit("/sales-logs") visit("/sales-logs")
expect(page).to have_link("Upload sales logs in bulk") expect(page).to have_link("Upload sales logs in bulk")
click_link("Upload sales logs in bulk") click_link("Upload sales logs in bulk")
@ -85,5 +94,4 @@ RSpec.describe "Bulk upload sales log" do
expect(page).to have_content("Upload your file") expect(page).to have_content("Upload your file")
end end
end end
end
end end

Loading…
Cancel
Save