Skip to content

Commit

Permalink
[CPDLP-3510] replaced rails config with Feature.ecf_api_disabled?
Browse files Browse the repository at this point in the history
  • Loading branch information
mooktakim committed Sep 25, 2024
1 parent 7d3949e commit d7d25de
Show file tree
Hide file tree
Showing 25 changed files with 30 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/models/external/ecf_api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module External
module EcfAPI
class ConnectionWithAuthHeader < JsonApiClient::Connection
def run(request_method, path, params: nil, headers: {}, body: nil)
raise JsonApiClient::Errors::ServiceUnavailable.new(@env, "EcfAPI service unavailable") if Rails.application.config.npq_separation[:ecf_api_disabled]
raise JsonApiClient::Errors::ServiceUnavailable.new(@env, "EcfAPI service unavailable") if Feature.ecf_api_disabled?

super(
request_method,
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_an_identity_user
end

def ecf_user
return if ecf_id.blank? || Rails.application.config.npq_separation[:ecf_api_disabled]
return if ecf_id.blank? || Feature.ecf_api_disabled?

External::EcfAPI::Npq::User.find(ecf_id).first
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/ecf/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Ecf
module Base
def call
return if Rails.application.config.npq_separation[:ecf_api_disabled]
return if Feature.ecf_api_disabled?

super
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/ecf/npq_profile_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def call
end

def tsf_data_field_update
return if Rails.application.config.npq_separation[:ecf_api_disabled]
return if Feature.ecf_api_disabled?

profile = External::EcfAPI::NpqProfile.find(application.ecf_id).first
profile.primary_establishment = application.primary_establishment
Expand Down
4 changes: 2 additions & 2 deletions app/services/funding_eligibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def possible_funding_for_non_pp50_and_fe?
end

def previously_received_targeted_funding_support?
return ecf_api_funding_lookup["previously_received_targeted_funding_support"] == true unless Rails.application.config.npq_separation[:ecf_api_disabled]
return ecf_api_funding_lookup["previously_received_targeted_funding_support"] == true unless Feature.ecf_api_disabled?

accepted_applications.with_targeted_delivery_funding_eligibility.any?
end
Expand Down Expand Up @@ -212,7 +212,7 @@ def trn_users
end

def previously_funded?
return ecf_api_funding_lookup["previously_funded"] == true unless Rails.application.config.npq_separation[:ecf_api_disabled]
return ecf_api_funding_lookup["previously_funded"] == true unless Feature.ecf_api_disabled?

accepted_applications.any?
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/participant_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(trn:, full_name:, date_of_birth:, national_insurance_number: nil)
end

def call
return if Rails.application.config.npq_separation[:ecf_api_disabled]
return if Feature.ecf_api_disabled?

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{config.bearer_token}"
Expand Down
1 change: 0 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
admin_portal_enabled: true,
api_enabled: true,
migration_enabled: true,
ecf_api_disabled: false,
}

# Disable origin check for Cross-Site Request Forgery (CSRF) protection for codespaces.
Expand Down
1 change: 0 additions & 1 deletion config/environments/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
admin_portal_enabled: true,
api_enabled: true,
migration_enabled: true,
ecf_api_disabled: true,
}
end
1 change: 0 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,5 @@
admin_portal_enabled: false,
api_enabled: false,
migration_enabled: false,
ecf_api_disabled: false,
}
end
1 change: 0 additions & 1 deletion config/environments/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
admin_portal_enabled: true,
api_enabled: true,
migration_enabled: true,
ecf_api_disabled: false,
}
end
1 change: 0 additions & 1 deletion config/environments/sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
admin_portal_enabled: false,
api_enabled: false,
migration_enabled: false,
ecf_api_disabled: false,
}
end
1 change: 0 additions & 1 deletion config/environments/separation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
admin_portal_enabled: true,
api_enabled: true,
migration_enabled: false,
ecf_api_disabled: true,
}
end
1 change: 0 additions & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
admin_portal_enabled: true,
api_enabled: true,
migration_enabled: true,
ecf_api_disabled: false,
}
end
1 change: 0 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
admin_portal_enabled: true,
api_enabled: true,
migration_enabled: true,
ecf_api_disabled: false,
}

config.dotenv.autorestore = false if config.respond_to?(:dotenv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
end

context "when ecf_api_disabled flag is toggled on" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(service.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/ecf/ecf_user_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
let(:response_code) { 201 }
let(:response_body) { "anything" }

before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/ecf/ecf_user_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
context "when ecf_api_disabled flag is toggled on" do
let(:response_body) { "anything" }

before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/ecf/ecf_user_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
let(:response_code) { 200 }
let(:response_body) { "anything" }

before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/ecf/npq_profile_creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
context "when ecf_api_disabled flag is toggled on" do
let(:response_code) { 200 }

before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/ecf/npq_profile_mass_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end

context "when ecf_api_disabled flag is toggled on" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/ecf/npq_profile_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
end

context "when ecf_api_disabled flag is toggled on" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/ecf/tsf_mass_data_field_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end

context "when ecf_api_disabled flag is toggled on" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
26 changes: 13 additions & 13 deletions spec/lib/services/funding_eligibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns true" do
expect(subject).to be_funded
Expand Down Expand Up @@ -82,7 +82,7 @@

context "when External::EcfAPI is disabled" do
before do
allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true })
allow(Feature).to receive(:ecf_api_disabled?).and_return(true)
user = create(:user, trn:)
create(:application, :previously_funded, user:, course:)
end
Expand Down Expand Up @@ -125,7 +125,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns true" do
expect(subject).to be_funded
Expand Down Expand Up @@ -166,7 +166,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns false" do
expect(subject).not_to be_funded
Expand Down Expand Up @@ -239,7 +239,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "is eligible" do
expect(subject).to be_funded
Expand All @@ -258,7 +258,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "is not eligible for #{course.identifier}" do
expect(subject).not_to be_funded
Expand All @@ -278,7 +278,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "is eligible" do
expect(subject).to be_funded
Expand All @@ -296,7 +296,7 @@

context "when External::EcfAPI is disabled" do
before do
allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true })
allow(Feature).to receive(:ecf_api_disabled?).and_return(true)
user = create(:user, trn:)
create(:application, :previously_funded, user:, course:)
end
Expand Down Expand Up @@ -325,7 +325,7 @@

context "when External::EcfAPI is disabled" do
before do
allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true })
allow(Feature).to receive(:ecf_api_disabled?).and_return(true)
user = create(:user, trn:)
create(:application, :previously_funded, user:, course:)
end
Expand All @@ -349,7 +349,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns status code :not_in_england" do
expect(subject.funding_eligiblity_status_code).to eq :not_in_england
Expand All @@ -373,7 +373,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns status code :early_years_invalid_npq" do
expect(subject.funding_eligiblity_status_code).to eq :early_years_invalid_npq
Expand All @@ -395,7 +395,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "is not eligible" do
expect(subject.funded?).to be false
Expand All @@ -417,7 +417,7 @@
end

context "when External::EcfAPI is disabled" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "is ineligible" do
expect(subject.funded?).to be false
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/services/participant_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
end

context "when ecf_api_disabled flag is toggled on" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(subject.call).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
end

context "when ecf_api_disabled flag is toggled on" do
before { allow(Rails.application.config).to receive(:npq_separation).and_return({ ecf_api_disabled: true }) }
before { allow(Feature).to receive(:ecf_api_disabled?).and_return(true) }

it "returns nil" do
expect(user.ecf_user).to be_nil
Expand Down

0 comments on commit d7d25de

Please sign in to comment.