Skip to content

Commit

Permalink
Loop back to the beginning of an indexed set
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed May 10, 2021
1 parent 58b6ae7 commit 2583c95
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 2583c95

Please sign in to comment.