Skip to content

Commit

Permalink
Merge pull request #5233 from DFE-Digital/3588-turn-off-npq-in-ecf-sw…
Browse files Browse the repository at this point in the history
…ap-out-app-config-for-feature-flag

[CPDLP-3588] Turn off NPQ in ECF - Swap out app config for feature flag
  • Loading branch information
mooktakim authored Oct 17, 2024
2 parents 2a7ee54 + bc15f4b commit f5381c8
Show file tree
Hide file tree
Showing 20 changed files with 136 additions and 87 deletions.
2 changes: 1 addition & 1 deletion app/services/api/participant_declarations/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def previous_declarations_scope
end

def declaration_class
if NpqApiEndpoint.disable_npq_endpoints?
if NpqApiEndpoint.disabled?
ParticipantDeclaration::ECF
else
ParticipantDeclaration
Expand Down
4 changes: 2 additions & 2 deletions app/services/api/v3/finance/statements_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def statement

def statement_class
if filter[:type].blank?
if NpqApiEndpoint.disable_npq_endpoints?
if NpqApiEndpoint.disabled?
return ::Finance::Statement::ECF
else
return ::Finance::Statement
Expand All @@ -49,7 +49,7 @@ def statement_class
when "ecf"
::Finance::Statement::ECF
when "npq"
if NpqApiEndpoint.disable_npq_endpoints?
if NpqApiEndpoint.disabled?
::Finance::Statement.none
else
::Finance::Statement::NPQ
Expand Down
2 changes: 1 addition & 1 deletion app/services/api/v3/participant_declarations_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def delivery_partner_ids
end

def declaration_class
if NpqApiEndpoint.disable_npq_endpoints?
if NpqApiEndpoint.disabled?
ParticipantDeclaration::ECF
else
ParticipantDeclaration
Expand Down
4 changes: 2 additions & 2 deletions app/services/feature_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def feature
}.with_indifferent_access.freeze

def self.activate(feature_name, **opts)
raise unless feature_name.in?(FEATURES)
raise "Unknown feature: #{feature_name}" unless feature_name.in?(FEATURES)

if opts.key?(:for).present?
sync_with_database_with_object(feature_name, opts[:for], true)
Expand All @@ -53,7 +53,7 @@ def self.deactivate(feature_name, **opts)
end

def self.active?(feature_name, **opts)
raise unless feature_name.in?(FEATURES)
raise "Unknown feature: #{feature_name}" unless feature_name.in?(FEATURES)

feature = FEATURES[feature_name].feature
feature.active? || (opts.key?(:for) && feature.selected_objects.exists?(object: opts[:for]))
Expand Down
2 changes: 1 addition & 1 deletion app/services/record_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def check_mentor_completion
end

def validate_if_npq_course_supported
return unless NpqApiEndpoint.disable_npq_endpoints?
return unless NpqApiEndpoint.disabled?

if course_identifier.to_s.starts_with?("npq-")
errors.add(:course_identifier, I18n.t(:npq_course_no_longer_supported))
Expand Down
2 changes: 1 addition & 1 deletion app/services/void_participant_declaration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def line_item
end

def check_if_npq_course_supported
return unless NpqApiEndpoint.disable_npq_endpoints?
return unless NpqApiEndpoint.disabled?

if participant_declaration.npq?
raise Api::Errors::InvalidTransitionError, I18n.t(:npq_course_no_longer_supported)
Expand Down
7 changes: 0 additions & 7 deletions config/environments/separation.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# frozen_string_literal: true

require Rails.root.join("config/environments/sandbox")

Rails.application.configure do
# Enable/disable aspects of the separation environment
config.npq_separation = {
disable_npq_endpoints: true,
}
end
8 changes: 3 additions & 5 deletions lib/npq_api_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

class NpqApiEndpoint
def self.matches?(_request)
!disable_npq_endpoints?
!disabled?
end

def self.disable_npq_endpoints?
return false unless Rails.application.config.respond_to?(:npq_separation)

!!(Rails.application.config.npq_separation || {})[:disable_npq_endpoints]
def self.disabled?
FeatureFlag.active?(:disable_npq)
end
end
26 changes: 12 additions & 14 deletions spec/lib/npq_api_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,48 @@
require "npq_api_endpoint"

RSpec.describe NpqApiEndpoint do
before { Rails.application.config.npq_separation = nil }

describe ".matches?" do
let(:request) { instance_double(ActionDispatch::Request) }

it "returns true by default" do
expect(described_class.matches?(request)).to be_truthy
end

describe "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns false" do
expect(described_class.matches?(request)).to be_falsy
end
end

describe "when disable_npq_endpoints is false" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: false } }
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns true" do
expect(described_class.matches?(request)).to be_truthy
end
end
end

describe ".disable_npq_endpoints?" do
describe ".disabled?" do
it "returns false by default" do
expect(described_class.disable_npq_endpoints?).to be_falsy
expect(described_class.disabled?).to be_falsy
end

describe "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns true" do
expect(described_class.disable_npq_endpoints?).to be_truthy
expect(described_class.disabled?).to be_truthy
end
end

describe "when disable_npq_endpoints is false" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: false } }
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns false" do
expect(described_class.disable_npq_endpoints?).to be_falsy
expect(described_class.disabled?).to be_falsy
end
end
end
Expand Down
4 changes: 0 additions & 4 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@
config.before do
Faker::Number.unique.clear
enqueued_jobs.clear

# Enable/disable aspects of the separation environment
# We reset to default before each test
Rails.application.config.npq_separation = nil
end
config.include Devise::Test::IntegrationHelpers, type: :request
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
Expand Down
10 changes: 6 additions & 4 deletions spec/requests/api/v1/participant_declarations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when using 'disable_npq' feature" do
let(:cpd_lead_provider) { create(:cpd_lead_provider, :with_lead_provider, :with_npq_lead_provider) }
let(:npq_course) { create(:npq_leadership_course) }
let(:course_identifier) { npq_course.identifier }
Expand All @@ -661,8 +661,8 @@
end
let!(:contract) { create(:npq_contract, npq_course:, npq_lead_provider: cpd_lead_provider.npq_lead_provider) }

context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns error response" do
post "/api/v1/participant-declarations", params: params.to_json
Expand All @@ -675,7 +675,9 @@
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns ok response" do
post "/api/v1/participant-declarations", params: params.to_json

Expand Down
10 changes: 6 additions & 4 deletions spec/requests/api/v2/participant_declarations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def build_params(attributes)
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when using 'disable_npq' feature" do
let(:cpd_lead_provider) { create(:cpd_lead_provider, :with_lead_provider, :with_npq_lead_provider) }
let(:npq_course) { create(:npq_leadership_course) }
let(:course_identifier) { npq_course.identifier }
Expand All @@ -371,8 +371,8 @@ def build_params(attributes)
}
end

context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns error response" do
post "/api/v2/participant-declarations", params: params.to_json
Expand All @@ -385,7 +385,9 @@ def build_params(attributes)
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns ok response" do
post "/api/v2/participant-declarations", params: params.to_json

Expand Down
30 changes: 18 additions & 12 deletions spec/requests/api/v3/participant_declarations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when using 'disable_npq' feature" do
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns empty declarations" do
get "/api/v3/participant-declarations"
Expand All @@ -310,7 +310,9 @@
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns npq declarations" do
get "/api/v3/participant-declarations"

Expand Down Expand Up @@ -368,9 +370,9 @@
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when using 'disable_npq' feature" do
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns only ecf declarations" do
get "/api/v3/participant-declarations"
Expand All @@ -384,7 +386,9 @@
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns both ecf and npq declarations" do
get "/api/v3/participant-declarations"

Expand Down Expand Up @@ -718,7 +722,7 @@ def build_params(attributes)
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when using 'disable_npq' feature" do
let(:cpd_lead_provider) { create(:cpd_lead_provider, :with_lead_provider, :with_npq_lead_provider) }
let(:npq_course) { create(:npq_leadership_course) }
let(:course_identifier) { npq_course.identifier }
Expand All @@ -741,8 +745,8 @@ def build_params(attributes)
}
end

context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns error response" do
post "/api/v3/participant-declarations", params: params.to_json
Expand All @@ -755,7 +759,9 @@ def build_params(attributes)
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns ok response" do
post "/api/v3/participant-declarations", params: params.to_json

Expand Down
10 changes: 6 additions & 4 deletions spec/services/api/participant_declarations/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when using 'disable_npq' feature" do
let(:cpd_lead_provider) { create(:cpd_lead_provider, :with_lead_provider, :with_npq_lead_provider) }
let!(:npq_declaration) do
create(
Expand All @@ -116,15 +116,17 @@

subject { described_class.new(cpd_lead_provider:) }

context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns only ecf declarations" do
expect(subject.scope.to_a).to eql([ecf_declaration])
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns both declarations" do
expect(subject.scope.to_a).to eql([npq_declaration, ecf_declaration])
end
Expand Down
20 changes: 12 additions & 8 deletions spec/services/api/v3/finance/statements_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when using 'disable_npq' feature" do
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

it "returns only ECF statements" do
expect(subject.statements).to eq([
Expand All @@ -171,7 +171,9 @@
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

it "returns all statements" do
expect(subject.statements).to eq([
ecf_statement_next_cohort,
Expand Down Expand Up @@ -217,7 +219,7 @@
end
end

context "when using 'disable_npq_endpoints' feature" do
context "when using 'disable_npq' feature" do
let!(:npq_statement_next_cohort) do
create(
:npq_statement,
Expand All @@ -228,8 +230,8 @@
)
end

context "when disable_npq_endpoints is true" do
before { Rails.application.config.npq_separation = { disable_npq_endpoints: true } }
context "when 'disable_npq' feature is active" do
before { FeatureFlag.activate(:disable_npq) }

context "when requesting ECF statement" do
let(:params) { { id: ecf_statement_next_cohort.id } }
Expand All @@ -248,7 +250,9 @@
end
end

context "when disable_npq_endpoints is false" do
context "when 'disable_npq' feature is not active" do
before { FeatureFlag.deactivate(:disable_npq) }

context "when requesting ECF statement" do
let(:params) { { id: ecf_statement_next_cohort.id } }

Expand Down
Loading

0 comments on commit f5381c8

Please sign in to comment.