Plots2: Add more functional tests for each method in Search API

Created on 22 Jan 2018  ·  3Comments  ·  Source: publiclab/plots2

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

The problem

Tests help us ensure that the site behaves as we expect it to -- and that as new features are added, they don't break existing functions. We're working to get to near 100% "coverage" -- which would mean all our code is covered by tests.
We have good tests written for the typeahead API, here: https://github.com/publiclab/plots2/blob/master/test/functional/typeahead_api_test.rb

This tests each method in: https://github.com/publiclab/plots2/blob/master/app/api/srch/typeahead.rb

But we should have similar ones for the search API, for each of the methods in: https://github.com/publiclab/plots2/blob/master/app/api/srch/search.rb

(Note that these draw heavily on this file, in turn -- in case you want to know how they're generated: https://github.com/publiclab/plots2/blob/master/app/services/search_service.rb)

Solution

In #1409, a first-time contributor recently created a new test file, and a single test, which you can find at test/functional/search_api_test.rb:

test 'search notes functionality' do
get '/api/srch/notes?srchString=Blog'
assert last_response.ok?
# more stuff after this
This is a basic test that the response is "ok" and then it goes on to test what's in the response. See how it uses a URL to access the notes method on this line:

So, copy it, and follow the provided URL examples in search.rb to create a new test for a different method. For example, profiles: https://github.com/publiclab/plots2/blob/master/app/api/srch/search.rb#L30

Start by just asserting last_response.ok? as above; we can add more substantive tests later.

You can try running this with rake test or (just to run the functional tests only) rake test TEST=test/functional/search_api_test.rb -- hopefully it will pass!

But you can also just open a pull request (see below) and our automated test system will run it, and you'll be able to see the output there.

If you can help with this, please open a pull request with this test added, and let's see how it goes -- even if it doesn't pass, we can help you with the next steps.

Steps to Fix

claim this issue with a comment here, below, and ask any clarifying questions you need
set up a repository locally following the README instructions, and make sure that all tests pass
try to fix the issue following the steps above, but even before you're done, you can:
commit your changes and start a pull request (see contributing to Public Lab software) but mark it as "in progress" if you have questions or if you haven't finished
alert someone via the developers list (see below) to have your pull request merged. This may take a few extra steps depending on when you do it, but we'll help you out!
Please email the developers list (see https://publiclab.org/wiki/developers) or go to the chatroom if you have questions, and take a look at our first-timers landing page for more information!

Ruby first-timers-only help wanted testing

All 3 comments

This is looking good, @Gauravano ! Maybe a little more formatting with headers, perhaps? Thank you!

Can I claim this?

yes, that would be great.

Was this page helpful?
0 / 5 - 0 ratings