-
-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds coverage for CSV and XLSX file download #10494
Adds coverage for CSV and XLSX file download #10494
Conversation
792f612
to
677156f
Compare
215be32
to
619cadd
Compare
4934af7
to
b993831
Compare
This one is ready for review I think. Some comments:
Happy for your thoughts and reviews. |
This looks good to me 👍 I did some research about the PDF format.
-a, --text
Process a binary file as if it were text; this is equivalent to the --binary-files=text option.
I hope that you'll find this useful :) |
I think the same thing, the system tests are slow. I was thinking about request-level vs object-level tests. what do you think? |
@abdellani
For sure, I agree. I'm not very confident to be able to write PS: maybe we could gain some insight from Matomo on which reports users download which file types the most, and add a request level coverage on those. Maybe a good compromise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
I agree that it's not necessary to have a system test for every test, every format. But it's necessary to test one of the reports using the report framework to ensure it generally works.
I notice that we have a more general spec/system/admin/reports_spec.rb
spec file. Maybe this test could have gone there. But I don't think it really matters.
Here, we test that it works, and can output the three formats. It also tests the content of those two formats that are most crucial (because they are structured data that could be used to import/integrate with other systems).
I had a suggestion, so will put back to in dev. But even if you don't use it, it's ready to go.
CSV.read("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv") | ||
end | ||
it 'as csv' do | ||
expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 downloaded_filenames
looks like a very handy helper! Looks like it was unused until now.
downloaded_xlsx = Roo::Excelx.new(downloaded_filename) | ||
downloaded_content = [downloaded_xlsx.row(1), downloaded_xlsx.row(2), | ||
downloaded_xlsx.row(3), downloaded_xlsx.row(4), | ||
downloaded_xlsx.row(5)] | ||
fixture_xlsx = Roo::Excelx.new(report_file_xlsx) | ||
fixture_content = [fixture_xlsx.row(1), fixture_xlsx.row(2), fixture_xlsx.row(3), | ||
fixture_xlsx.row(4), | ||
fixture_xlsx.row(5)] | ||
expect(downloaded_content).to eq(fixture_content) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why, but I couldn't help but try to reduce the code down :D
downloaded_xlsx = Roo::Excelx.new(downloaded_filename) | |
downloaded_content = [downloaded_xlsx.row(1), downloaded_xlsx.row(2), | |
downloaded_xlsx.row(3), downloaded_xlsx.row(4), | |
downloaded_xlsx.row(5)] | |
fixture_xlsx = Roo::Excelx.new(report_file_xlsx) | |
fixture_content = [fixture_xlsx.row(1), fixture_xlsx.row(2), fixture_xlsx.row(3), | |
fixture_xlsx.row(4), | |
fixture_xlsx.row(5)] | |
expect(downloaded_content).to eq(fixture_content) | |
end | |
downloaded_content = extract_xlsx_rows(downloaded_filename, 1..5) | |
fixture_content = extract_xlsx_rows(report_file_xlsx, 1..5) | |
expect(downloaded_content).to eq(fixture_content) | |
end | |
def extract_xlsx_rows(file, range) | |
xlsx = Roo::Excelx.new(file) | |
range.map { |i| xlsx.row(i) } | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for that suggestion David. I've committed and squashed with the last commit (in which the contexts are added). I wanted to squash with the commit the which I introduced this XLSX test, but this would introduce several conflicts.
Hope this is ok now - moved back to code review.
PDF:
Good idea @abdellani , I think this looks good. It provides a Object-level tests (aka unit tests): |
Reduces code
3a3524c
to
56b9c28
Compare
What? Why?
Adds coverage for sales tax by orders report downloads, for file types:
What should we test?
Release notes
Changelog Category: Technical changes
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates