Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry getting a rating profile on BGS::ShareError #15316

Merged
merged 5 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions app/models/promulgated_rating.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def ratings_from_bgs_response(response)

attr_writer :rating_profile

def rating_profile
@rating_profile ||= fetch_rating_profile
end

private

def fetch_rating_profile
Expand All @@ -65,9 +69,24 @@ def fetch_rating_profile
)
rescue Savon::Error
{}
rescue BGS::ShareError
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to rescue the generic ShareError instead of the specific one originally listed in the AC because I figure anytime we get the ShareError, it's worth trying the other service as a backup.

retry_fetching_rating_profile
end

def rating_profile
@rating_profile ||= fetch_rating_profile
# Re-tries fetching the rating profile with the RatingAtIssue service
def retry_fetching_rating_profile
ratings_at_issue = RatingAtIssue.fetch_in_range(
participant_id: participant_id,
start_date: profile_date,
end_date: profile_date
Comment on lines +80 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the start and end dates be the same?

Copy link
Contributor Author

@leikkisa leikkisa Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, with the regular service we can fetch a specific rating profile using the veteran's participant ID and profile date.

With the "back" service, we can fetch a range by date instead of a specific one. So this limits the results, and then another (just in case) matching is done using the profile date comparison method which includes the timestamp.

)
matching_rating = ratings_at_issue.find { |rating| profile_date_matches(rating.profile_date) }
matching_rating.present? ? matching_rating.rating_profile : {}
end

# The profile date is used as a key when fetching a rating by profile date.
# Profile dates in RatingAtIssue appear to have the same Date/Time stamp, but sometimes disagree by one timezone
def profile_date_matches(profile_date_to_compare)
profile_date.strftime("%Y-%m-%d %H:%M:%S") == profile_date_to_compare.strftime("%Y-%m-%d %H:%M:%S")
end
end
8 changes: 6 additions & 2 deletions lib/fakes/bgs_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ def fetch_ratings_in_range(participant_id:, start_date:, end_date:)
format_promulgated_rating(build_ratings_in_range(ratings, start_date, end_date))
end

def fetch_rating_profile(participant_id:, profile_date:)
stored_rating_profile(participant_id: participant_id, profile_date: profile_date)
end

def fetch_rating_profiles_in_range(participant_id:, start_date:, end_date:)
ratings = get_rating_record(participant_id)[:ratings] || []
# Simulate the response if participant doesn't exist or doesn't have any ratings
Expand Down Expand Up @@ -446,7 +450,7 @@ def rating_at_issue_profile_data(rating)
# If a PromulgatedRating was originally stored in rating_store
# convert to be compatible with RatingAtIssue
if promulgated_rating_data.present?
rating_profile = fetch_rating_profile(
rating_profile = stored_rating_profile(
participant_id: promulgated_rating_data[:ptcpnt_vet_id],
profile_date: promulgated_rating_data[:prfil_dt]
)
Expand All @@ -464,7 +468,7 @@ def rating_at_issue_profile_data(rating)
end
end

def fetch_rating_profile(participant_id:, profile_date:)
def stored_rating_profile(participant_id:, profile_date:)
normed_date_key = Fakes::RatingStore.normed_profile_date_key(profile_date).to_sym
rating_profile = (get_rating_record(participant_id)[:profiles] || {})[normed_date_key]

Expand Down
48 changes: 31 additions & 17 deletions spec/models/promulgated_rating_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# In comparison, Ratings at issue return both the rating and rating profile information from the RatingProfile service

describe PromulgatedRating do
context ".fetch_timely" do
let(:receipt_date) { Time.zone.today }
let(:receipt_date) { Time.zone.today }
let!(:rating) do
Generators::PromulgatedRating.build(
participant_id: "DRAYMOND",
promulgation_date: receipt_date - 370.days,
profile_date: receipt_date - 370.days
)
end

context ".fetch_timely" do
subject { PromulgatedRating.fetch_timely(participant_id: "DRAYMOND", from_date: receipt_date) }

let!(:rating) do
Generators::PromulgatedRating.build(
participant_id: "DRAYMOND",
promulgation_date: receipt_date - 371.days
)
end

let!(:untimely_rating) do
Generators::PromulgatedRating.build(
participant_id: "DRAYMOND",
Expand All @@ -32,7 +32,7 @@
let!(:another_rating) do
Generators::PromulgatedRating.build(
participant_id: "DRAYMOND",
promulgation_date: receipt_date - 370.days
promulgation_date: receipt_date - 371.days
)
end

Expand Down Expand Up @@ -66,13 +66,6 @@

subject { PromulgatedRating.fetch_all("DRAYMOND") }

let!(:rating) do
Generators::PromulgatedRating.build(
participant_id: "DRAYMOND",
promulgation_date: receipt_date - 370.days
)
end

let!(:untimely_rating) do
Generators::PromulgatedRating.build(
participant_id: "DRAYMOND",
Expand Down Expand Up @@ -116,4 +109,25 @@
)
end
end

context "#rating_profile" do
subject { rating.rating_profile }

context "when BGS throws a Share Error" do
let(:bgs) { Fakes::BGSService.new }

before do
allow(Fakes::BGSService).to receive(:new).and_return(bgs)
allow(bgs).to receive(:fetch_rating_profile)
.and_raise(BGS::ShareError, "Veteran does not meet the minimum disability requirements")
allow(bgs).to receive(:fetch_rating_profiles_in_range).and_call_original
end

it "Fetches the rating profile using RatingAtIssue" do
expect(subject.present?)
expect { rating.issues }.to_not raise_error
expect(bgs).to have_received(:fetch_rating_profiles_in_range)
end
end
end
end
4 changes: 0 additions & 4 deletions spec/models/rating_at_issue_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# frozen_string_literal: true

describe RatingAtIssue do
before { FeatureToggle.enable!(:ratings_at_issue) }
after { FeatureToggle.disable!(:ratings_at_issue) }

let(:disability_sn) { "1234" }
let(:diagnostic_code) { "7611" }
let(:reference_id) { "1555" }
Expand Down Expand Up @@ -96,7 +93,6 @@
let!(:unpromulgated_rating) do
Generators::RatingAtIssue.build(
participant_id: "DRAYMOND",
promulgation_date: receipt_date - 100.years,
promulgation_date: nil
)
end
Expand Down