Skip to content

Commit

Permalink
5284 filter doc 27 (#12447)
Browse files Browse the repository at this point in the history
  • Loading branch information
aherzberg authored Apr 21, 2023
1 parent 94dfa2e commit 5eaf9ed
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
4 changes: 4 additions & 0 deletions config/features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ features:
actor_type: user
description: enables us to easily turn off pre-caching appointments if our requests are overwhelming the upstream service
enable_in_development: true
mobile_filter_doc_27_decision_letters_out:
actor_type: user
description: filters out doc type 27 decision letters out of list of decision letters for mobile
enable_in_development: false
multiple_address_10_10ez:
actor_type: cookie_id
description: >
Expand Down
38 changes: 23 additions & 15 deletions modules/mobile/app/models/mobile/v0/adapters/decision_letters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@ class DecisionLetters
def parse(decision_letters)
return [] if decision_letters.empty?

if Flipper.enabled?(:mobile_filter_doc_27_decision_letters_out)
decision_letters.reject! { |letter| letter[:doc_type] == '27' }
end

decision_letters.map do |letter|
Mobile::V0::DecisionLetter.new(
document_id: letter[:document_id],
series_id: letter[:series_id],
version: letter[:version],
type_description: letter[:type_description],
type_id: letter[:type_id],
doc_type: letter[:doc_type],
subject: letter[:subject],
received_at: letter[:received_at].iso8601,
source: letter[:source],
mime_type: letter[:mime_type],
alt_doc_types: letter[:alt_doc_types],
restricted: letter[:restricted],
upload_date: letter[:upload_date]&.iso8601
)
create_decision_letter(letter)
end.sort_by(&:received_at).reverse!
end

def create_decision_letter(letter)
Mobile::V0::DecisionLetter.new(
document_id: letter[:document_id],
series_id: letter[:series_id],
version: letter[:version],
type_description: letter[:type_description],
type_id: letter[:type_id],
doc_type: letter[:doc_type],
subject: letter[:subject],
received_at: letter[:received_at].iso8601,
source: letter[:source],
mime_type: letter[:mime_type],
alt_doc_types: letter[:alt_doc_types],
restricted: letter[:restricted],
upload_date: letter[:upload_date]&.iso8601
)
end
end
end
end
Expand Down
47 changes: 37 additions & 10 deletions modules/mobile/spec/request/decision_letters_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,50 @@
allow(VBMS::Client).to receive(:from_env_vars).and_return(FakeVBMS.new)
allow_any_instance_of(IAMUser).to receive(:icn).and_return('24811694708759028')
iam_sign_in(build(:iam_user))
Flipper.disable('mobile_filter_doc_27_decision_letters_out')
end

after do
Flipper.disable('mobile_filter_doc_27_decision_letters_out')
end

# This endpoint's upstream service mocks it's own data for test env. HTTP client is not exposed by the
# connect_vbms gem so it cannot intercept the actual HTTP request, making the use of VCRs not possible.
# This means we cannot test error states for the index endpoint within specs
describe 'GET /mobile/v0/decision-letters' do
context 'with a valid response' do
it 'returns expected decision letters' do
get '/mobile/v0/claims/decision-letters', headers: iam_headers
expect(response).to have_http_status(:ok)
decision_letters = response.parsed_body['data']
first_received_at = decision_letters.first.dig('attributes', 'receivedAt')
last_received_at = decision_letters.last.dig('attributes', 'receivedAt')

expect(decision_letters.count).to eq(6)
expect(first_received_at).to be >= last_received_at
expect(response.body).to match_json_schema('decision_letter')
context 'with mobile_filter_doc_27_decision_letters_out flag enabled' do
it 'returns expected decision letters' do
Flipper.enable('mobile_filter_doc_27_decision_letters_out')

get '/mobile/v0/claims/decision-letters', headers: iam_headers
expect(response).to have_http_status(:ok)
decision_letters = response.parsed_body['data']
first_received_at = decision_letters.first.dig('attributes', 'receivedAt')
last_received_at = decision_letters.last.dig('attributes', 'receivedAt')
expect(decision_letters.count).to eq(5)
expect(first_received_at).to be >= last_received_at
expect(response.body).to match_json_schema('decision_letter')
doc_types = decision_letters.map { |letter| letter.dig('attributes', 'docType') }.uniq
expect(doc_types).to eq(['184'])
end
end

context 'with mobile_filter_doc_27_decision_letters_out flag disabled' do
it 'returns expected decision letters' do
Flipper.disable('mobile_filter_doc_27_decision_letters_out')

get '/mobile/v0/claims/decision-letters', headers: iam_headers
expect(response).to have_http_status(:ok)
decision_letters = response.parsed_body['data']
first_received_at = decision_letters.first.dig('attributes', 'receivedAt')
last_received_at = decision_letters.last.dig('attributes', 'receivedAt')
expect(decision_letters.count).to eq(6)
expect(first_received_at).to be >= last_received_at
expect(response.body).to match_json_schema('decision_letter')
doc_types = decision_letters.map { |letter| letter.dig('attributes', 'docType') }.uniq
expect(doc_types).to eq(%w[27 184])
end
end
end
end
Expand Down

0 comments on commit 5eaf9ed

Please sign in to comment.