Skip to content

Commit

Permalink
Bdex/54508: intent to file get abstraction (#12427)
Browse files Browse the repository at this point in the history
* Initial creation of common files between GET and POST endpoint migration work

* Correct response abstraction file name; Add remaining abstraction functions

* intent to file post abstraction

* fix flipper placements

* fix tests

* fixes to swagger_spec.rb

* rubocop fix

* unit test fix

---------

Co-authored-by: mchae-nava <129200156+mchae-nava@users.noreply.github.com>
Co-authored-by: Seth Darr <seth.darr@agile6.com>
Co-authored-by: Seth Darr <92405130+sethdarragile6@users.noreply.github.com>
  • Loading branch information
4 people authored Apr 19, 2023
1 parent 2579f14 commit d21a0af
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/controllers/v0/intent_to_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'evss/intent_to_file/service'
require 'evss/intent_to_file/response_strategy'
require 'disability_compensation/factories/api_provider_factory'

module V0
class IntentToFilesController < ApplicationController
Expand All @@ -13,7 +14,8 @@ class IntentToFilesController < ApplicationController
TYPES = %w[compensation].freeze

def index
response = service.get_intent_to_file
intent_to_file_service = ApiProviderFactory.intent_to_file_service_provider(@current_user)
response = intent_to_file_service.get_intent_to_file
render json: response,
serializer: IntentToFileSerializer
end
Expand All @@ -25,7 +27,9 @@ def active
end

def submit
response = service.create_intent_to_file(params[:type])
intent_to_file_service = ApiProviderFactory.intent_to_file_service_provider(@current_user)

response = intent_to_file_service.create_intent_to_file(params[:type])
render json: response,
serializer: IntentToFileSerializer
end
Expand Down
3 changes: 3 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -854,3 +854,6 @@ features:
btsss_login_widget:
actor_type: user
description: If enabled shows the BTSSS login widget on the /get-reimbursed-for-travel-pay/ page
disability_compensation_lighthouse_intent_to_file_provider:
actor_type: user
description: If enabled uses the lighthouse intent to file endpoint
23 changes: 23 additions & 0 deletions lib/disability_compensation/factories/api_provider_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
require 'disability_compensation/providers/rated_disabilities/evss_rated_disabilities_provider'
require 'disability_compensation/providers/rated_disabilities/lighthouse_rated_disabilities_provider'
require 'disability_compensation/providers/rated_disabilities/rated_disabilities_provider'
require 'disability_compensation/providers/intent_to_file/evss_intent_to_file_provider'
require 'disability_compensation/providers/intent_to_file/lighthouse_intent_to_file_provider'
require 'disability_compensation/providers/intent_to_file/intent_to_file_provider'

class ApiProviderFactory
API_PROVIDER = {
Expand All @@ -11,6 +14,7 @@ class ApiProviderFactory
}.freeze

FEATURE_TOGGLE_RATED_DISABILITIES = 'disability_compensation_lighthouse_rated_disabilities_provider'
FEATURE_TOGGLE_INTENT_TO_FILE = 'disability_compensation_lighthouse_intent_to_file_provider'

def self.rated_disabilities_service_provider(current_user, api_provider = nil)
api_provider ||= if Flipper.enabled?(FEATURE_TOGGLE_RATED_DISABILITIES)
Expand All @@ -28,4 +32,23 @@ def self.rated_disabilities_service_provider(current_user, api_provider = nil)
raise NotImplementedError, 'No known Rated Disabilities Api Provider type provided'
end
end

def self.intent_to_file_service_provider(current_user, api_provider = nil)
api_provider ||= if Flipper.enabled?(FEATURE_TOGGLE_INTENT_TO_FILE)
API_PROVIDER[:lighthouse]
else
API_PROVIDER[:evss]
end

case api_provider
when API_PROVIDER[:evss]
EvssIntentToFileProvider.new(current_user)
when API_PROVIDER[:lighthouse]
# TODO: Implement this
raise NotImplementedError, 'Not implemented yet'
# LighthouseIntentToFileProvider.new(current_user)
else
raise NotImplementedError, 'No known Rated Disabilities Api Provider type provided'
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'disability_compensation/providers/intent_to_file/intent_to_file_provider'
require 'disability_compensation/responses/intent_to_files_response'
require 'evss/intent_to_file/service'

class EvssIntentToFileProvider
include IntentToFileProvider
def initialize(current_user)
@service = EVSS::IntentToFile::Service.new(current_user)
end

def get_intent_to_file
@service.get_intent_to_file
end

def create_intent_to_file(type)
@service.create_intent_to_file(type)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module IntentToFileProvider
def self.get_intent_to_file
raise NotImplementedError, 'Do not use base module methods. Override this method in implementation class.'
end

def self.create_intent_to_file(type)
raise NotImplementedError, 'Do not use base module methods. Override this method in implementation class.'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# frozen_string_literal: true
35 changes: 35 additions & 0 deletions lib/disability_compensation/responses/intent_to_files_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module DisabilityCompensation
module ApiProvider
class IntentToFile
include ActiveModel::Serialization
include Virtus.model

# The spelling of these status types has been validated with the partner team
STATUS_TYPES = %w[
active
claim_recieved
duplicate
expired
incomplete
canceled
].freeze

attribute :id, String
attribute :creation_date, DateTime
attribute :expiration_date, DateTime
attribute :participant_id, Integer
attribute :source, String
attribute :status, String
attribute :type, String
end

class IntentToFilesResponse
include ActiveModel::Serialization
include Virtus.model

attribute :intent_to_file, Array[DisabilityCompensation::ApiProvider::IntentToFile]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,40 @@
end.to raise_error NotImplementedError
end
end

context 'intent_to_file' do
it 'provides an EVSS intent to file provider' do
provider = ApiProviderFactory.intent_to_file_service_provider(current_user, :evss)
expect(provider.class).to equal(EvssIntentToFileProvider)
end

it 'provides a Lighthouse intent to file provider' do
# TODO: update when lighthouse provider is implemented
# provider = ApiProviderFactory.intent_to_file_service_provider(current_user, :lighthouse)
# expect(provider.class).to equal(LighthouseIntentToFileProvider)
expect do
ApiProviderFactory.intent_to_file_service_provider(current_user, :lighthouse)
end.to raise_error NotImplementedError
end

it 'provides intent to file provider based on Flipper' do
Flipper.enable(ApiProviderFactory::FEATURE_TOGGLE_INTENT_TO_FILE)
# TODO: update when lighthouse provider is implemented
# provider = ApiProviderFactory.intent_to_file_service_provider(current_user)
# expect(provider.class).to equal(LighthouseIntentToFileProvider)
expect do
ApiProviderFactory.intent_to_file_service_provider(current_user, :lighthouse)
end.to raise_error NotImplementedError

Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_INTENT_TO_FILE)
provider = ApiProviderFactory.intent_to_file_service_provider(current_user)
expect(provider.class).to equal(EvssIntentToFileProvider)
end

it 'throw error if provider unknown' do
expect do
ApiProviderFactory.intent_to_file_service_provider(current_user, :random)
end.to raise_error NotImplementedError
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_compensation/providers/intent_to_file/evss_intent_to_file_provider'
require 'support/disability_compensation_form/shared_examples/intent_to_file_provider'

RSpec.describe EvssIntentToFileProvider do
let(:current_user) { build(:disabilities_compensation_user) }

it_behaves_like 'intent to file provider'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_compensation/providers/intent_to_file/intent_to_file_provider'

RSpec.describe IntentToFileProvider do
let(:current_user) { build(:user) }

it 'always raises an error on the IntentToFileProvider base module - get intent to file' do
expect do
IntentToFileProvider.get_intent_to_file
end.to raise_error NotImplementedError
end

it 'always raises an error on the IntentToFileProvider base module - create intent to file' do
expect do
IntentToFileProvider.create_intent_to_file('')
end.to raise_error NotImplementedError
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'rails_helper'
require 'disability_compensation/providers/rated_disabilities/rated_disabilities_provider'
require 'support/disability_compensation_form/shared_examples/rated_disabilities_provider'

RSpec.describe RatedDisabilitiesProvider do
let(:current_user) { build(:user) }
Expand Down
5 changes: 4 additions & 1 deletion spec/requests/disability_compensation_form_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
end

context 'EVSS api provider' do
before do
Flipper.disable(feature_toggle_rated_disabilities)
end

context 'with a valid 200 evss response' do
Flipper.disable('disability_compensation_lighthouse_rated_disabilities_provider')
it 'matches the rated disabilities schema' do
VCR.use_cassette('evss/disability_compensation_form/rated_disabilities') do
get('/v0/disability_compensation_form/rated_disabilities', params: nil, headers:)
Expand Down
2 changes: 2 additions & 0 deletions spec/requests/intent_to_files_request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'rails_helper'
require 'disability_compensation/factories/api_provider_factory'

RSpec.describe 'Intent to file' do
include SchemaMatchers

before do
Flipper.disable(ApiProviderFactory::FEATURE_TOGGLE_INTENT_TO_FILE)
sign_in
end

Expand Down
5 changes: 5 additions & 0 deletions spec/requests/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,11 @@
end

describe 'intent to file' do
before do
# TODO: remove Flipper feature toggle when lighthouse provider is implemented
Flipper.disable('disability_compensation_lighthouse_intent_to_file_provider')
end

it 'supports getting all intent to file' do
expect(subject).to validate(:get, '/v0/intent_to_file', 401)
VCR.use_cassette('evss/intent_to_file/intent_to_file') do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'rails_helper'

shared_examples 'intent to file provider' do
# this is used to instantiate any IntentToFileProvider with a current_user
subject { described_class.new(current_user) }

it { is_expected.to respond_to(:get_intent_to_file) }
it { is_expected.to respond_to(:create_intent_to_file) }
end

0 comments on commit d21a0af

Please sign in to comment.