Skip to content

Commit

Permalink
MMT-3409: Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
macrouch committed Oct 24, 2023
1 parent c233749 commit f8537e1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/cmr/concepts/__tests__/draft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('Draft concept', () => {

process.env = { ...OLD_ENV }

process.env.cmrRootUrl = 'http://example.com'
process.env.ummCollectionVersion = '1.0.0'
process.env.ummServiceVersion = '1.0.0'
process.env.ummToolVersion = '1.0.0'
Expand Down
5 changes: 2 additions & 3 deletions src/cmr/concepts/collectionDraftProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ export default class CollectionDraftProposal extends Concept {
}

fetch(searchParams) {
// eslint-disable-next-line no-param-reassign
searchParams = mergeParams(searchParams)
const params = mergeParams(searchParams)

// Default an array to hold the promises we need to make depending on the requested fields
const promises = []
Expand All @@ -106,7 +105,7 @@ export default class CollectionDraftProposal extends Concept {

// Construct the promise that will request data from the umm endpoint
promises.push(
this.fetchUmm(searchParams, ummKeys, ummHeaders)
this.fetchUmm(params, ummKeys, ummHeaders)
)

this.response = Promise.all(promises)
Expand Down
22 changes: 9 additions & 13 deletions src/cmr/concepts/concept.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,14 @@ export default class Concept {
* @param {Object} providedHeaders Headers requested by the query
*/
ingest(data, requestedKeys, providedHeaders) {
// eslint-disable-next-line no-param-reassign
data = mergeParams(data)
const params = mergeParams(data)

this.logKeyRequest(requestedKeys, 'ingest')

// Construct the promise that will ingest data into CMR
this.response = cmrIngest(
this.getConceptType(),
data,
params,
providedHeaders,
this.ingestPath
)
Expand All @@ -383,15 +382,14 @@ export default class Concept {
* @param {Object} providedHeaders Headers requested by the query
*/
delete(data, requestedKeys, providedHeaders) {
// eslint-disable-next-line no-param-reassign
data = mergeParams(data)
const params = mergeParams(data)

this.logKeyRequest(requestedKeys, 'ingest')

// Construct the promise that will delete data from CMR
this.response = cmrDelete(
this.getConceptType(),
data,
params,
providedHeaders,
this.ingestPath
)
Expand Down Expand Up @@ -455,8 +453,7 @@ export default class Concept {
* @param {Object} searchParams Parameters provided by the query
*/
fetch(searchParams) {
// eslint-disable-next-line no-param-reassign
searchParams = mergeParams(searchParams)
const params = mergeParams(searchParams)

// Default an array to hold the promises we need to make depending on the requested fields
const promises = []
Expand All @@ -469,11 +466,10 @@ export default class Concept {

const {
cursor
} = searchParams
} = params

if (cursor) {
// eslint-disable-next-line no-param-reassign
delete searchParams.cursor
delete params.cursor
}

const {
Expand All @@ -493,7 +489,7 @@ export default class Concept {
}

promises.push(
this.fetchJson(this.arrayifyParams(searchParams), jsonKeys, jsonHeaders)
this.fetchJson(this.arrayifyParams(params), jsonKeys, jsonHeaders)
)
} else {
// Push a null promise to the array so that the umm promise always exists as
Expand All @@ -516,7 +512,7 @@ export default class Concept {

// Construct the promise that will request data from the umm endpoint
promises.push(
this.fetchUmm(this.arrayifyParams(searchParams), ummKeys, ummHeaders)
this.fetchUmm(this.arrayifyParams(params), ummKeys, ummHeaders)
)
} else {
promises.push(
Expand Down
10 changes: 5 additions & 5 deletions src/cmr/concepts/draft.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { pick, uniq } from 'lodash'

import { pickIgnoringCase } from '../../utils/pickIgnoringCase'
import Concept from './concept'
import { mergeParams } from '../../utils/mergeParams'
import { cmrIngest } from '../../utils/cmrIngest'

import Concept from './concept'

export default class Draft extends Concept {
/**
* Instantiates a Draft object
Expand All @@ -16,7 +17,7 @@ export default class Draft extends Concept {
super(conceptType, headers, requestInfo, params)

const {
draftConceptId = '',
draftConceptId,
providerId
} = params

Expand Down Expand Up @@ -196,8 +197,7 @@ export default class Draft extends Concept {
publish(data, requestedKeys, providedHeaders) {
const { ummVersion } = data

// eslint-disable-next-line no-param-reassign
data = mergeParams(data)
const params = mergeParams(data)

// Default headers
const defaultHeaders = {
Expand All @@ -222,7 +222,7 @@ export default class Draft extends Concept {
// Construct the promise that will ingest data into CMR
this.response = cmrIngest(
this.getConceptType(),
pick(data, this.getPermittedPublishKeys()),
pick(params, this.getPermittedPublishKeys()),
permittedHeaders,
this.publishPath
)
Expand Down
5 changes: 2 additions & 3 deletions src/cmr/concepts/draftConcept.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export default class DraftConcept extends Concept {
}

fetch(searchParams) {
// eslint-disable-next-line no-param-reassign
searchParams = mergeParams(searchParams)
const params = mergeParams(searchParams)

// Default an array to hold the promises we need to make depending on the requested fields
const promises = []
Expand All @@ -109,7 +108,7 @@ export default class DraftConcept extends Concept {

// Construct the promise that will request data from the umm endpoint
promises.push(
this.fetchUmm(searchParams, ummKeys, ummHeaders)
this.fetchUmm(params, ummKeys, ummHeaders)
)

this.response = Promise.all(promises)
Expand Down
6 changes: 3 additions & 3 deletions src/datasources/__tests__/tool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ describe('subscription#delete', () => {

process.env = { ...OLD_ENV }

process.env.cmrRootUrl = 'http://example.com'
process.env.cmrRootUrl = 'http://example-cmr.com'

// Default requestInfo
requestInfo = {
Expand Down Expand Up @@ -376,7 +376,7 @@ describe('subscription#delete', () => {
})

test('returns the CMR results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Request-Id': 'abcd-1234-efgh-5678'
})
Expand All @@ -403,7 +403,7 @@ describe('subscription#delete', () => {
})

test('catches errors received from cmrDelete', async () => {
nock(/example/)
nock(/example-cmr/)
.delete(/ingest\/providers\/EDSC\/tools\/test-guid/)
.reply(500, {
errors: ['HTTP Error']
Expand Down
4 changes: 2 additions & 2 deletions src/types/tool.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type Mutation {

type ToolMutationResponse {
"The unique concept id assigned to the tool."
conceptId: String
conceptId: String!
"The revision of the tool."
revisionId: String
revisionId: String!
}

0 comments on commit f8537e1

Please sign in to comment.