-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mock a linked workflow for a mock request slug and test the staging and production APIs.
- Loading branch information
1 parent
eee5ebf
commit 0204df7
Showing
1 changed file
with
159 additions
and
0 deletions.
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
packages/app-project/src/screens/ProjectHomePage/getServerSideProps.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
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 | ||
} | ||
} | ||
|
||
describe('with the staging API', function () { | ||
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 = { | ||
env: 'staging' | ||
} | ||
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') | ||
] | ||
} | ||
]) | ||
}) | ||
}) | ||
|
||
describe('with the production API', function () { | ||
before(function () { | ||
const slug = 'test-owner/test-project' | ||
const scope = nock('https://www.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 = { | ||
env: 'production' | ||
} | ||
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') | ||
] | ||
} | ||
]) | ||
}) | ||
}) | ||
}) |