RusticiSoftware/TinCanJS — pull request #95 by pascallaliberte (2014-12-02 21:33:47+00:00)
Title: Fix for when zero (or too few) statements are returned but a more URL is returned

Some LRSes* are implemented in such a way that their index are optimized for certain combination of filters.

When statements are queried with filters that don't match the internal index of the LRS in question, the LRS will draw from a best-case internal index (matching some of the requested filters, but not all) and will filter out the statements against the additional filter not part of the index. In some cases, the returned result set has zero statements, and these LRSes also return a 'more' URL indicating more statements can be fetched. In some cases, just a few statements will be returned (fewer than expected, if a limit filter is set), and the 'more' URL is return to also indicate that more statement can be fetched.

This pull request contains a private method (`_ensureStatementsReturned`) that detects this implementation idiosyncrasy and pages through the 'more' URLs until enough statements are returned. It's called from the `queryStatements` and `moreStatements` methods.

This pull request also includes unit tests method to fetch the 'first found' statement from a configured LRS, against a configurable list of test scenarios that poll the LRS for given filters and check the returned statement_id is the one expected.

In addition, this pull request includes unit tests for the queryStatements method, writing arbitrary statements with one-time verbs, actors and activity_ids and then querying for them. A delay before querying can be configured to account for LRSes that take some time to index the newly sent statements.

* The LRS used in my tests was Saltbox's WaxLRS. I assumed that more LRSes address indexing efficiency by setting up indexes based on pre-determined filter combinations, which is why I'm proposing to modify the core libraries as opposed to writing a wrapper or implementing these checks at the application level.