Skip to content

Commit

Permalink
Add cellect API to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Feb 18, 2021
1 parent 70564d5 commit a0f0347
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,73 @@ import nock from 'nock'

import fetchWorkflowsHelper from './fetchWorkflowsHelper'

const WORKFLOWS = [
{
id: '1',
completeness: 0.4,
grouped: false,
links: {
subject_sets: ['1', '2', '3']
describe('Helpers > fetchWorkflowsHelper', function () {
const WORKFLOWS = [
{
id: '1',
completeness: 0.4,
grouped: false,
links: {
subject_sets: ['1', '2', '3']
}
},
{
id: '2',
completeness: 0.7,
grouped: false,
links: {
subject_sets: ['1', '2', '3']
}
}
},
{
id: '2',
completeness: 0.7,
grouped: false,
links: {
subject_sets: ['1', '2', '3']
]

// `translated_id` is a number because of a bug in the translations API :(
const TRANSLATIONS = [
{
translated_id: 1,
strings: {
display_name: 'Foo'
}
},
{
translated_id: 2,
strings: {
display_name: 'Bar'
}
}
]

const availableSubjects = {
1: 4,
2: 10,
3: 10
}
]

// `translated_id` is a number because of a bug in the translations API :(
const TRANSLATIONS = [
{
translated_id: 1,
strings: {
display_name: 'Foo'
}
},
{
translated_id: 2,
strings: {
display_name: 'Bar'

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

function subjectSet(id) {
return {
id,
display_name: `test set ${id}`,
set_member_subjects_count: 10
}
}
before(function () {
const cellect = nock('https://cellect.zooniverse.org')
.persist()
.get('/workflows/1/status')
.reply(200, {
groups: availableSubjects
})
.get('/workflows/2/status')
.reply(200, {
groups: availableSubjects
})
})

after(function () {
nock.cleanAll()
})

describe('Helpers > fetchWorkflowsHelper', function () {
it('should provide the expected result with a single workflow', async function () {
const scope = nock('https://panoptes-staging.zooniverse.org/api')
.get('/translations')
Expand Down Expand Up @@ -76,9 +99,9 @@ describe('Helpers > fetchWorkflowsHelper', function () {
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
}
])
Expand Down Expand Up @@ -113,9 +136,9 @@ describe('Helpers > fetchWorkflowsHelper', function () {
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
},
{
Expand All @@ -125,9 +148,9 @@ describe('Helpers > fetchWorkflowsHelper', function () {
id: '2',
displayName: 'Bar',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
}
])
Expand Down Expand Up @@ -163,9 +186,9 @@ describe('Helpers > fetchWorkflowsHelper', function () {
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
},
{
Expand All @@ -175,9 +198,9 @@ describe('Helpers > fetchWorkflowsHelper', function () {
id: '2',
displayName: 'Bar',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe('Components > ProjectHomePage > getDefaultPageProps', function () {
}
}

const availableSubjects = {
1: 4,
2: 10,
3: 10
}

function subjectSet(id) {
return {
id,
Expand All @@ -40,6 +46,12 @@ describe('Components > ProjectHomePage > getDefaultPageProps', function () {
describe('with the staging API', function () {
before(function () {
const slug = 'test-owner/test-project'
const cellect = nock('https://cellect.zooniverse.org')
.persist()
.get('/workflows/1/status')
.reply(200, {
groups: availableSubjects
})
const scope = nock('https://panoptes-staging.zooniverse.org/api')
.persist()
.get('/projects')
Expand Down Expand Up @@ -111,9 +123,9 @@ describe('Components > ProjectHomePage > getDefaultPageProps', function () {
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
}
])
Expand Down Expand Up @@ -199,6 +211,12 @@ describe('Components > ProjectHomePage > getDefaultPageProps', function () {
describe('with the production API', function () {
before(function () {
const slug = 'test-owner/test-project'
const cellect = nock('https://cellect.zooniverse.org')
.persist()
.get('/workflows/1/status')
.reply(200, {
groups: availableSubjects
})
const scope = nock('https://www.zooniverse.org/api')
.persist()
.get('/projects')
Expand Down Expand Up @@ -270,9 +288,9 @@ describe('Components > ProjectHomePage > getDefaultPageProps', function () {
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe('Helpers > getStaticPageProps', function () {
}
}

const availableSubjects = {
1: 4,
2: 10,
3: 10
}

function subjectSet(id) {
return {
id,
Expand All @@ -40,6 +46,12 @@ describe('Helpers > getStaticPageProps', function () {
describe('with the staging API', function () {
before(function () {
const slug = 'test-owner/test-project'
const cellect = nock('https://cellect.zooniverse.org')
.persist()
.get('/workflows/1/status')
.reply(200, {
groups: availableSubjects
})
const scope = nock('https://panoptes-staging.zooniverse.org/api')
.persist()
.get('/projects')
Expand Down Expand Up @@ -102,9 +114,9 @@ describe('Helpers > getStaticPageProps', function () {
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
}
])
Expand Down Expand Up @@ -164,6 +176,12 @@ describe('Helpers > getStaticPageProps', function () {
describe('with the production API', function () {
before(function () {
const slug = 'test-owner/test-project'
const cellect = nock('https://cellect.zooniverse.org')
.persist()
.get('/workflows/1/status')
.reply(200, {
groups: availableSubjects
})
const scope = nock('https://www.zooniverse.org/api')
.persist()
.get('/projects')
Expand Down Expand Up @@ -226,9 +244,9 @@ describe('Helpers > getStaticPageProps', function () {
id: '1',
displayName: 'Foo',
subjectSets: [
subjectSet('1'),
subjectSet('2'),
subjectSet('3')
Object.assign(subjectSet('1'), { availableSubjects: availableSubjects[1]}),
Object.assign(subjectSet('2'), { availableSubjects: availableSubjects[2]}),
Object.assign(subjectSet('3'), { availableSubjects: availableSubjects[3]})
]
}
])
Expand Down

0 comments on commit a0f0347

Please sign in to comment.