From a0f0347a9f2f9bbd5fcacd44aa756da633f54547 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Mon, 8 Feb 2021 16:39:38 +0000 Subject: [PATCH] Add cellect API to tests --- .../fetchWorkflowsHelper.spec.js | 127 +++++++++++------- .../getDefaultPageProps.spec.js | 30 ++++- .../getStaticPageProps.spec.js | 30 ++++- 3 files changed, 123 insertions(+), 64 deletions(-) diff --git a/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.spec.js b/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.spec.js index fb645cb8c69..fa7f5dfb27a 100644 --- a/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.spec.js +++ b/packages/app-project/src/helpers/fetchWorkflowsHelper/fetchWorkflowsHelper.spec.js @@ -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') @@ -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]}) ] } ]) @@ -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]}) ] }, { @@ -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]}) ] } ]) @@ -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]}) ] }, { @@ -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]}) ] } ]) diff --git a/packages/app-project/src/helpers/getDefaultPageProps/getDefaultPageProps.spec.js b/packages/app-project/src/helpers/getDefaultPageProps/getDefaultPageProps.spec.js index 10daffc8c12..f85aa7627e4 100644 --- a/packages/app-project/src/helpers/getDefaultPageProps/getDefaultPageProps.spec.js +++ b/packages/app-project/src/helpers/getDefaultPageProps/getDefaultPageProps.spec.js @@ -29,6 +29,12 @@ describe('Components > ProjectHomePage > getDefaultPageProps', function () { } } + const availableSubjects = { + 1: 4, + 2: 10, + 3: 10 + } + function subjectSet(id) { return { id, @@ -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') @@ -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]}) ] } ]) @@ -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') @@ -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]}) ] } ]) diff --git a/packages/app-project/src/helpers/getStaticPageProps/getStaticPageProps.spec.js b/packages/app-project/src/helpers/getStaticPageProps/getStaticPageProps.spec.js index fcdf75299ec..a4a4d4dfceb 100644 --- a/packages/app-project/src/helpers/getStaticPageProps/getStaticPageProps.spec.js +++ b/packages/app-project/src/helpers/getStaticPageProps/getStaticPageProps.spec.js @@ -29,6 +29,12 @@ describe('Helpers > getStaticPageProps', function () { } } + const availableSubjects = { + 1: 4, + 2: 10, + 3: 10 + } + function subjectSet(id) { return { id, @@ -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') @@ -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]}) ] } ]) @@ -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') @@ -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]}) ] } ])