Open malparty opened 3 weeks ago
Thank you for your feedback.
I understand that the core logic should be covered in test.
If I were able to add tests, I would have done the following:
CSV parsing As we discussed in #10, we can refactor the code and move CSV parsing related logic into a separate object. I would create a CSV service object that contains following methods
initialize
: takes file_path
then set it as the property @file_path
read_file
: return rows if CSV.read()
success else []
[]
to be returned.count_rows
: return rows count
parse_objects
: read a file and parse rows to array of Keyword
Keyword
to be returned.** CSV files for test will be at test/fixtures
Keyword creation
I would create another function process_keyword
that meant process a single keyword.
Then I would call multiple process_keyword
inside a parent function (currently import_csv)
Test process_keyword
Keyword scraping Scraping can be split into 2 parts
initialize
: takes response.body
then use Nokogiri::HTML() to parse it into HTML document and set property @document
.extract_ads
:
return CSS selector result for ads element
extract_links
return CSS selector result for link element
extract_search_results
return CSS selector result for search result stats
Keyword listing Some are covered in (test/keywords) test/controllers/keywords_controller_test.rb I would add more assertions to ensure that each column of a row contains the correct data matching the test fixtures.
Thanks for your detailed answer 🙏
Issue
Automated tests do not cover the core business logic (CSV upload, scraping).
Expected
While 100% test coverage is not required for this code challenge, all critical paths of the application should be unit-tested (and, ideally, UI-tested). So the following should be covered: