Skip to content

Commit

Permalink
Import row service returns skipped rows
Browse files Browse the repository at this point in the history
When importing a single row can be skipped when:

- the RODA identifier is present and valid
- the financial quarter is present and valid
- the financial year is present and valid
- the actual value is zero
- the refund value is zero
- the comment is empty

We want to be able to show users the rows in their data that were
skipped, to do so the first step is to return a SkippedRow in the
appropriate cases.
  • Loading branch information
mec committed Jan 9, 2024
1 parent e4c4f26 commit 4694ce7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
comments
- add a service that can import a single row of csv that contains either a
Actual, Refund or Activity Comment
- when importing an Activity, Refund or Activity comment, the result can now be
a row that was skipped

## Release 141 - 2023-12-04

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def import!

return false if @activity.nil?

return false if @row.empty?

return false unless authorise_activity(@activity)

return Import::Csv::ActivityActualRefundComment::SkippedRow.new(@row) if @row.empty?

create_record
else
@errors.update(@row.errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,19 +358,29 @@
context "when the row is empty" do
let(:csv_row) { valid_csv_row(actual: "0", refund: "0", comment: "") }

it "returns false without an error" do
row = double(Import::Csv::ActivityActualRefundComment::Row, valid?: true, empty?: true)
allow(row).to receive(:roda_identifier)
it "returns a skipped row instance" do
row = double(
Import::Csv::ActivityActualRefundComment::Row,
valid?: true,
empty?: true,
roda_identifier: "VALID-RODA-IDENTIFIER",
financial_quarter: "2",
financial_year: "2023"
)
allow(Import::Csv::ActivityActualRefundComment::Row).to receive(:new).and_return(row)

allow(subject).to receive(:find_activity).and_return(activity)
allow(subject).to receive(:authorise_activity).and_return(true)

result = subject.import!
errors = subject.errors

expect(result).to be false

expect(errors.count).to be_zero

expect(result).to be_a Import::Csv::ActivityActualRefundComment::SkippedRow
expect(result.roda_identifier).to eql "VALID-RODA-IDENTIFIER"
expect(result.financial_quarter).to eql "2"
expect(result.financial_year).to eql "2023"
end
end

Expand Down

0 comments on commit 4694ce7

Please sign in to comment.