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. 8
      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. 122
      spec/features/bulk_upload_lettings_logs_spec.rb
  13. 90
      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"),

8
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
@ -63,10 +63,10 @@ module Forms
true true
end end
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

122
spec/features/bulk_upload_lettings_logs_spec.rb

@ -22,94 +22,108 @@ 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")
expect(page).to have_content("Which year") expect(page).to have_content("Which year")
click_button("Continue") click_button("Continue")
expect(page).to have_content("You must select a collection period to upload for") expect(page).to have_content("You must select a collection period to upload for")
choose("2023/2024") choose("2023/2024")
click_button("Continue") click_button("Continue")
click_link("Back") click_link("Back")
expect(page.find_field("form-year-2023-field")).to be_checked expect(page.find_field("form-year-2023-field")).to be_checked
click_button("Continue") click_button("Continue")
expect(page).to have_content("Upload lettings logs in bulk (2023/24)") expect(page).to have_content("Upload lettings logs in bulk (2023/24)")
click_button("Continue") click_button("Continue")
expect(page).not_to have_content("What is the needs type?") expect(page).not_to have_content("What is the needs type?")
expect(page).to have_content("Upload lettings logs in bulk (2023/24)") expect(page).to have_content("Upload lettings logs in bulk (2023/24)")
expect(page).to have_content("Upload your file") expect(page).to have_content("Upload your file")
click_button("Upload") click_button("Upload")
allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv") allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("not a csv")
expect(page).to have_content("Select which file to upload") expect(page).to have_content("Select which file to upload")
attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx") attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx")
click_button("Upload") click_button("Upload")
allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv") allow_any_instance_of(Forms::BulkUploadLettings::UploadYourFile).to receive(:`).and_return("text/csv")
expect(page).to have_content("Your file must be in CSV format") expect(page).to have_content("Your file must be in CSV format")
attach_file "file", file_fixture("blank_bulk_upload_sales.csv") attach_file "file", file_fixture("blank_bulk_upload_sales.csv")
expect { expect {
click_button("Upload") click_button("Upload")
}.to change(BulkUpload, :count).by(1) }.to change(BulkUpload, :count).by(1)
expect(page).to have_content("Once this is done") expect(page).to have_content("Once this is done")
click_link("Back") click_link("Back")
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")
expect(page).to have_content("Upload lettings logs in bulk (2023/24)") expect(page).to have_content("Upload lettings logs in bulk (2023/24)")
click_button("Continue") click_button("Continue")
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")
expect(page).to have_content("Prepare your file") expect(page).to have_content("Prepare your file")
click_button("Continue") click_button("Continue")
click_link("Back") click_link("Back")
expect(page).to have_content("Prepare your file") expect(page).to have_content("Prepare your file")
click_button("Continue") click_button("Continue")
expect(page).to have_content("Upload lettings logs in bulk (2023/24)") expect(page).to have_content("Upload lettings logs in bulk (2023/24)")
expect(page).to have_content("Upload your file") expect(page).to have_content("Upload your file")
click_button("Upload") click_button("Upload")
end
end end
end end
end end

90
spec/features/bulk_upload_sales_logs_spec.rb

@ -22,68 +22,76 @@ 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")
expect(page).to have_content("Which year") expect(page).to have_content("Which year")
click_button("Continue") click_button("Continue")
expect(page).to have_content("You must select a collection period to upload for") expect(page).to have_content("You must select a collection period to upload for")
choose("2023/2024") choose("2023/2024")
click_button("Continue") click_button("Continue")
click_link("Back") click_link("Back")
expect(page.find_field("form-year-2023-field")).to be_checked expect(page.find_field("form-year-2023-field")).to be_checked
click_button("Continue") click_button("Continue")
expect(page).to have_content("Upload sales logs in bulk (2023/24)") expect(page).to have_content("Upload sales logs in bulk (2023/24)")
click_button("Continue") click_button("Continue")
expect(page).to have_content("Upload your file") expect(page).to have_content("Upload your file")
click_button("Upload") click_button("Upload")
allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("not a csv") allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("not a csv")
expect(page).to have_content("Select which file to upload") expect(page).to have_content("Select which file to upload")
attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx") attach_file "file", file_fixture("2023_24_lettings_bulk_upload.xlsx")
click_button("Upload") click_button("Upload")
allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv") allow_any_instance_of(Forms::BulkUploadSales::UploadYourFile).to receive(:`).and_return("text/csv")
expect(page).to have_content("Your file must be in CSV format") expect(page).to have_content("Your file must be in CSV format")
attach_file "file", file_fixture("blank_bulk_upload_sales.csv") attach_file "file", file_fixture("blank_bulk_upload_sales.csv")
expect { expect {
click_button("Upload") click_button("Upload")
}.to change(BulkUpload, :count).by(1) }.to change(BulkUpload, :count).by(1)
expect(page).to have_content("Once this is done") expect(page).to have_content("Once this is done")
click_link("Back") click_link("Back")
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)
visit("/sales-logs") end
expect(page).to have_link("Upload sales logs in bulk")
click_link("Upload sales logs in bulk") after do
Timecop.return
end
it "shows journey without year option" do
visit("/sales-logs")
expect(page).to have_link("Upload sales logs in bulk")
click_link("Upload sales logs in bulk")
expect(page).to have_content("Upload sales logs in bulk (2023/24)") expect(page).to have_content("Upload sales logs in bulk (2023/24)")
click_button("Continue") click_button("Continue")
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