Browse Source

feat: add feature flag

pull/1318/head
natdeanlewissoftwire 2 years ago
parent
commit
ba2124eb08
  1. 2
      app/models/validations/setup_validations.rb
  2. 4
      config/initializers/feature_toggle.rb
  3. 24
      spec/models/validations/setup_validations_spec.rb

2
app/models/validations/setup_validations.rb

@ -5,7 +5,7 @@ module Validations::SetupValidations
def validate_startdate_setup(record) def validate_startdate_setup(record)
return unless record.startdate && date_valid?("startdate", record) return unless record.startdate && date_valid?("startdate", record)
unless record.startdate.between?(active_collection_start_date, current_collection_end_date) if FeatureToggle.startdate_validation_enabled? && !record.startdate.between?(active_collection_start_date, current_collection_end_date)
record.errors.add :startdate, validation_error_message record.errors.add :startdate, validation_error_message
end end
end end

4
config/initializers/feature_toggle.rb

@ -8,6 +8,10 @@ class FeatureToggle
Rails.env.production? || Rails.env.test? || Rails.env.staging? Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end
def self.startdate_validation_enabled?
!Rails.env.test?
end
def self.startdate_two_week_validation_enabled? def self.startdate_two_week_validation_enabled?
Rails.env.production? || Rails.env.test? || Rails.env.staging? Rails.env.production? || Rails.env.test? || Rails.env.staging?
end end

24
spec/models/validations/setup_validations_spec.rb

@ -6,6 +6,10 @@ RSpec.describe Validations::SetupValidations do
let(:setup_validator_class) { Class.new { include Validations::SetupValidations } } let(:setup_validator_class) { Class.new { include Validations::SetupValidations } }
let(:record) { FactoryBot.create(:lettings_log) } let(:record) { FactoryBot.create(:lettings_log) }
before do
allow(FeatureToggle).to receive(:startdate_validation_enabled?).and_return(true)
end
describe "tenancy start date" do describe "tenancy start date" do
context "when in 22/23 collection" do context "when in 22/23 collection" do
context "when in the crossover period" do context "when in the crossover period" do
@ -94,7 +98,7 @@ RSpec.describe Validations::SetupValidations do
record.irproduct_other = nil record.irproduct_other = nil
setup_validator.validate_irproduct_other(record) setup_validator.validate_irproduct_other(record)
expect(record.errors["irproduct_other"]) expect(record.errors["irproduct_other"])
.to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank"))
end end
it "adds an error when the intermediate rent product name is blank but the rent type was given as other intermediate rent product" do it "adds an error when the intermediate rent product name is blank but the rent type was given as other intermediate rent product" do
@ -102,7 +106,7 @@ RSpec.describe Validations::SetupValidations do
record.irproduct_other = "" record.irproduct_other = ""
setup_validator.validate_irproduct_other(record) setup_validator.validate_irproduct_other(record)
expect(record.errors["irproduct_other"]) expect(record.errors["irproduct_other"])
.to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank")) .to include(match I18n.t("validations.setup.intermediate_rent_product_name.blank"))
end end
it "Does not add an error when the intermediate rent product name is provided and the rent type was given as other intermediate rent product" do it "Does not add an error when the intermediate rent product name is provided and the rent type was given as other intermediate rent product" do
@ -128,7 +132,7 @@ RSpec.describe Validations::SetupValidations do
record.location = location record.location = location
setup_validator.validate_scheme(record) setup_validator.validate_scheme(record)
expect(record.errors["scheme_id"]) expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022")) .to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022"))
end end
it "produces no error when tenancy start date is during an active location period" do it "produces no error when tenancy start date is during an active location period" do
@ -153,7 +157,7 @@ RSpec.describe Validations::SetupValidations do
record.location = location record.location = location
setup_validator.validate_scheme(record) setup_validator.validate_scheme(record)
expect(record.errors["scheme_id"]) expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022")) .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022"))
end end
it "produces no error when tenancy start date is during an active location period" do it "produces no error when tenancy start date is during an active location period" do
@ -180,7 +184,7 @@ RSpec.describe Validations::SetupValidations do
record.location = location record.location = location
setup_validator.validate_scheme(record) setup_validator.validate_scheme(record)
expect(record.errors["scheme_id"]) expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022")) .to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022"))
end end
end end
@ -197,7 +201,7 @@ RSpec.describe Validations::SetupValidations do
record.scheme = scheme record.scheme = scheme
setup_validator.validate_scheme(record) setup_validator.validate_scheme(record)
expect(record.errors["scheme_id"]) expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 August 2022")) .to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 August 2022"))
end end
it "produces no error when tenancy start date is during an active scheme period" do it "produces no error when tenancy start date is during an active scheme period" do
@ -223,7 +227,7 @@ RSpec.describe Validations::SetupValidations do
record.scheme = scheme record.scheme = scheme
setup_validator.validate_scheme(record) setup_validator.validate_scheme(record)
expect(record.errors["scheme_id"]) expect(record.errors["scheme_id"])
.to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 September 2022")) .to include(match I18n.t("validations.setup.startdate.scheme.reactivating_soon", name: scheme.service_name, date: "4 September 2022"))
end end
it "produces no error when tenancy start date is during an active scheme period" do it "produces no error when tenancy start date is during an active scheme period" do
@ -250,7 +254,7 @@ RSpec.describe Validations::SetupValidations do
record.location = location record.location = location
setup_validator.validate_location(record) setup_validator.validate_location(record)
expect(record.errors["location_id"]) expect(record.errors["location_id"])
.to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022")) .to include(match I18n.t("validations.setup.startdate.location.deactivated", postcode: location.postcode, date: "4 June 2022"))
end end
it "produces no error when tenancy start date is during an active location period" do it "produces no error when tenancy start date is during an active location period" do
@ -275,7 +279,7 @@ RSpec.describe Validations::SetupValidations do
record.location = location record.location = location
setup_validator.validate_location(record) setup_validator.validate_location(record)
expect(record.errors["location_id"]) expect(record.errors["location_id"])
.to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022")) .to include(match I18n.t("validations.setup.startdate.location.reactivating_soon", postcode: location.postcode, date: "4 August 2022"))
end end
it "produces no error when tenancy start date is during an active location period" do it "produces no error when tenancy start date is during an active location period" do
@ -302,7 +306,7 @@ RSpec.describe Validations::SetupValidations do
record.location = location record.location = location
setup_validator.validate_location(record) setup_validator.validate_location(record)
expect(record.errors["location_id"]) expect(record.errors["location_id"])
.to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022")) .to include(match I18n.t("validations.setup.startdate.location.activating_soon", postcode: location.postcode, date: "15 September 2022"))
end end
end end
end end

Loading…
Cancel
Save