Skip to content

Commit

Permalink
Csv import actuals cannot be negative
Browse files Browse the repository at this point in the history
An Actuals value must never be negative, here we add the validation to
the `Import::Csv::ActivityActualRefundComment::Row`.
  • Loading branch information
mec committed Jan 10, 2024
1 parent 4057fc7 commit c7e5513
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- add a new Activity tag, Strategic Allocation Pot (SAP), code 8
- model a single row of csv data that contains actual, refund and activity
comments
- the new actual, refund and activity importer no longer accepts negative actual
values

## Release 141 - 2023-12-04

Expand Down
6 changes: 6 additions & 0 deletions app/models/import/csv/activity_actual_refund_comment/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ def receiving_organisation_iati_reference
@errors["Actual Value"] = [original_actual_value, I18n.t("import.csv.activity_actual_refund_comment.errors.financial_value")]
return false
end

if actual_value.negative?
@errors["Actual Value"] = [original_actual_value, I18n.t("import.csv.activity_actual_refund_comment.errors.default.negative")]
return false
end

true
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ en:
errors:
default:
required: Is required
negative: Cannot be negative
financial_quarter: Must be 1, 2, 3 or 4
financial_year: Must be a four digit year
financial_value: Must be a financial value
Expand Down
10 changes: 10 additions & 0 deletions spec/models/import/csv/activity_actual_refund_comment/row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@
end

context "when the actual value is a number" do
context "and the number is negative" do
let(:csv_row) { valid_csv_row(actual: "-10000", refund: "0", comment: "") }

it "is invaid with an error message and the original value" do
expect(subject).to be_invalid
expect(error_for_column("Actual Value").message).to eql "Cannot be negative"
expect(error_for_column("Actual Value").value).to eql "-10000"
end
end

context "and the refund value is zero" do
context "and there is no comment" do
let(:csv_row) { valid_csv_row(actual: "10000", refund: "0", comment: "") }
Expand Down

0 comments on commit c7e5513

Please sign in to comment.