diff --git a/src/cmr/concepts/concept.js b/src/cmr/concepts/concept.js index acdb48632..89d9f81f0 100644 --- a/src/cmr/concepts/concept.js +++ b/src/cmr/concepts/concept.js @@ -668,7 +668,23 @@ export default class Concept { } if (keyValue != null) { - const camelCasedObject = camelcaseKeys({ [ummKey]: keyValue }, { deep: true }) + const camelCasedObject = camelcaseKeys({ [ummKey]: keyValue }, { + deep: true, + exclude: ['RelatedURLs'] + }) + + // CamelcaseKey converts RelatedURLs to relatedUrLs, so excluding RelatedURLs above. + // This will remove RelatedURLs and create a new + // key called relatedUrls and assign the value to it so MMT and graphql response matches. + if (ummKey === 'previewMetadata') { + const { previewMetadata } = camelCasedObject + camelCasedObject.previewMetadata = { + ...previewMetadata, + relatedUrls: previewMetadata.RelatedURLs + } + + delete camelCasedObject.previewMetadata.RelatedURLs + } const { [ummKey]: camelCasedValue } = camelCasedObject diff --git a/src/resolvers/__tests__/variable.test.js b/src/resolvers/__tests__/variable.test.js index cf6431df9..0bba5d0c6 100644 --- a/src/resolvers/__tests__/variable.test.js +++ b/src/resolvers/__tests__/variable.test.js @@ -423,6 +423,84 @@ describe('Variable', () => { } }) }) + + test('returns correct values for Related URLs', async () => { + nock(/example-cmr/) + .defaultReplyHeaders({ + 'CMR-Hits': 2, + 'CMR-Took': 7, + 'CMR-Request-Id': 'abcd-1234-efgh-5678' + }) + .post(/variable-drafts\.umm_json/) + .reply(200, { + items: [{ + meta: { + 'concept-id': 'VD100000-EDSC' + }, + umm: {} + }, { + meta: { + 'concept-id': 'VD100001-EDSC' + }, + umm: { + RelatedURLs: [ + { + description: 'Test', + urlContentType: 'DataCenterURL', + type: 'HOME PAGE', + url: 'mock url', + format: 'HTML', + mimeType: 'application/msword' + } + ] + } + }] + }) + + const response = await server.executeOperation({ + variables: { + params: { + conceptType: 'Variable' + } + }, + query: `query Drafts($params: DraftsInput) { + drafts(params: $params) { + items { + previewMetadata { + ... on Variable { + relatedUrls + } + } + } + } + }` + }, { + contextValue + }) + + const { data } = response.body.singleResult + + expect(data).toEqual({ + drafts: { + items: [{ + previewMetadata: { + relatedUrls: null + } + }, { + previewMetadata: { + relatedUrls: [{ + description: 'Test', + urlContentType: 'DataCenterURL', + type: 'HOME PAGE', + url: 'mock url', + format: 'HTML', + mimeType: 'application/msword' + }] + } + }] + } + }) + }) }) })