Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom normalizer for non JSON-API compliant payload #1419

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions operator_ui/__tests__/actions.test.js

This file was deleted.

20 changes: 5 additions & 15 deletions operator_ui/__tests__/containers/JobRuns/Index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ describe('containers/JobRuns/Index', () => {
it('renders the runs for the job spec', async () => {
expect.assertions(2)

const runsResponse = jsonApiJobSpecRunFactory(
[
{
jobId: jobSpecId
}
],
jobSpecId
)
const runsResponse = jsonApiJobSpecRunFactory([{ jobId: jobSpecId }])
global.fetch.getOnce(
`/v2/runs?sort=-createdAt&page=1&size=25&jobSpecId=${jobSpecId}`,
runsResponse
Expand All @@ -56,8 +49,7 @@ describe('containers/JobRuns/Index', () => {
expect.assertions(12)

const pageOneResponse = jsonApiJobSpecRunFactory(
[{ id: 'ID-ON-FIRST-PAGE' }],
jobSpecId,
[{ id: 'ID-ON-FIRST-PAGE', jobId: jobSpecId }],
3
)
global.fetch.getOnce(
Expand All @@ -73,8 +65,7 @@ describe('containers/JobRuns/Index', () => {
expect(wrapper.text()).not.toContain('ID-ON-SECOND-PAGE')

const pageTwoResponse = jsonApiJobSpecRunFactory(
[{ id: 'ID-ON-SECOND-PAGE' }],
jobSpecId,
[{ id: 'ID-ON-SECOND-PAGE', jobId: jobSpecId }],
3
)
global.fetch.getOnce(
Expand All @@ -98,8 +89,7 @@ describe('containers/JobRuns/Index', () => {
expect(wrapper.text()).not.toContain('ID-ON-SECOND-PAGE')

const pageThreeResponse = jsonApiJobSpecRunFactory(
[{ id: 'ID-ON-THIRD-PAGE' }],
jobSpecId,
[{ id: 'ID-ON-THIRD-PAGE', jobId: jobSpecId }],
3
)
global.fetch.getOnce(
Expand Down Expand Up @@ -128,7 +118,7 @@ describe('containers/JobRuns/Index', () => {
it('displays an empty message', async () => {
expect.assertions(1)

const runsResponse = jsonApiJobSpecRunFactory([], jobSpecId)
const runsResponse = jsonApiJobSpecRunFactory([])
global.fetch.getOnce(
`/v2/runs?sort=-createdAt&page=1&size=25&jobSpecId=${jobSpecId}`,
runsResponse
Expand Down
16 changes: 6 additions & 10 deletions operator_ui/__tests__/containers/Jobs/Show.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@ const mountShow = props =>
describe('containers/Jobs/Show', () => {
const jobSpecId = 'c60b9927eeae43168ddbe92584937b1b'
const jobRunId = 'ad24b72c12f441b99b9877bcf6cb506e'

it('renders the details of the job spec, its latest runs and task list entries,', async () => {
expect.assertions(7)

const minuteAgo = isoDate(Date.now() - MINUTE_MS)
const jobSpecResponse = jsonApiJobSpecFactory({
id: jobSpecId,
initiators: [{ type: 'web' }],
createdAt: minuteAgo,
runs: [
{
id: 'runA',
status: 'pending',
result: { data: { value: '8400.00' } }
}
]
createdAt: minuteAgo
})
global.fetch.getOnce(`/v2/specs/${jobSpecId}`, jobSpecResponse)

const jobRunResponse = jsonApiJobSpecRunsFactory([
{
id: jobRunId,
jobId: jobSpecId
jobId: jobSpecId,
status: 'pending'
}
])
global.fetch.getOnce(`/v2/specs/${jobSpecId}`, jobSpecResponse)
global.fetch.getOnce(
`/v2/runs?sort=-createdAt&page=1&size=5&jobSpecId=${jobSpecId}`,
jobRunResponse
Expand Down
37 changes: 1 addition & 36 deletions operator_ui/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,41 +273,6 @@ const request = (type, requestData, normalizeData, ...apiArgs) => {
}
}

const normalizeFetchJob = json => {
const attrs = Object.assign({}, json.data.attributes)
const runs = attrs.runs
delete attrs.runs

const validJsonApi = Object.assign(
{},
json,
{
data: {
id: json.data.id,
type: json.data.type,
attributes: attrs,
relationships: {
runs: {
data: (runs || []).map(r => ({
type: 'runs',
id: r.id
}))
}
}
}
},
{
included: (runs || []).map(r => ({
type: 'runs',
id: r.id,
attributes: r
}))
}
)

return normalize(validJsonApi, { camelizeKeys: false })
}

export const fetchAccountBalance = () =>
request('ACCOUNT_BALANCE', api.getAccountBalance, json => normalize(json))

Expand All @@ -329,7 +294,7 @@ export const fetchRecentlyCreatedJobs = size =>
)

export const fetchJob = id =>
request('JOB', api.getJobSpec, json => normalizeFetchJob(json), id)
request('JOB', api.getJobSpec, json => normalize(json), id)

export const fetchJobRuns = (opts: api.JobSpecRunsOpts) =>
request(
Expand Down
18 changes: 10 additions & 8 deletions operator_ui/support/factories/jsonApiJobSpecRuns.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import uuid from 'uuid/v4'
import { decamelizeKeys } from 'humps'

export default (jobs, jobSpecId, count) => {
const j = jobs || []
const jc = count || j.length
export default (runs, count) => {
const r = runs || []
const rc = count || r.length

return decamelizeKeys({
meta: { count: jc },
data: j.map(c => {
meta: { count: rc },
data: r.map(c => {
const config = c || {}
const id = config.id || uuid().replace(/-/g, '')
const jobId = config.jobId || uuid().replace(/-/g, '')
const status = config.status || 'completed'

return {
id: id,
type: 'runs',
attributes: {
id: id,
jobId: jobSpecId,
jobId: jobId,
result: {
jobRunId: id,
data: {
value: { result: 'value' }
},
status: 'completed',
status: status,
error: null
},
status: 'completed',
status: status,
createdAt: '2018-06-18T15:49:33.015913563-04:00',
finishedAt: '2018-06-18T15:49:33.023078819-04:00'
}
Expand Down