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

GQL-3: Appending variableKeyMap response to add new JSON fields #82

Closed
wants to merge 4 commits into from
Closed
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
120 changes: 119 additions & 1 deletion src/cmr/concepts/__tests__/concept.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Concept from '../concept'

describe('collection', () => {
describe('concept', () => {
beforeEach(() => {
jest.resetAllMocks()

Expand Down Expand Up @@ -47,5 +47,123 @@ describe('collection', () => {
})
})
})

describe('parseJsonBody', () => {
describe('the nested key is not a tag', () => {
test('the keys return camelCased', () => {
const concept = new Concept('concept', {}, [])
const conceptId = 'C1200000000-EDSC'
const jsonKeys = ['nestedKey', 'nestedKey2']
const jsonResponse = {
data:
{
hits: 1,
took: 9,
feed: {
entry: [{
concept_id: conceptId,
nested_key: [
{
key1: 'value',
key2: 'value2',
snake_key_1: 'value3',
snake_key_2: 'value4'
},
{
key1: 'value',
key2: 'value2',
snake_key_1: 'value3'
}
],
nested_key_2: {
url: 'https://mock.html',
format: 'Zarr',
description: 'Other brief end user information can go here.',
mock_distribution_information: {
region: 'us-west-2',
s_3_bucket_and_object_prefix_names: [
'mock-name-1',
'mock-name-2'
],
s_3_credentials_api_endpoint: 'https://s3mock.html',
s_3_credentials_api_documentation_url: 'https://s3Docsmock.html'
},
mock_chunking_information: 'Chunk size for this example is 1MB. It is optimized for time series.'
}
}]
}
}
}
concept.parseJson(jsonResponse, jsonKeys)
expect(concept.items[conceptId].nestedKey).toEqual([
{
key1: 'value',
key2: 'value2',
snakeKey1: 'value3',
snakeKey2: 'value4'
},
{
key1: 'value',
key2: 'value2',
snakeKey1: 'value3'
}
])

expect(concept.items[conceptId].nestedKey2).toEqual({
description: 'Other brief end user information can go here.',
format: 'Zarr',
mockChunkingInformation: 'Chunk size for this example is 1MB. It is optimized for time series.',
mockDistributionInformation: {
region: 'us-west-2',
s3BucketAndObjectPrefixNames: ['mock-name-1', 'mock-name-2'],
s3CredentialsApiDocumentationUrl: 'https://s3Docsmock.html',
s3CredentialsApiEndpoint: 'https://s3mock.html'
},
url: 'https://mock.html'
})
})
})

describe('the nested key is tag', () => {
test('the child-keys of the tag return in their original format', () => {
const concept = new Concept('concept', {}, [])
const conceptId = 'C1200000000-EDSC'
const jsonKeys = ['tags']
const jsonResponse = {
data:
{
hits: 1,
took: 9,
feed: {
entry: [{
concept_id: conceptId,
tags: {
'edsc.extra.serverless.collection_capabilities': {
data: {
cloud_cover: true,
day_night_flag: true,
granule_online_access_flag: true,
orbit_calculated_spatial_domains: false
}
}
}
}]
}
}
}
concept.parseJson(jsonResponse, jsonKeys)
expect(concept.items[conceptId].tags).toEqual({
'edsc.extra.serverless.collection_capabilities': {
data: {
cloud_cover: true,
day_night_flag: true,
granule_online_access_flag: true,
orbit_calculated_spatial_domains: false
}
}
})
})
})
})
})
})
6 changes: 3 additions & 3 deletions src/cmr/concepts/__tests__/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ describe('Service concept', () => {
describe('retrieve the parent collection', () => {
describe('if a parent collection is passed into the service', () => {
test('Ensure that the parentCollectionConceptId can be passed to child queries', () => {
const service = new Service({}, {}, {}, 'C1234567889')
const service = new Service({}, {}, {}, 'C100000-EDSC')
service.associationDetails = {}
const items = { meta: { 'association-details': {} } }
service.setEssentialUmmValues('S1234', items)
expect(service.parentCollectionConceptId).toEqual('C1234567889')
service.setEssentialUmmValues('S100000-EDSC', items)
expect(service.parentCollectionConceptId).toEqual('C100000-EDSC')
})
})
})
Expand Down
11 changes: 9 additions & 2 deletions src/cmr/concepts/concept.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default class Concept {

const formattedAssociationDetails = camelcaseKeys(associationDetails, { deep: true })

// When querying for associated concepts we must ensure `associationDetails` is in the requested fields
if (associationDetails) {
this.setItemValue(id, 'associationDetails', formattedAssociationDetails)
}
Expand Down Expand Up @@ -602,12 +603,18 @@ export default class Concept {
this.setEssentialJsonValues(conceptId, normalizedItem)

jsonKeys.forEach((jsonKey) => {
// Snake case the key requested and any children of that key
const cmrKey = snakeCase(jsonKey)

const { [cmrKey]: keyValue } = normalizedItem

// Snake case the key requested and any children of that key
this.setItemValue(conceptId, jsonKey, keyValue)
// Once accessed, ensure that the child key/value pairs are consistently returning in `camelCase` except for user-defined tags
let formattedKeyValue = keyValue
if (jsonKey !== 'tags') {
formattedKeyValue = camelcaseKeys(keyValue, { deep: true })
}

this.setItemValue(conceptId, jsonKey, formattedKeyValue)
})
})
}
Expand Down
6 changes: 5 additions & 1 deletion src/utils/umm/variableKeyMap.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"sharedKeys": [
"conceptId",
"definition",
"instanceInformation",
"longName",
"name"
"name",
eudoroolivares2016 marked this conversation as resolved.
Show resolved Hide resolved
"nativeId",
"scienceKeywords"
],
"ummKeyMappings": {
"additionalIdentifiers": "umm.AdditionalIdentifiers",
Expand Down