-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMR-9090: Add support for UMM-S to CMR graphql (#62)
* CMR-9090: Added support for Service Draft. * CMR-9090: Added test cases for serviceDraft * CMR-9090: Updated UMM-S version * CMR-9090: Reflected on PR comments * CMR-9090: Fixed the serviceDraft test
- Loading branch information
Showing
12 changed files
with
399 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import nock from 'nock' | ||
|
||
import serviceDraftDataSource from '../serviceDraft' | ||
|
||
let requestInfo | ||
|
||
describe('serviceDraft', () => { | ||
const OLD_ENV = process.env | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
|
||
jest.restoreAllMocks() | ||
|
||
process.env = { ...OLD_ENV } | ||
|
||
process.env.mmtRootUrl = 'http://example.com' | ||
|
||
// Default requestInfo | ||
requestInfo = { | ||
name: 'serviceDraft', | ||
alis: 'serviceDraft', | ||
args: {}, | ||
fieldsByTypeName: { | ||
ServiceDraft: { | ||
name: { | ||
name: 'name', | ||
alis: 'name', | ||
args: {}, | ||
fieldsByTypeName: {} | ||
}, | ||
description: { | ||
name: 'description', | ||
alis: 'description', | ||
args: {}, | ||
fieldsByTypeName: {} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
process.env = OLD_ENV | ||
}) | ||
|
||
test('return the service draft results', async () => { | ||
nock(/example/) | ||
.defaultReplyHeaders({ | ||
'X-Request-Id': 'abcd-1234-efgh-5678' | ||
}) | ||
.get(/api\/service_drafts/) | ||
.reply(200, { | ||
draft: { | ||
Name: 'Mock Name', | ||
Description: 'Mock Description' | ||
} | ||
}) | ||
|
||
const response = await serviceDraftDataSource({ | ||
params: { | ||
id: '123' | ||
} | ||
}, { | ||
headers: { | ||
'Client-Id': 'eed-test-graphql', | ||
'X-Request-Id': 'abcd-1234-efgh-5678' | ||
} | ||
}, requestInfo) | ||
|
||
expect(response).toEqual([{ | ||
name: 'Mock Name', | ||
description: 'Mock Description' | ||
}]) | ||
}) | ||
|
||
test('catches errors received from mmtQuery', async () => { | ||
nock(/example/) | ||
.get(/api\/service_drafts/) | ||
.reply(500, { | ||
errors: ['HTTP Error'] | ||
}, { | ||
'cmr-request-id': 'abcd-1234-efgh-5678' | ||
}) | ||
|
||
await expect( | ||
serviceDraftDataSource({ | ||
params: { | ||
id: '123' | ||
} | ||
}, { | ||
headers: { | ||
'Client-Id': 'eed-test-graphql', | ||
'X-Request-Id': 'abcd-1234-efgh-5678' | ||
} | ||
}, requestInfo) | ||
).rejects.toThrow(Error) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import DraftConcept from '../cmr/concepts/draftConcept' | ||
import { parseRequestedFields } from '../utils/parseRequestedFields' | ||
|
||
import serviceDraftKeyMap from '../utils/umm/serviceDraftKeyMap.json' | ||
|
||
export default async (params, context, parsedInfo) => { | ||
const { headers } = context | ||
|
||
const requestInfo = parseRequestedFields(parsedInfo, serviceDraftKeyMap, 'serviceDraft') | ||
|
||
const serviceDraft = new DraftConcept(headers, requestInfo, params, 'serviceDraft') | ||
|
||
// Query MMT | ||
serviceDraft.fetch(params) | ||
|
||
// Parse the response from MMT | ||
await serviceDraft.parse(requestInfo, params) | ||
|
||
// Return a formatted JSON response | ||
return serviceDraft.getFormattedResponse() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import nock from 'nock' | ||
|
||
import { | ||
buildContextValue, | ||
server | ||
} from './__mocks__/mockServer' | ||
|
||
const contextValue = buildContextValue() | ||
|
||
describe('ServiceDraft', () => { | ||
const OLD_ENV = process.env | ||
|
||
beforeEach(() => { | ||
process.env = { ...OLD_ENV } | ||
|
||
process.env.mmtRootUrl = 'http://example.com' | ||
}) | ||
|
||
afterEach(() => { | ||
process.env = OLD_ENV | ||
}) | ||
|
||
describe('Query', () => { | ||
describe('serviceDraft', () => { | ||
describe('with result', () => { | ||
test('all service draft fields', async () => { | ||
nock(/example/) | ||
.defaultReplyHeaders({ | ||
'X-Request-Id': 'abcd-1234-efgh-5678' | ||
}) | ||
.get(/api\/service_drafts/) | ||
.reply(200, { | ||
draft: { | ||
AccessConstraints: 'Mock Access Constraints', | ||
AncillaryKeywords: [], | ||
ContactGroups: {}, | ||
ContactPersons: {}, | ||
Description: 'Mock Description', | ||
LastUpdatedDate: 'Mock Last Updated Date', | ||
LongName: 'Mock Long Name', | ||
Name: 'Mock Name', | ||
OperationMetadata: {}, | ||
RelatedURLs: {}, | ||
ServiceKeywords: [], | ||
ServiceOptions: {}, | ||
ServiceOrganizations: {}, | ||
ServiceQuality: {}, | ||
Type: 'Mock Type', | ||
URL: {}, | ||
UseConstraints: {}, | ||
Version: '1.0', | ||
VersionDescription: 'Mock Version Description' | ||
} | ||
}) | ||
const response = await server.executeOperation({ | ||
variables: {}, | ||
query: `{ | ||
serviceDraft (params: { id: 123 }) { | ||
accessConstraints | ||
ancillaryKeywords | ||
contactGroups | ||
contactPersons | ||
description | ||
lastUpdatedDate | ||
longName | ||
name | ||
operationMetadata | ||
relatedUrls | ||
serviceKeywords | ||
serviceOptions | ||
serviceOrganizations | ||
serviceQuality | ||
type | ||
url | ||
useConstraints | ||
version | ||
versionDescription | ||
} | ||
}` | ||
}, { | ||
contextValue | ||
}) | ||
|
||
const { data } = response.body.singleResult | ||
|
||
expect(data).toEqual({ | ||
serviceDraft: { | ||
accessConstraints: 'Mock Access Constraints', | ||
ancillaryKeywords: [], | ||
contactGroups: {}, | ||
contactPersons: {}, | ||
description: 'Mock Description', | ||
lastUpdatedDate: 'Mock Last Updated Date', | ||
longName: 'Mock Long Name', | ||
name: 'Mock Name', | ||
operationMetadata: {}, | ||
relatedUrls: {}, | ||
serviceKeywords: [], | ||
serviceOptions: {}, | ||
serviceOrganizations: {}, | ||
serviceQuality: {}, | ||
type: 'Mock Type', | ||
url: {}, | ||
useConstraints: {}, | ||
version: '1.0', | ||
versionDescription: 'Mock Version Description' | ||
} | ||
}) | ||
}) | ||
test('return results', async () => { | ||
nock(/example/) | ||
.defaultReplyHeaders({ | ||
'X-Request-Id': 'abcd-1234-efgh-5678' | ||
}) | ||
.get(/api\/service_drafts/) | ||
.reply(200, { | ||
draft: { | ||
Name: 'Mock Name' | ||
} | ||
}) | ||
const response = await server.executeOperation({ | ||
variables: {}, | ||
query: `{ | ||
serviceDraft (params: { id: 123 }) { | ||
name | ||
} | ||
}` | ||
}, { | ||
contextValue | ||
}) | ||
const { data } = response.body.singleResult | ||
expect(data).toEqual({ | ||
serviceDraft: { | ||
name: 'Mock Name' | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
describe('with no results', () => { | ||
test('return no results', async () => { | ||
nock(/example/) | ||
.defaultReplyHeaders({ | ||
'X-Request-Id': 'abcd-1234-efgh-5678' | ||
}) | ||
.get(/api\/service_drafts/) | ||
.reply(200, {}) | ||
const response = await server.executeOperation({ | ||
variables: {}, | ||
query: `{ | ||
serviceDraft (params: { id: 123 }) { | ||
name | ||
} | ||
}` | ||
}, { | ||
contextValue | ||
}) | ||
|
||
const { data } = response.body.singleResult | ||
|
||
expect(data).toEqual({ | ||
serviceDraft: { | ||
name: null | ||
} | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { parseResolveInfo } from 'graphql-parse-resolve-info' | ||
|
||
export default { | ||
Query: { | ||
serviceDraft: async (source, args, context, info) => { | ||
const { dataSources } = context | ||
|
||
const result = await dataSources.serviceDraftSource(args, context, parseResolveInfo(info)) | ||
|
||
const [firstResult] = result | ||
|
||
return firstResult | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.