Repository: department-of-veterans-affairs/vets-api
Pull request #22091: MHV-67096-add-x-api-key
Author: login: agravell047
Labels: name: test-passing
name: require-backend-approval
Created: 2025-05-07T19:33:34Z | Merged: 2025-05-12T18:10:28Z

## Summary

- This PR adds a FF in replace of an AWS parameter to make it safer to test this feature (moving to AWS GW endpoints)
- Originally an AWS parameter was used because it was thought that we wouldn't be able to use it in configuration.rb because of a race condition. After testing, we noticed that we could as long as we catch the initial error that occurs before Flipper is loaded.
- Updates MHV Account Creation which is dependent on Rx

## Related issue(s)

- MHV-67096
![Screenshot 2025-03-06 at 4 45 11 PM](https://github.com/user-attachments/assets/1d5e4f12-a9bf-4e28-a8a0-939a09c1439d)

## Testing done

- Updates tests
- Tested locally
- Tested using existing cassettes, once feature is turned on and tested, FF will be removed and new cassettes will be generated

## Screenshots
N/A

## What areas of the site does it impact?
MHV medications endpoints/VAHB endpoints

## Acceptance criteria

- [ ]  I fixed|updated|added unit tests and integration tests for each feature (if applicable).
- [ ]  No error nor warning in the console.
- [ ]  Events are being sent to the appropriate logging solution
- [ ]  Documentation has been updated (link to documentation)
- [ ]  No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
- [ ]  Feature/bug has a monitor built into Datadog (if applicable)
- [ ]  If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected
- [ ]  I added a screenshot of the developed feature

## Requested Feedback

(OPTIONAL)_What should the reviewers know in addition to the above. Is there anything specific you wish the reviewer to assist with. Do you have any concerns with this PR, why?_



Diff:
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 5e22646decb1..f36966ab9fa6 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -2069,6 +2069,7 @@ spec/support/sidekiq/batch.rb @department-of-veterans-affairs/va-api-engineers @
 spec/support/silence_stream.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
 spec/support/sm_client_helpers.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
 spec/support/sm_spec_helper.rb @department-of-veterans-affairs/vfs-mhv-secure-messaging @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
+spec/support/rx_spec_helper.rb @department-of-veterans-affairs/vfs-mhv-medications @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
 spec/support/spec_builders.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group
 spec/support/spool_helpers.rb @department-of-veterans-affairs/va-api-engineers @department-of-veterans-affairs/backend-review-group @department-of-veterans-affairs/govcio-vfep-codereviewers
 spec/support/stub_debt_letters.rb @department-of-veterans-affairs/vsa-debt-resolution @department-of-veterans-affairs/backend-review-group
diff --git a/config/features.yml b/config/features.yml
index 4ae7b655a833..0043639447bc 100644
--- a/config/features.yml
+++ b/config/features.yml
@@ -1224,6 +1224,10 @@ features:
     actor_type: user
     description: Enables/disables refill progress related work
     enable_in_development: true
+  mhv_medications_migrate_to_api_gateway:
+    actor_type: user
+    description: Enables/disables medications migration to the new API Gateway endpoints
+    enable_in_development: true
   mhv_medications_remove_landing_page:
     actor_type: user
     description: Enables/disables removal of landing page
diff --git a/config/settings.yml b/config/settings.yml
index f4ada8520712..85c2142dc1cf 100644
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -893,7 +893,6 @@ mhv:
     gw_base_path: <%= ENV['mhv__rx__gw_base_path'] %>
     host: <%= ENV['mhv__rx__host'] %>
     mock: <%= ENV['mhv__rx__mock'] %>
-    use_new_api: <%= ENV['mhv__rx__use_new_api'] %>
     x_api_key: <%= ENV['mhv__rx__x_api_key'] %>
   sm:
     app_token: <%= ENV['mhv__sm__app_token'] %>
diff --git a/config/settings/development.yml b/config/settings/development.yml
index dc25698a543a..7fee15bef690 100644
--- a/config/settings/development.yml
+++ b/config/settings/development.yml
@@ -907,7 +907,6 @@ mhv:
     gw_base_path: v1/
     host: https://mhv-api.example.com
     mock: true
-    use_new_api: false
     x_api_key: fake-x-api-key
   sm:
     app_token: fake-app-token
diff --git a/config/settings/test.yml b/config/settings/test.yml
index ab4b41a98599..94a875dab733 100644
--- a/config/settings/test.yml
+++ b/config/settings/test.yml
@@ -906,7 +906,6 @@ mhv:
     gw_base_path: v1/
     host: https://mhv-api.example.com
     mock: true
-    use_new_api: false
     x_api_key: fake-x-api-key
   sm:
     app_token: fake-app-token
diff --git a/lib/mhv_ac/client.rb b/lib/mhv_ac/client.rb
index a4b22ffdb440..0d57b8dec728 100644
--- a/lib/mhv_ac/client.rb
+++ b/lib/mhv_ac/client.rb
@@ -19,7 +19,8 @@ class Client < Common::Client::Base
     #
     def post_register(params)
       form = MHVAC::RegistrationForm.new(params)
-      perform(:post, 'account/register', form.mhv_params, nonauth_headers).body
+      path = Flipper.enabled?(:mhv_medications_migrate_to_api_gateway) ? 'usermgmt/alter/register' : 'account/register'
+      perform(:post, path, form.mhv_params, nonauth_headers).body
     end
 
     ##
@@ -29,7 +30,8 @@ def post_register(params)
     #
     def post_upgrade(params)
       form = MHVAC::UpgradeForm.new(params)
-      perform(:post, 'account/upgrade', form.mhv_params, nonauth_headers).body
+      path = Flipper.enabled?(:mhv_medications_migrate_to_api_gateway) ? 'usermgmt/alter/upgrade' : 'account/upgrade'
+      perform(:post, path, form.mhv_params, nonauth_headers).body
     end
 
     ##
@@ -38,22 +40,34 @@ def post_upgrade(params)
     # @return [Hash] an object containing the body of the response
     #
     def get_states
-      perform(:get, 'enum/states', nil, nonauth_headers).body
+      path = Flipper.enabled?(:mhv_medications_migrate_to_api_gateway) ? 'usermgmt/enum/states' : 'enum/states'
+      perform(:get, path, nil, nonauth_headers).body
     end
 
     ##
-    # Get a list of available countries (used for registraion)
+    # Get a list of available countries (used for registration)
     # @note These two lists (state and country) should be cached for any given day.
     # @return [Hash] an object containing the body of the response
     #
     def get_countries
-      perform(:get, 'enum/countries', nil, nonauth_headers).body
+      path = Flipper.enabled?(:mhv_medications_migrate_to_api_gateway) ? 'usermgmt/enum/countries' : 'enum/countries'
+      perform(:get, path, nil, nonauth_headers).body
     end
 
     private
 
     def nonauth_headers
-      config.base_request_headers.merge('appToken' => config.app_token)
+      headers = config.base_request_headers.merge('appToken' => config.app_token)
+      get_headers(headers)
+    end
+
+    def get_headers(headers)
+      headers = headers.dup
+      if Flipper.enabled?(:mhv_medications_migrate_to_api_gateway)
+        headers.merge('x-api-key' => config.x_api_key)
+      else
+        headers
+      end
     end
   end
 end
diff --git a/lib/mhv_ac/configuration.rb b/lib/mhv_ac/configuration.rb
index b9475ae5a2a5..72d2cb1408b6 100644
--- a/lib/mhv_ac/configuration.rb
+++ b/lib/mhv_ac/configuration.rb
@@ -21,11 +21,25 @@ def app_token
       Settings.mhv.rx.app_token
     end
 
+    ##
+    # @return [String] API GW key set in `settings.yml` via credstash
+    #
+    def x_api_key
+      Settings.mhv.rx.x_api_key
+    end
+
     ##
     # @return [String] Base path for dependent URLs
     #
     def base_path
-      "#{Settings.mhv.rx.host}/mhv-api/patient/v1/"
+      if Flipper.enabled?(:mhv_medications_migrate_to_api_gateway)
+        "#{Settings.mhv.api_gateway.hosts.pharmacy}/#{Settings.mhv.rx.gw_base_path}"
+      else
+        "#{Settings.mhv.rx.host}/#{Settings.mhv.rx.base_path}"
+      end
+    rescue NoMethodError => e
+      Rails.logger.error("RX:Configuration Flipper error: #{e.message}")
+      "#{Settings.mhv.rx.host}/#{Settings.mhv.rx.base_path}" # Default path
     end
 
     ##
diff --git a/lib/rx/client.rb b/lib/rx/client.rb
index 01680c7e7c5b..a5fba292fbae 100644
--- a/lib/rx/client.rb
+++ b/lib/rx/client.rb
@@ -192,7 +192,7 @@ def post_preferences(params)
 
     def get_session_tagged
       Sentry.set_tags(error: 'mhv_session')
-      env = if Settings.mhv.rx.use_new_api.present? && Settings.mhv.rx.use_new_api
+      env = if Flipper.enabled?(:mhv_medications_migrate_to_api_gateway)
               perform(:get, 'usermgmt/auth/session', nil, auth_headers)
             else
               perform(:get, 'session', nil, auth_headers)
@@ -215,7 +215,7 @@ def auth_headers
 
     def get_headers(headers)
       headers = headers.dup
-      if Settings.mhv.rx.use_new_api.present? && Settings.mhv.rx.use_new_api
+      if Flipper.enabled?(:mhv_medications_migrate_to_api_gateway)
         headers.merge('x-api-key' => config.x_api_key)
       else
         headers
@@ -223,12 +223,12 @@ def get_headers(headers)
     end
 
     def get_path(endpoint)
-      base_path = Settings.mhv.rx.use_new_api.present? && Settings.mhv.rx.use_new_api ? 'pharmacy/ess' : 'prescription'
+      base_path = Flipper.enabled?(:mhv_medications_migrate_to_api_gateway) ? 'pharmacy/ess' : 'prescription'
       "#{base_path}/#{endpoint}"
     end
 
     def get_preferences_path(endpoint)
-      base_path = if Settings.mhv.rx.use_new_api.present? && Settings.mhv.rx.use_new_api
+      base_path = if Flipper.enabled?(:mhv_medications_migrate_to_api_gateway)
                     'usermgmt/notification'
                   else
                     'preferences'
diff --git a/lib/rx/configuration.rb b/lib/rx/configuration.rb
index d21c71ca4c12..f5a5f26f77f9 100644
--- a/lib/rx/configuration.rb
+++ b/lib/rx/configuration.rb
@@ -35,11 +35,14 @@ def x_api_key
     # @return [String] Base path for dependent URLs
     #
     def base_path
-      if Settings.mhv.rx.use_new_api.present? && Settings.mhv.rx.use_new_api
+      if Flipper.enabled?(:mhv_medications_migrate_to_api_gateway)
         "#{Settings.mhv.api_gateway.hosts.pharmacy}/#{Settings.mhv.rx.gw_base_path}"
       else
         "#{Settings.mhv.rx.host}/#{Settings.mhv.rx.base_path}"
       end
+    rescue NoMethodError => e
+      Rails.logger.error("RX:Configuration Flipper error: #{e.message}")
+      "#{Settings.mhv.rx.host}/#{Settings.mhv.rx.base_path}" # Default path
     end
 
     ##
diff --git a/lib/rx/medications_client.rb b/lib/rx/medications_client.rb
deleted file mode 100644
index aa2aca0ae647..000000000000
--- a/lib/rx/medications_client.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-require 'common/client/base'
-require 'common/client/concerns/mhv_session_based_client'
-require 'rx/configuration'
-require 'rx/client_session'
-require 'rx/rx_gateway_timeout'
-require 'active_support/core_ext/hash/slice'
-require 'rx/client'
-
-module Rx
-  ##
-  # Core class responsible for Rx API interface operations on va.gov
-  #
-  class MedicationsClient < Rx::Client
-    include Common::Client::Concerns::MHVSessionBasedClient
-    configuration Rx::Configuration
-    client_session Rx::ClientSession
-
-    def auth_headers
-      Rails.logger.info('Rx request is coming from VA.gov web')
-      get_headers(config.base_request_headers.merge('appToken' => config.app_token,
-                                                    'mhvCorrelationId' => session.user_id.to_s))
-    end
-
-    def get_headers(headers)
-      if Settings.mhv.rx.use_new_api.present? && Settings.mhv.rx.use_new_api
-        headers.merge('x-api-key' => Settings.mhv.rx.x_api_key)
-      else
-        headers
-      end
-    end
-  end
-end
diff --git a/modules/my_health/app/controllers/my_health/rx_controller.rb b/modules/my_health/app/controllers/my_health/rx_controller.rb
index dbec01943846..a70f36992ee2 100644
--- a/modules/my_health/app/controllers/my_health/rx_controller.rb
+++ b/modules/my_health/app/controllers/my_health/rx_controller.rb
@@ -1,7 +1,6 @@
 # frozen_string_literal: true
 
 require 'rx/client'
-require 'rx/medications_client'
 
 module MyHealth
   class RxController < ApplicationController
diff --git a/spec/lib/rx/client_spec.rb b/spec/lib/rx/client_spec.rb
index 9be6f3ee3fe8..e4aa3f3b3c87 100644
--- a/spec/lib/rx/client_spec.rb
+++ b/spec/lib/rx/client_spec.rb
@@ -2,6 +2,7 @@
 
 require 'rails_helper'
 require 'rx/client'
+require 'rx/configuration'
 
 # Mock upstream request to return source app for Rx client
 class UpstreamRequest
@@ -11,14 +12,11 @@ def self.env
 end
 
 describe Rx::Client do
-  before(:all) do
+  before do
     VCR.use_cassette 'rx_client/session' do
-      @client ||= begin
-        client = Rx::Client.new(session: { user_id: '12210827' },
-                                upstream_request: UpstreamRequest)
-        client.authenticate
-        client
-      end
+      @client = Rx::Client.new(session: { user_id: '12210827' },
+                               upstream_request: UpstreamRequest)
+      @client.authenticate
     end
   end
 
@@ -167,64 +165,29 @@ def self.env
   end
 
   describe 'Test new API gateway methods' do
-    before do
-      allow(Settings.mhv.rx).to receive(:use_new_api).and_return(use_new_api)
-      allow(Settings.mhv_mobile.rx).to receive(:x_api_key).and_return('fake-x-api-key')
-      allow(client).to receive(:config).and_return(OpenStruct.new(base_request_headers: { 'base-header' => 'value' },
-                                                                  app_token: 'test-app-token'))
-      allow(client).to receive(:config).and_return(OpenStruct.new(base_request_headers: { 'base-header' => 'value' },
-                                                                  app_token: 'test-app-token',
-                                                                  x_api_key: 'fake-x-api-key'))
-    end
+    let(:config) { Rx::Configuration.instance }
 
-    describe '#auth_headers' do
-      let(:use_new_api) { true }
-
-      it 'returns headers with appToken and mhvCorrelationId' do
-        result = client.send(:auth_headers)
-        expect(result).to include('x-api-key' => 'fake-x-api-key')
-      end
-    end
-
-    describe '#get_headers' do
-      let(:headers) { { 'custom-header' => 'value' } }
-
-      context 'when use_new_api is true' do
-        let(:use_new_api) { true }
-
-        it 'adds x-api-key to headers' do
-          result = client.send(:get_headers, headers)
-          expect(result).to include('custom-header' => 'value', 'x-api-key' => 'fake-x-api-key')
-        end
+    context 'when mhv_medications_migrate_to_api_gateway flipper flag is true' do
+      before do
+        allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(true)
+        allow(Settings.mhv.rx).to receive(:x_api_key).and_return('test-api-key')
       end
 
-      context 'when use_new_api is false' do
-        let(:use_new_api) { false }
-
-        it 'returns headers without x-api-key' do
-          result = client.send(:get_headers, headers)
-          expect(result).to eq(headers)
-        end
+      it 'returns the x-api-key header' do
+        result = client.send(:auth_headers)
+        headers = { 'base-header' => 'value', 'appToken' => 'test-app-token', 'mhvCorrelationId' => '10616687' }
+        allow(client).to receive(:auth_headers).and_return(headers)
+        expect(result).to include('x-api-key' => 'test-api-key')
+        expect(config.x_api_key).to eq('test-api-key')
       end
     end
 
-    describe '#get_path' do
-      context 'when use_new_api is true' do
-        let(:use_new_api) { true }
-
-        it 'returns path with pharmacy/ess' do
-          result = client.send(:get_path, 'test-endpoint')
-          expect(result).to eq('pharmacy/ess/test-endpoint')
-        end
-      end
-
-      context 'when use_new_api is false' do
-        let(:use_new_api) { false }
-
-        it 'returns path with prescription' do
-          result = client.send(:get_path, 'test-endpoint')
-          expect(result).to eq('prescription/test-endpoint')
-        end
+    context 'when mhv_medications_migrate_to_api_gateway flipper flag is false' do
+      it 'returns nil for x-api-key' do
+        result = client.send(:auth_headers)
+        headers = { 'base-header' => 'value', 'appToken' => 'test-app-token', 'mhvCorrelationId' => '10616687' }
+        allow(client).to receive(:auth_headers).and_return(headers)
+        expect(result).not_to include('x-api-key')
       end
     end
   end
diff --git a/spec/lib/rx/configuration_spec.rb b/spec/lib/rx/configuration_spec.rb
index 4441859b01d0..879bb2c921b0 100644
--- a/spec/lib/rx/configuration_spec.rb
+++ b/spec/lib/rx/configuration_spec.rb
@@ -13,28 +13,43 @@
     end
   end
 
+  describe '#x_api_key' do
+    it 'returns the API GW key from settings' do
+      allow(Settings.mhv.rx).to receive(:x_api_key).and_return('test_api_key')
+      expect(configuration.x_api_key).to eq('test_api_key')
+    end
+  end
+
   describe '#base_path' do
-    context 'when use_new_api is true' do
-      it 'returns the new API base path' do
+    context 'when Flipper is enabled for API gateway' do
+      it 'returns the API gateway base path' do
+        allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(true)
+        allow(Settings.mhv.api_gateway.hosts).to receive(:pharmacy).and_return('https://api-gateway.example.com')
+        allow(Settings.mhv.rx).to receive(:gw_base_path).and_return('v1/')
+        expect(configuration.base_path).to eq('https://api-gateway.example.com/v1/')
+      end
+    end
+
+    context 'when Flipper is disabled for API gateway' do
+      it 'returns the default base path' do
+        allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
         allow(Settings.mhv.rx).to receive_messages(
-          use_new_api: true,
-          base_path: 'mhv-api-patient/v1/',
-          gw_base_path: 'v1/'
+          host: 'https://default-api.example.com',
+          base_path: 'mhv-api-patient/v1/'
         )
-        allow(Settings.mhv.api_gateway.hosts).to receive(:pharmacy).and_return('https://new-api.example.com')
-        expect(configuration.base_path).to eq('https://new-api.example.com/v1/')
+        expect(configuration.base_path).to eq('https://default-api.example.com/mhv-api-patient/v1/')
       end
     end
 
-    context 'when use_new_api is false' do
-      it 'returns the old API base path' do
+    context 'when a NoMethodError occurs' do
+      it 'logs the error and returns the default base path' do
+        allow(Flipper).to receive(:enabled?).and_raise(NoMethodError, 'undefined method')
         allow(Settings.mhv.rx).to receive_messages(
-          use_new_api: false,
-          host: 'https://old-api.example.com',
-          base_path: 'mhv-api-patient/v1/',
-          gw_base_path: 'v1/'
+          host: 'https://error-api.example.com',
+          base_path: 'mhv-api-patient/v1/'
         )
-        expect(configuration.base_path).to eq('https://old-api.example.com/mhv-api-patient/v1/')
+        expect(Rails.logger).to receive(:error).with(/RX:Configuration Flipper error: undefined method/)
+        expect(configuration.base_path).to eq('https://error-api.example.com/mhv-api-patient/v1/')
       end
     end
   end
diff --git a/spec/lib/rx/medications_client_spec.rb b/spec/lib/rx/medications_client_spec.rb
deleted file mode 100644
index 796e6cd057be..000000000000
--- a/spec/lib/rx/medications_client_spec.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-# frozen_string_literal: true
-
-require 'rails_helper'
-require 'rx/medications_client'
-
-RSpec.describe Rx::MedicationsClient do
-  before(:all) do
-    VCR.use_cassette 'rx_client/session' do
-      @client ||= begin
-        client = Rx::MedicationsClient.new(session: { user_id: '12345' })
-        client.authenticate
-        client
-      end
-    end
-  end
-
-  let(:session) { instance_double(Rx::ClientSession, user_id: '17621060') } # Ensure user_id is mocked
-  let(:client) { @client }
-
-  describe '#auth_headers' do
-    context 'when use_new_api is true' do
-      it 'includes x-api-key in the headers' do
-        allow(Settings.mhv.rx).to receive_messages(
-          use_new_api: true,
-          x_api_key: 'fake-x-api-key',
-          app_token: 'va_gov_token'
-        )
-        headers = client.auth_headers
-        expect(headers['x-api-key']).to eq('fake-x-api-key')
-        expect(headers['appToken']).to eq('va_gov_token')
-        expect(headers['mhvCorrelationId']).to eq('12345')
-      end
-    end
-
-    context 'when use_new_api is false' do
-      it 'does not include x-api-key in the headers' do
-        allow(Settings.mhv.rx).to receive_messages(
-          use_new_api: false,
-          x_api_key: 'fake-x-api-key',
-          app_token: 'va_gov_token'
-        )
-        headers = client.auth_headers
-        expect(headers).not_to have_key('x-api-key')
-        expect(headers['appToken']).to eq('va_gov_token')
-        expect(headers['mhvCorrelationId']).to eq('12345')
-      end
-    end
-  end
-
-  describe '#get_headers' do
-    it 'merges additional headers correctly' do
-      base_headers = { 'Content-Type' => 'application/json' }
-      allow(Settings.mhv.rx).to receive_messages(
-        use_new_api: true,
-        x_api_key: 'fake-x-api-key'
-      )
-      headers = client.get_headers(base_headers)
-      expect(headers['Content-Type']).to eq('application/json')
-      expect(headers['x-api-key']).to eq('fake-x-api-key')
-    end
-
-    it 'returns base headers when use_new_api is false' do
-      base_headers = { 'Content-Type' => 'application/json' }
-      allow(Settings.mhv.rx).to receive_messages(
-        use_new_api: false,
-        x_api_key: 'fake-x-api-key',
-        app_token: 'va_gov_token'
-      )
-      headers = client.get_headers(base_headers)
-      expect(headers['Content-Type']).to eq('application/json')
-      expect(headers).not_to have_key('x-api-key')
-    end
-  end
-end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 6e85fceec59e..9d4e98d64704 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -29,6 +29,7 @@
 require 'support/financial_status_report_helpers'
 require 'support/poa_stub'
 require 'support/sm_spec_helper'
+require 'support/rx_spec_helper'
 require 'support/pdf_fill_helper'
 require 'support/vcr_multipart_matcher_helper'
 require 'support/request_helper'
diff --git a/spec/support/rx_spec_helper.rb b/spec/support/rx_spec_helper.rb
new file mode 100644
index 000000000000..fe4784b3b8c4
--- /dev/null
+++ b/spec/support/rx_spec_helper.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+  config.before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
+  end
+end


Reviews:
user: login: rmtolmach
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T13:33:53Z
user: login: agravell047
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T13:39:03Z
user: login: rmtolmach
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T15:11:07Z
user: login: robertroddev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:20:33Z
user: login: agravell047
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:24:30Z
user: login: robertroddev
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:31:40Z
user: login: robertroddev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:35:30Z
user: login: agravell047
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:37:01Z
user: login: robertroddev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:46:24Z
user: login: rmtolmach
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:51:15Z
user: login: rmtolmach
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:55:46Z
user: login: vmenshutin-bylight
state: DISMISSED
author_association: NONE
submitted_at: 2025-05-08T17:57:34Z
user: login: rmtolmach
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:58:05Z
user: login: robertroddev
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T17:58:10Z
user: login: bosawt
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T20:16:19Z
user: login: agravell047
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T20:24:13Z
user: login: agravell047
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T20:35:14Z
user: login: bosawt
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T20:35:25Z
user: login: agravell047
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T20:36:02Z
user: login: emilykim13
body: Lgtm, re-tested the recent commit that removed unnecessary flipper mocks. Tests passing locally.
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T21:14:15Z
user: login: robertroddev
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T21:43:38Z
user: login: rmtolmach
body: Good catch @bosawt!
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-05-08T21:59:33Z
user: login: alex-morgun-1
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-09T19:10:49Z
user: login: robertroddev
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T14:48:34Z
user: login: emilykim13
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T16:54:33Z
user: login: rjohnson2011
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-05-12T17:33:25Z

Review comments:
diff_hunk: @@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+  config.before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/support/rx_spec_helper.rb
user: login: rmtolmach
body: This makes me a bit nervous since it's global in scope 😕 and could interfere with other tests. Is this necessary or can you put this mock only in the tests that need it or narrow the scope somehow?
created_at: 2025-05-08T13:33:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+  config.before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/support/rx_spec_helper.rb
user: login: agravell047
body: @rmtolmach I was following this: 
https://github.com/department-of-veterans-affairs/vets-api/blob/master/spec/support/sm_spec_helper.rb#L9

If it interfered with other tests wouldn't they be failing?
created_at: 2025-05-08T13:39:03Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+  config.before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/support/rx_spec_helper.rb
user: login: rmtolmach
body: they would probably fail intermittently because CI tests run in parallel. I see you've gotten 2 passing test runs. I'm running it once more just to be sure.
created_at: 2025-05-08T15:11:07Z
author_association: CONTRIBUTOR
diff_hunk: @@ -19,7 +19,8 @@ class Client < Common::Client::Base
     #
path: lib/mhv_ac/client.rb
user: login: robertroddev
body: these changes seem good, but I'm curious on who else could use this file? do you know if medications is the only team dependent on this file? 
created_at: 2025-05-08T17:20:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -19,7 +19,8 @@ class Client < Common::Client::Base
     #
path: lib/mhv_ac/client.rb
user: login: agravell047
body: we actually aren't dependent on/using this, they're dependent on us. I've reached out to their team (identity team) and got their monitors to track and was able to test these locally. They also gave me steps for testing in staging which I plan to do after merging.
created_at: 2025-05-08T17:24:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+  config.before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/support/rx_spec_helper.rb
user: login: robertroddev
body: @agravell047 curious why put this ff here rather than using it on the specific rx specs instead?
created_at: 2025-05-08T17:35:30Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+  config.before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/support/rx_spec_helper.rb
user: login: agravell047
body: this was Alex's recommendation and it worked for SM. There are quite a few that need to be added and once this FF is tested, it makes it much easier to remove.
created_at: 2025-05-08T17:37:01Z
author_association: CONTRIBUTOR
diff_hunk: @@ -19,7 +19,8 @@ class Client < Common::Client::Base
     #
path: lib/mhv_ac/client.rb
user: login: robertroddev
body: i see, yeah I've never messed with this file which is why i was ignorant on it. Thanks!
created_at: 2025-05-08T17:46:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -935,7 +935,6 @@ mhv:
     gw_base_path: <%= ENV['mhv__rx__gw_base_path'] %>
     host: <%= ENV['mhv__rx__host'] %>
     mock: <%= ENV['mhv__rx__mock'] %>
-    use_new_api: <%= ENV['mhv__rx__use_new_api'] %>
path: config/settings.yml
user: login: rmtolmach
body: Make sure you delete this (for all envs) in parameter store after this PR is _deployed_
created_at: 2025-05-08T17:51:15Z
author_association: CONTRIBUTOR
diff_hunk: @@ -935,7 +935,6 @@ mhv:
     gw_base_path: <%= ENV['mhv__rx__gw_base_path'] %>
     host: <%= ENV['mhv__rx__host'] %>
     mock: <%= ENV['mhv__rx__mock'] %>
-    use_new_api: <%= ENV['mhv__rx__use_new_api'] %>
path: config/settings.yml
user: login: rmtolmach
body: 👍 I see all mentions of this setting removed in vets-api
created_at: 2025-05-08T17:55:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require 'rspec/rails'
+
+RSpec.configure do |config|
+  config.before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/support/rx_spec_helper.rb
user: login: robertroddev
body: I see makes sense, since it seems the set up and clean up require more complexity vs this simple solution. Thanks! 
created_at: 2025-05-08T17:58:10Z
author_association: CONTRIBUTOR
diff_hunk: @@ -67,6 +67,7 @@ def append_info_to_payload(payload)
   end
 
   before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/controllers/application_controller_spec.rb
user: login: bosawt
body: Is this necessary? I tested with and without it, and the specs appear to pass without this. Were you seeing differently?
created_at: 2025-05-08T20:16:19Z
author_association: CONTRIBUTOR
diff_hunk: @@ -67,6 +67,7 @@ def append_info_to_payload(payload)
   end
 
   before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/controllers/application_controller_spec.rb
user: login: agravell047
body: @bosawt good point, I think its not needed now that I added rx_spec_helper.rb which does this globally. I was seeing this as needed before I had that file.
created_at: 2025-05-08T20:24:13Z
author_association: CONTRIBUTOR
diff_hunk: @@ -67,6 +67,7 @@ def append_info_to_payload(payload)
   end
 
   before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/controllers/application_controller_spec.rb
user: login: agravell047
body: Just removed it
created_at: 2025-05-08T20:35:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -67,6 +67,7 @@ def append_info_to_payload(payload)
   end
 
   before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/controllers/application_controller_spec.rb
user: login: bosawt
body: I think you could remove a ton of the extra flipper mocks, right? Might be useful to remove the others. It'll make it easier to clean up as well when eventually this flipper is no longer necessary
created_at: 2025-05-08T20:35:24Z
author_association: CONTRIBUTOR
diff_hunk: @@ -67,6 +67,7 @@ def append_info_to_payload(payload)
   end
 
   before do
+    allow(Flipper).to receive(:enabled?).with(:mhv_medications_migrate_to_api_gateway).and_return(false)
path: spec/controllers/application_controller_spec.rb
user: login: agravell047
body: agreed!
created_at: 2025-05-08T20:36:02Z
author_association: CONTRIBUTOR

PR comments:
user: login: github-actions[bot]
created_at: 2025-05-07T19:34:20Z
body: <!--
  0 Errors
  1 Warning: This PR changes <code>264</cod...
  0 Messages
  0 Markdowns
-->
<table>
  <thead>
    <tr>
      <th width="50"></th>
      <th width="100%" data-danger-table="true" data-kind="Warning">
          1 Warning
      </th>
     </tr>
  </thead>
  <tbody>
    <tr>
      <td>:warning:</td>
      <td data-sticky="false">This PR changes <code>264</code> LoC (not counting whitespace/newlines).</p>

<p>In order to ensure each PR receives the proper attention it deserves, we recommend not exceeding<br />
<code>200</code>. Expect some delays getting reviews.</p>

<details>
  <summary>File Summary</summary>

  #### Files
  - .github/CODEOWNERS (+1/-0)
- config/features.yml (+4/-0)
- config/settings.yml (+0/-1)
- config/settings/development.yml (+0/-1)
- config/settings/test.yml (+0/-1)
- lib/mhv_ac/client.rb (+18/-5)
- lib/mhv_ac/configuration.rb (+11/-1)
- lib/rx/client.rb (+4/-4)
- lib/rx/configuration.rb (+4/-1)
- lib/rx/medications_client.rb (+0/-26)
- modules/my_health/app/controllers/my_health/rx_controller.rb (+0/-1)
- spec/lib/rx/client_spec.rb (+19/-48)
- spec/lib/rx/configuration_spec.rb (+27/-14)
- spec/lib/rx/medications_client_spec.rb (+0/-66)
- spec/rails_helper.rb (+1/-0)
- spec/support/rx_spec_helper.rb (+6/-0)

  ####
  _Note: We exclude files matching the following when considering PR size:_

  ```
  *.csv, *.json, *.tsv, *.txt, *.md, Gemfile.lock, app/swagger, modules/mobile/docs, spec/fixtures/, spec/support/vcr_cassettes/, modules/mobile/spec/support/vcr_cassettes/, db/seeds, modules/vaos/app/docs, modules/meb_api/app/docs, modules/appeals_api/app/swagger/, *.bru, *.pdf
  ```
</details>

<p>Big PRs are difficult to review, often become stale, and cause delays.</td>
    </tr>
  </tbody>
</table>

<p align="right" data-meta="generated_by_danger">
  Generated by :no_entry_sign: <a href="https://danger.systems/">Danger</a>
</p>

author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-05-07T22:04:51Z
body: Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: spec/support/rx_spec_helper.rb
author_association: CONTRIBUTOR
user: login: github-actions[bot]
created_at: 2025-05-08T02:18:28Z
body: Error: A file (or its parent directories) does not have a CODEOWNERS entry. Please update the .github/CODEOWNERS file and add the entry for the Offending file: spec/support/rx_spec_helper.rb
author_association: CONTRIBUTOR
user: login: rmtolmach
created_at: 2025-05-08T18:03:22Z
body: @agravell047 You'll need a review from @department-of-veterans-affairs/mobile-api-team (#va-mobile-app) and @department-of-veterans-affairs/octo-identity (#identity-support)
author_association: CONTRIBUTOR
user: login: bosawt
created_at: 2025-05-09T17:11:41Z
body: @agravell047 Heads up, I just got a PR merged that removes a lot of MHV legacy controllers, it should only simplify the work you're doing here, but just wanted you to know in case you were wondering why things changed a bit out from under you here
author_association: CONTRIBUTOR