Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
Mock a linked workflow for a mock request slug.
  • Loading branch information
eatyourgreens committed Sep 28, 2020
1 parent 95292ad commit 99ca725
Showing 1 changed file with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import nock from 'nock'

import { getServerSideProps } from './getServerSideProps'

describe('Components > ProjectHomePage > getServerSideProps', function () {
const PROJECT = {
id: '1',
default_workflow: '1',
primary_language: 'en',
slug: 'test-owner/test-project',
links: {
active_workflows: ['1']
}
}

const TRANSLATION = {
translated_id: 1,
strings: {
display_name: 'Foo'
}
}

const WORKFLOW = {
id: '1',
completeness: 0.4,
grouped: false,
links: {
subject_sets: ['1', '2', '3']
}
}

function subjectSet(id) {
return {
id,
display_name: `test set ${id}`,
set_member_subjects_count: 10
}
}

before(function () {
const slug = 'test-owner/test-project'
const scope = nock('https://panoptes-staging.zooniverse.org/api')
.get('/projects')
.query(query => query.slug === slug)
.reply(200, {
projects: [PROJECT]
})
.get('/translations')
.query(query => {
return query.translated_type === 'workflow'
&& query.translated_id === '1'
&& query.language === 'en'
})
.reply(200, {
translations: [TRANSLATION]
})
.get('/workflows')
.query(query => query.id === '1')
.reply(200, {
workflows: [WORKFLOW],
linked: {
subject_sets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
]
}
})
})

it('should return the project\'s active workflows', async function () {
const params = {
owner: 'test-owner',
project: 'test-project'
}
const query = {}
const req = {}
const res = {}
const { props } = await getServerSideProps({ params, query, req, res })
expect(props.workflows).to.deep.equal([
{
completeness: 0.4,
default: true,
grouped: false,
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
]
}
])
})
})

0 comments on commit 99ca725

Please sign in to comment.