Skip to content

Commit

Permalink
Validate against hours completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kizr committed Jan 3, 2025
1 parent 9241f53 commit 997b301
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<h1 class="govuk-heading-l"><%= t(".title") %></h1>

<h2 class="govuk-heading-m"><%= t(".total_title") %></h2>
<%= 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")) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) } %>
</div>

<div class="govuk-form-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion config/locales/en/wizards/claims/request_clawback_wizard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/wizards/claims/request_clawback_wizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 997b301

Please sign in to comment.