Skip to content

Commit

Permalink
Tidy up the API mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Oct 25, 2024
1 parent b8f3940 commit 7d1ed39
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function DecoratedStory(Story) {
)
}

const PANOPTES_HOST = process.env.NODE_ENV === 'production'
? 'https://www.zooniverse.org'
: 'https://panoptes-staging.zooniverse.org'

export default {
title: 'Project App / Shared / Subject Picker',
component: SubjectPicker,
Expand All @@ -34,16 +38,7 @@ export default {
rows
})
}),
http.get('https://panoptes-staging.zooniverse.org/api/subjects/selection', ({ request }) => {
return HttpResponse.json({
subjects: [
{ id: 1, already_seen: false, retired: false },
{ id: 2, already_seen: true, retired: false },
{ id: 3, already_seen: true, retired: true }
]
})
}),
http.get('https://www.zooniverse.org/api/subjects/selection', ({ request }) => {
http.get(`${PANOPTES_HOST}/api/subjects/selection`, ({ request }) => {
return HttpResponse.json({
subjects: [
{ id: 1, already_seen: false, retired: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function StoryContext(Story) {
)
}

const PANOPTES_HOST = process.env.NODE_ENV === 'production'
? 'https://www.zooniverse.org'
: 'https://panoptes-staging.zooniverse.org'

export default {
title: 'Project App / Shared / Workflow Selector',
component: WorkflowSelector,
Expand All @@ -89,6 +93,31 @@ export default {
options: asyncStates
}
}
},
parameters: {
msw: {
handlers: [
http.get(`${PANOPTES_HOST}/api/workflows`, ({ request }) => {
const { searchParams } = new URL(request.url)
if (
searchParams.get('fields') === 'configuration' &&
searchParams.get('id') === '9012'
) {
return HttpResponse.json({
workflows: [
{
id: '9012',
configuration: {
level: 3
}
}
]
})
}
return new HttpResponse(null, { status: 404 })
}),
],
},
}
}

Expand Down Expand Up @@ -179,51 +208,6 @@ MissingLevels.args = {
workflows: WORKFLOWS
}

MissingLevels.parameters = {
msw: {
handlers: [
http.get('https://panoptes-staging.zooniverse.org/api/workflows', ({ request }) => {
const { searchParams } = new URL(request.url)
if (
searchParams.get('fields') === 'configuration' &&
searchParams.get('id') === '9012'
) {
return HttpResponse.json({
workflows: [
{
id: '9012',
configuration: {
level: 3
}
}
]
})
}
return new HttpResponse(null, { status: 404 })
}),
http.get('https://www.zooniverse.org/api/workflows', ({ request }) => {
const { searchParams } = new URL(request.url)
if (
searchParams.get('fields') === 'configuration' &&
searchParams.get('id') === '9012'
) {
return HttpResponse.json({
workflows: [
{
id: '9012',
configuration: {
level: 3
}
}
]
})
}
return new HttpResponse(null, { status: 404 })
}),
],
},
}

export function Loading({
uppLoaded,
userReadyState,
Expand Down

0 comments on commit 7d1ed39

Please sign in to comment.