Skip to content

Commit

Permalink
upload eligible FE CSV now handles currency values
Browse files Browse the repository at this point in the history
  • Loading branch information
asmega committed Nov 7, 2024
1 parent 8a4b579 commit 8c19a95
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/eligible_fe_providers_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def delete_all_scope
def row_to_hash(row)
{
ukprn: row.fetch("ukprn"),
max_award_amount: row.fetch("max_award_amount"),
lower_award_amount: row.fetch("lower_award_amount"),
max_award_amount: row.fetch("max_award_amount").gsub(/£|,/, ""),
lower_award_amount: row.fetch("lower_award_amount").gsub(/£|,/, ""),
primary_key_contact_email_address: row.fetch("primary_key_contact_email_address"),
academic_year:
}
Expand Down
29 changes: 29 additions & 0 deletions spec/models/eligible_fe_providers_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,34 @@ def to_row(hash)
end
end
end

context "when currency values has GBP symbols and thousand separators" do
before do
file.write correct_headers

3.times do
file.write to_row(attributes_for(:eligible_fe_provider).merge(max_award_amount: '"£6,000"', lower_award_amount: '"£3,000"'))
end

file.close
end

it "ignores superfluous characters and imports new records" do
expect { subject.run }.to change { EligibleFeProvider.count }.by(3)
expect(EligibleFeProvider.pluck(:max_award_amount).uniq).to eql([6000])
expect(EligibleFeProvider.pluck(:lower_award_amount).uniq).to eql([3000])
end

context "when there are existing records" do
before do
create(:eligible_fe_provider)
create(:eligible_fe_provider, academic_year: AcademicYear.next)
end

it "deletes them with new records" do
expect { subject.run }.to change { EligibleFeProvider.count }.by(2)
end
end
end
end
end

0 comments on commit 8c19a95

Please sign in to comment.