Skip to content

Commit

Permalink
Add helper for showing provider rejection reason
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie authored and JamieCleare2525 committed Dec 24, 2024
1 parent 64cd360 commit ad43a9c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/helpers/claims/claim_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ def claim_statuses_for_selection
Claims::Claim::DRAFT_STATUSES.map(&:to_s).include?(status)
}.sort
end

def claim_provider_response(claim)
not_assured_mentor_trainings = claim.mentor_trainings.not_assured
return "" if not_assured_mentor_trainings.blank?

content_tag(:ul, class: "govuk-list") do
not_assured_mentor_trainings.order_by_mentor_full_name.each do |mentor_training|
concat(
content_tag(
:li,
"#{mentor_training.mentor_full_name}: #{mentor_training.reason_not_assured}",
),
)
end
end
end
end
7 changes: 7 additions & 0 deletions app/views/claims/support/claims/samplings/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
</div>
<% end %>

<% if @claim.sampling_provider_not_approved? && @claim.mentor_trainings.not_assured.present? %>
<div class="govuk-inset-text">
<h3 class="govuk-heading-s"><%= t(".provider_response") %></h3>
<p class="govuk-body"><%= claim_provider_response(@claim) %></p>
</div>
<% end %>

<% if @claim.sampling_in_progress? %>
<div class="govuk-button-group">
<%= govuk_button_link_to t(".approve"), confirm_approval_claims_support_claims_sampling_path(@claim) %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/claims/support/claims/samplings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ en:
mentor_with_index: Mentor %{index}
mentor: Mentor
submitted_by: Submitted by %{name} on %{date}.
provider_response: Provider response
confirm_approval:
page_caption: Sampling - Claim %{reference}
page_title: Are you sure you want to approve the claim?
Expand Down
57 changes: 57 additions & 0 deletions spec/helpers/claims/claim_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,61 @@
)
end
end

describe "#claim_provider_response" do
let(:claim) { create(:claim, :submitted, status: :sampling_provider_not_approved) }

context "when the claim has no 'not_assured' mentor trainings" do
it "returns an empty string" do
expect(claim_provider_response(claim)).to eq("")
end
end

context "when the claim has 'not_assured' mentor trainings" do
let(:mentor_john_smith) { create(:claims_mentor, first_name: "John", last_name: "Smith") }
let(:mentor_jane_doe) { create(:claims_mentor, first_name: "Jane", last_name: "Doe") }
let(:mentor_joe_bloggs) { create(:claims_mentor, first_name: "Joe", last_name: "Bloggs") }
let(:john_smith_mentor_training) do
create(
:mentor_training,
mentor: mentor_john_smith,
claim:,
hours_completed: 20,
not_assured: true,
reason_not_assured: "Some reason",
)
end

let(:jane_doe_mentor_training) do
create(
:mentor_training,
mentor: mentor_jane_doe,
claim:,
hours_completed: 20,
not_assured: true,
reason_not_assured: "Another reason",
)
end
let(:joe_bloggs_mentor_training) do
create(
:mentor_training,
mentor: mentor_joe_bloggs,
claim:,
hours_completed: 20,
)
end

before do
john_smith_mentor_training
jane_doe_mentor_training
joe_bloggs_mentor_training
end

it "returns a list of the not assured mentors and the providers reason" do
expect(claim_provider_response(claim)).to eq(
"<ul class=\"govuk-list\"><li>Jane Doe: Another reason</li><li>John Smith: Some reason</li></ul>",
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

when_i_click_on_confirm_and_reject_claim
then_i_see_that_the_claim_has_been_updated_to_provider_not_approved
and_i_see_the_providers_response
end

private
Expand Down Expand Up @@ -195,4 +196,12 @@ def and_i_see_the_new_rejection_details_for_john_smith
expect(page).to have_summary_list_row("Reason for rejection", "New reason the provider rejected John Smith")
end
end

def and_i_see_the_providers_response
expect(page).to have_element(
:div,
text: "Provider response\nJohn Smith: New reason the provider rejected John Smith",
class: "govuk-inset-text",
)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

when_i_click_on_confirm_and_reject_claim
then_i_see_that_the_claim_has_been_updated_to_provider_not_approved
and_i_see_the_providers_response
end

private
Expand Down Expand Up @@ -282,4 +283,12 @@ def when_i_enter_a_reason_why_the_provider_rejected_jane_doe
end
alias_method :and_i_enter_a_reason_why_the_provider_rejected_jane_doe,
:when_i_enter_a_reason_why_the_provider_rejected_jane_doe

def and_i_see_the_providers_response
expect(page).to have_element(
:div,
text: "Provider response\nJane Doe: Provider rejected Jane DoeJohn Smith: Provider rejected John Smith",
class: "govuk-inset-text",
)
end
end

0 comments on commit ad43a9c

Please sign in to comment.