diff --git a/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.js b/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.js index 0331b65572..289572ad91 100644 --- a/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.js +++ b/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.js @@ -36,7 +36,10 @@ export default async function subjectSelectionStrategy(workflow, subjectIDs, pri /** fetch ordered subjects for indexed subject sets */ if (workflow.hasIndexedSubjects) { const apiUrl = '/subjects/selection' - const ids = await getIndexedSubjects(workflow.subjectSetId, priority) + let ids = await getIndexedSubjects(workflow.subjectSetId, priority) + if (ids === '') { + ids = await getIndexedSubjects(workflow.subjectSetId) + } const params = { ids, workflow_id diff --git a/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.spec.js b/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.spec.js index 76b9eab79f..5d98d9c9e6 100644 --- a/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.spec.js +++ b/packages/lib-classifier/src/store/helpers/subjectSelectionStrategy/subjectSelectionStrategy.spec.js @@ -109,6 +109,7 @@ describe('Store > Helpers > subjectSelectionStrategy', function () { before(async function () { nock('https://subject-set-search-api.zooniverse.org') + .persist(true) .get('/subjects/2.json') .query(query => query.priority__gt === '-1') .reply(200, { @@ -127,6 +128,16 @@ describe('Store > Helpers > subjectSelectionStrategy', function () { ['56789', '3'] ] }) + .get('/subjects/2.json') + .query(query => query.priority__gt === '3') + .reply(200, { + columns: ['subject_id', 'priority'], + rows: [] + }) + }) + + after(function () { + nock.cleanAll() }) describe('with a subject priority', function () { @@ -154,6 +165,31 @@ describe('Store > Helpers > subjectSelectionStrategy', function () { }) }) + describe('at the end of a set', function () { + before(async function () { + const workflow = WorkflowFactory.build({ + id: '12345', + grouped: true, + prioritized: true, + hasIndexedSubjects: true, + subjectSetId: '2' + }) + let subjectIDs + strategy = await subjectSelectionStrategy(workflow, subjectIDs, '3') + }) + + it(`should use the /subjects/selection endpoint`, function () { + expect(strategy.apiUrl).to.equal('/subjects/selection') + }) + + it('should query by workflow and the first subjects in the set', function () { + expect(strategy.params).to.deep.equal({ + ids: '12345,34567,56789', + workflow_id: '12345' + }) + }) + }) + describe('without a subject priority', function () { before(async function () { const workflow = WorkflowFactory.build({