Skip to content

Automated tests

Mark Woodhall requested to merge automated-tests into master

This has turned into a rather large PR but is actually quite isolated, much of the change is around the implementation of automated tests for the API.

Bugs

There are also a number of small bug fixes:

  1. CrossRef/rest-api-doc#319
  2. CrossRef/rest-api-doc#289
  3. CrossRef/rest-api-doc#306

Features

The implementation of the new Peer Review content type:

  1. CrossRef/rest-api-doc#327

Other notable commits include:

  1. https://github.com/CrossRef/cayenne/commit/41ac6489206b6ee39d337f0407bae3b28127a7a5 - This includes an upgrade to congomongo and a change to use mass-insert! to improve funder loading.

Tests

The story around automated api tests is as follow:

  1. Solr and MongoDB are spun up using docker-compose, this will happen automatically as part of a lein test because we make use of api-fixture. We may want to make this an explicit step that someone runs in isolation but I've found it useful as it is, for now.

  2. Ping MongoDB/Solr and stall until they are responding successfully.

  3. The API is started with (start-core! :default :api).

  4. Inject any required config changes into the running core. As an example, set the funders rdf location to a local file:

(with-core :default
  (->> (.getPath (resource "registry.rdf"))
           (str "file://")
           (set-param! [:location :cr-funder-registry])))
  1. Redef (it's the only real option) any functions that require "mocking" and insert any sample data required for testing. As an example, loading funders:
(with-redefs 
    [cayenne.tasks.funder/get-country-literal-name 
    (fn [model node] 
      (let [url (rdf/->uri (first (rdf/objects (select-country-stmts model node))))]
        (case url
          "http://sws.geonames.org/2921044/" "Germany"
          "http://sws.geonames.org/6252001/" "United States"
          "http://sws.geonames.org/2077456/" "Australia"
          "http://sws.geonames.org/337996/" "Ethiopia"
          "http://sws.geonames.org/1814991/" "China"
          "http://sws.geonames.org/2635167/" "United Kingdom"
          "http://sws.geonames.org/3144096/" "Norway"
          "http://sws.geonames.org/2661886/" "Sweden"
          "http://sws.geonames.org/1861060/" "Japan"
          url)))]
   (load-funders))
  1. Run applicable tests.

  2. Stop the API with (stop-core! :default).

  3. Stop Solr and MongoDB with docker-compose.

Tests are added for the following endpoints:

Funders

  1. /funders/
  2. /funders?offset={offset}
  3. /funders/{funder-id}

Journals

  1. /journals/
  2. /journals/{issn}
  3. /journals/{issn}/works
  4. /journals?offset={offset}

Works

  1. /works/
  2. /works/{doi}
  3. /works?query={query} - Limited to a subset of possible queries
  4. /works?filter={filter} - Limited to a subset of possible filters
  5. /works?select={select} - Limited to a subset of selectable fields
  6. /works/{doi}/ageny

It's worth noting that none of the source feed xml used for testing have been included as part of this pull request, they are still under consideration as there are issues with redistributing them.

Merge request reports