Skip to content

Commit

Permalink
MMT-3382: Integration branch for Service Preview (#69)
Browse files Browse the repository at this point in the history
* 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

* MMT-3382: Fixed lint warnings

* MMT-3382: Updated the latest service fields
  • Loading branch information
dmistry1 authored Oct 17, 2023
1 parent 965460b commit 9de0272
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 5 deletions.
99 changes: 99 additions & 0 deletions src/datasources/__tests__/serviceDraft.test.js
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)
})
})
21 changes: 21 additions & 0 deletions src/datasources/serviceDraft.js
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()
}
2 changes: 2 additions & 0 deletions src/graphql/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import gridSource from '../datasources/grid'
import maxItemsPerOrderSource from '../datasources/maxItemsPerOrder'
import orderOptionSource from '../datasources/orderOption'
import serviceSource from '../datasources/service'
import serviceDraftSource from '../datasources/serviceDraft'
import toolDraftSource from '../datasources/toolDraft'
import toolSource from '../datasources/tool'
import variableSource from '../datasources/variable'
Expand Down Expand Up @@ -116,6 +117,7 @@ export default startServerAndCreateLambdaHandler(
maxItemsPerOrderSource,
orderOptionSource,
serviceSource,
serviceDraftSource,
subscriptionSourceDelete,
subscriptionSourceFetch,
subscriptionSourceIngest,
Expand Down
2 changes: 2 additions & 0 deletions src/resolvers/__tests__/__mocks__/mockServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import gridSource from '../../../datasources/grid'
import maxItemsPerOrderSource from '../../../datasources/maxItemsPerOrder'
import orderOptionSource from '../../../datasources/orderOption'
import serviceSource from '../../../datasources/service'
import serviceDraftSource from '../../../datasources/serviceDraft'
import {
deleteSubscription as subscriptionSourceDelete,
fetchSubscription as subscriptionSourceFetch,
Expand Down Expand Up @@ -42,6 +43,7 @@ export const buildContextValue = (extraContext) => ({
maxItemsPerOrderSource,
orderOptionSource,
serviceSource,
serviceDraftSource,
subscriptionSourceDelete,
subscriptionSourceFetch,
subscriptionSourceIngest,
Expand Down
173 changes: 173 additions & 0 deletions src/resolvers/__tests__/serviceDraft.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
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
}
})
})
})
})
})
})
2 changes: 2 additions & 0 deletions src/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import collectionResolver from './collection'
import granuleResolver from './granule'
import gridResolver from './grid'
import serviceResolver from './service'
import serviceDraftResolver from './serviceDraft'
import subscriptionResolver from './subscription'
import toolDraftResolver from './toolDraft'
import toolResolver from './tool'
Expand All @@ -23,6 +24,7 @@ const resolvers = [
gridResolver,
orderOptionResolver,
serviceResolver,
serviceDraftResolver,
subscriptionResolver,
toolDraftResolver,
toolResolver,
Expand Down
15 changes: 15 additions & 0 deletions src/resolvers/serviceDraft.js
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
}
}
}
2 changes: 2 additions & 0 deletions src/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import granule from './granule.graphql'
import grid from './grid.graphql'
import json from './json.graphql'
import service from './service.graphql'
import serviceDraft from './serviceDraft.graphql'
import subscription from './subscription.graphql'
import toolDraft from './toolDraft.graphql'
import tool from './tool.graphql'
Expand All @@ -26,6 +27,7 @@ export default mergeTypeDefs(
json,
orderOption,
service,
serviceDraft,
subscription,
tool,
toolDraft,
Expand Down
Loading

0 comments on commit 9de0272

Please sign in to comment.