From d516027ec77d2910081028fc095dc241128e37c5 Mon Sep 17 00:00:00 2001
From: Ben Abraham <16797406+Kizr@users.noreply.github.com>
Date: Fri, 3 Jan 2025 15:19:52 +0000
Subject: [PATCH] Validate against hours completed
---
.../_check_your_answers_step.html.erb | 1 +
.../_mentor_training_clawback_step.html.erb | 2 +-
.../check_your_answers_step.rb | 2 +-
.../mentor_training_clawback_step.rb | 4 ++--
.../claims/request_clawback_wizard.yml | 3 ++-
.../support_user_requests_a_clawback_spec.rb | 12 +++++++----
.../mentor_training_clawback_step_spec.rb | 20 +++++++++++++++++++
.../claims/request_clawback_wizard_spec.rb | 2 +-
8 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/app/views/wizards/claims/request_clawback_wizard/_check_your_answers_step.html.erb b/app/views/wizards/claims/request_clawback_wizard/_check_your_answers_step.html.erb
index 91510e3ad..c32f6f38c 100644
--- a/app/views/wizards/claims/request_clawback_wizard/_check_your_answers_step.html.erb
+++ b/app/views/wizards/claims/request_clawback_wizard/_check_your_answers_step.html.erb
@@ -7,6 +7,7 @@
<%= t(".title") %>
+ <%= t(".total_title") %>
<%= govuk_summary_list(html_attributes: { id: "clawback-totals" }) do |summary_list| %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t(".number_of_hours")) %>
diff --git a/app/views/wizards/claims/request_clawback_wizard/_mentor_training_clawback_step.html.erb b/app/views/wizards/claims/request_clawback_wizard/_mentor_training_clawback_step.html.erb
index 64a1543f1..5955848fd 100644
--- a/app/views/wizards/claims/request_clawback_wizard/_mentor_training_clawback_step.html.erb
+++ b/app/views/wizards/claims/request_clawback_wizard/_mentor_training_clawback_step.html.erb
@@ -20,7 +20,7 @@
<%= f.govuk_text_field :number_of_hours,
width: 2,
label: { text: t(".hours"), size: "s" },
- hint: { text: t(".hours_hint") } %>
+ hint: { text: t(".hours_hint", hours_completed: current_step.mentor_training.hours_completed) } %>
diff --git a/app/wizards/claims/request_clawback_wizard/check_your_answers_step.rb b/app/wizards/claims/request_clawback_wizard/check_your_answers_step.rb
index ba5f7f29c..c2e85be2b 100644
--- a/app/wizards/claims/request_clawback_wizard/check_your_answers_step.rb
+++ b/app/wizards/claims/request_clawback_wizard/check_your_answers_step.rb
@@ -8,7 +8,7 @@ def mentor_training_clawback_data(mentor_training)
end
def mentor_training_clawback_hours(mentor_training)
- mentor_training_clawback_data(mentor_training).number_of_hours
+ mentor_training_clawback_data(mentor_training).number_of_hours.to_i
end
def mentor_training_clawback_amount(mentor_training)
diff --git a/app/wizards/claims/request_clawback_wizard/mentor_training_clawback_step.rb b/app/wizards/claims/request_clawback_wizard/mentor_training_clawback_step.rb
index a204253d9..d859cd403 100644
--- a/app/wizards/claims/request_clawback_wizard/mentor_training_clawback_step.rb
+++ b/app/wizards/claims/request_clawback_wizard/mentor_training_clawback_step.rb
@@ -1,10 +1,10 @@
class Claims::RequestClawbackWizard::MentorTrainingClawbackStep < BaseStep
attribute :mentor_training_id
- attribute :number_of_hours, :integer
+ attribute :number_of_hours
attribute :reason_for_clawback
validates :mentor_training_id, presence: true
- validates :number_of_hours, presence: true, numericality: { only_integer: true, less_than_or_equal_to: 20 }
+ validates :number_of_hours, presence: true, numericality: { only_integer: true, less_than_or_equal_to: proc { |step| step.mentor_training.hours_completed } }
validates :reason_for_clawback, presence: true
delegate :mentor_trainings, to: :wizard
diff --git a/config/locales/en/wizards/claims/request_clawback_wizard.yml b/config/locales/en/wizards/claims/request_clawback_wizard.yml
index 711cc009b..5a5f92b91 100644
--- a/config/locales/en/wizards/claims/request_clawback_wizard.yml
+++ b/config/locales/en/wizards/claims/request_clawback_wizard.yml
@@ -6,7 +6,7 @@ en:
page_title: Clawback details for %{mentor_name} - %{school_name} - Claim %{reference}
title: Clawback details for %{mentor_name}
hours: Number of hours to clawback
- hours_hint: Enter whole numbers up to a maximum of 20 hours
+ hours_hint: Enter whole numbers up to a maximum of %{hours_completed} hours
reason: Notes on your decision
reason_hint: Only include details related to %{mentor_name}
continue: Continue
@@ -16,6 +16,7 @@ en:
check_your_answers_step:
page_title: Check your answers - %{school_name} - Claim %{reference}
title: Check your answers
+ total_title: Total clawback
mentor_training_title: Clawback request for %{mentor_name}
rate: Hourly rate
number_of_hours: Number of hours
diff --git a/spec/system/claims/support/claims/clawbacks/support_user_requests_a_clawback_spec.rb b/spec/system/claims/support/claims/clawbacks/support_user_requests_a_clawback_spec.rb
index 53a5a6407..5400cb03b 100644
--- a/spec/system/claims/support/claims/clawbacks/support_user_requests_a_clawback_spec.rb
+++ b/spec/system/claims/support/claims/clawbacks/support_user_requests_a_clawback_spec.rb
@@ -54,8 +54,12 @@ def given_claims_exist
@john_doe = create(:claims_mentor, first_name: "John", last_name: "Doe")
@jane_smith = create(:claims_mentor, first_name: "Jane", last_name: "Smith")
- @john_doe_training = create(:mentor_training, claim: @claim_one, mentor: @john_doe, not_assured: true, reason_not_assured: "Mismatch in hours recorded compared with hours claimed.")
- @jane_smith_training = create(:mentor_training, claim: @claim_one, mentor: @jane_smith, not_assured: true, reason_not_assured: "Mismatch in hours recorded compared with hours claimed.")
+ @john_doe_training = create(:mentor_training, claim: @claim_one, mentor: @john_doe,
+ hours_completed: 20, not_assured: true,
+ reason_not_assured: "Mismatch in hours recorded compared with hours claimed.")
+ @jane_smith_training = create(:mentor_training, claim: @claim_one, mentor: @jane_smith,
+ hours_completed: 20, not_assured: true,
+ reason_not_assured: "Mismatch in hours recorded compared with hours claimed.")
end
def and_i_am_signed_in
@@ -98,7 +102,7 @@ def then_i_see_the_show_page_for_claim_one
expect(page).to have_h2("Grant funding")
expect(page).to have_summary_list_row("Total hours", "#{@claim_one.mentor_trainings.sum(:hours_completed)} hours")
expect(page).to have_summary_list_row("Hourly rate", @claim_one.school.region.funding_available_per_hour)
- expect(page).to have_summary_list_row("Claim amount", @claim_one.amount)
+ expect(page).to have_summary_list_row("Claim amount", @claim_one.amount.format(symbol: true, decimal_mark: ".", no_cents: true))
end
def when_i_click_on_request_clawback
@@ -209,7 +213,7 @@ def and_i_see_the_claim_status_is_clawback_requested
"academic_year" => @claim_one.academic_year.name,
"provider_name" => @claim_one.provider.name,
"submitted_at" => I18n.l(@claim_one.submitted_at.to_date, format: :long),
- "amount" => @claim_one.amount,
+ "amount" => @claim_one.amount.format(symbol: true, decimal_mark: ".", no_cents: true),
})
end
end
diff --git a/spec/wizards/claims/request_clawback_wizard/mentor_training_clawback_step_spec.rb b/spec/wizards/claims/request_clawback_wizard/mentor_training_clawback_step_spec.rb
index a1a8d65b2..a40f1ee59 100644
--- a/spec/wizards/claims/request_clawback_wizard/mentor_training_clawback_step_spec.rb
+++ b/spec/wizards/claims/request_clawback_wizard/mentor_training_clawback_step_spec.rb
@@ -19,9 +19,29 @@
end
describe "validations" do
+ let(:mentor_training) { create(:mentor_training, claim:, hours_completed: 3, not_assured: true, reason_not_assured: "reason") }
+
it { is_expected.to validate_presence_of(:mentor_training_id) }
it { is_expected.to validate_presence_of(:number_of_hours) }
it { is_expected.to validate_presence_of(:reason_for_clawback) }
+
+ context "when the number of hours is greater than the hours completed" do
+ let(:attributes) { { mentor_training_id: mentor_training.id, number_of_hours: 4, reason_for_clawback: "reason" } }
+
+ it { is_expected.not_to be_valid }
+ end
+
+ context "when the number of hours is less than the hours completed" do
+ let(:attributes) { { mentor_training_id: mentor_training.id, number_of_hours: 1, reason_for_clawback: "reason" } }
+
+ it { is_expected.to be_valid }
+ end
+
+ context "when the number of hours is equal to the hours completed" do
+ let(:attributes) { { mentor_training_id: mentor_training.id, number_of_hours: 3, reason_for_clawback: "reason" } }
+
+ it { is_expected.to be_valid }
+ end
end
describe "delegations" do
diff --git a/spec/wizards/claims/request_clawback_wizard_spec.rb b/spec/wizards/claims/request_clawback_wizard_spec.rb
index 5b4af6bf9..f54522228 100644
--- a/spec/wizards/claims/request_clawback_wizard_spec.rb
+++ b/spec/wizards/claims/request_clawback_wizard_spec.rb
@@ -10,7 +10,7 @@
let(:params_data) { {} }
let(:params) { ActionController::Parameters.new(params_data) }
let(:claim) { create(:claim, status: "sampling_in_progress") }
- let!(:mentor_training) { create(:mentor_training, claim:, not_assured: true, reason_not_assured: "reason") }
+ let!(:mentor_training) { create(:mentor_training, claim:, not_assured: true, reason_not_assured: "reason", hours_completed: 20) }
before do
allow(claim).to receive(:save!).and_return(true)