From d2f9e080078508461b5e1423b21cbb1d1cd8c5be Mon Sep 17 00:00:00 2001 From: Matthew Crouch Date: Thu, 3 Oct 2024 16:12:23 -0400 Subject: [PATCH] GQL-80: Adds content-type header to subscription ingest requests. Fixes undefined request id in error message --- src/cmr/concepts/subscription.js | 7 ++++++- src/datasources/__tests__/subscription.test.js | 3 +++ src/graphql/handler.js | 3 ++- src/types/subscription.graphql | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cmr/concepts/subscription.js b/src/cmr/concepts/subscription.js index e5f8e9389..27295dd0f 100644 --- a/src/cmr/concepts/subscription.js +++ b/src/cmr/concepts/subscription.js @@ -116,7 +116,12 @@ export default class Subscription extends Concept { // Use the provided native id and provider id const { nativeId = uuidv4() } = params - super.ingest(data, requestedKeys, providedHeaders, { + const headers = { + ...providedHeaders, + 'Content-Type': 'application/vnd.nasa.cmr.umm+json' + } + + super.ingest(data, requestedKeys, headers, { path: `ingest/subscriptions/${encodeURIComponent(nativeId)}` }) } diff --git a/src/datasources/__tests__/subscription.test.js b/src/datasources/__tests__/subscription.test.js index 6dfae223c..9215ec88e 100644 --- a/src/datasources/__tests__/subscription.test.js +++ b/src/datasources/__tests__/subscription.test.js @@ -384,6 +384,7 @@ describe('subscription#ingest', () => { .defaultReplyHeaders({ 'CMR-Request-Id': 'abcd-1234-efgh-5678' }) + .matchHeader('Content-Type', 'application/vnd.nasa.cmr.umm+json') .put(/ingest\/subscriptions\/1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed/, JSON.stringify({ CollectionConceptId: 'C100000-EDSC', EmailAddress: 'test@example.com', @@ -429,6 +430,7 @@ describe('subscription#ingest', () => { .defaultReplyHeaders({ 'CMR-Request-Id': 'abcd-1234-efgh-5678' }) + .matchHeader('Content-Type', 'application/vnd.nasa.cmr.umm+json') .put(/ingest\/subscriptions\/test-guid/, JSON.stringify({ CollectionConceptId: 'C100000-EDSC', EmailAddress: 'test@example.com', @@ -516,6 +518,7 @@ describe('subscription#ingest', () => { test('catches errors received from ingestCmr', async () => { nock(/example-cmr/) .put(/ingest\/subscriptions\/1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed/) + .matchHeader('Content-Type', 'application/vnd.nasa.cmr.umm+json') .reply(500, { errors: ['HTTP Error'] }, { diff --git a/src/graphql/handler.js b/src/graphql/handler.js index 5195e1bc6..ad3653916 100644 --- a/src/graphql/handler.js +++ b/src/graphql/handler.js @@ -269,7 +269,8 @@ export default startServerAndCreateLambdaHandler( collectionLoader: new DataLoader(getCollectionsById, { cacheKeyFn: (obj) => obj.conceptId }), - headers: requestHeaders + headers: requestHeaders, + requestId: newRequestId } }, middleware: [ diff --git a/src/types/subscription.graphql b/src/types/subscription.graphql index d8604933c..518216dea 100644 --- a/src/types/subscription.graphql +++ b/src/types/subscription.graphql @@ -175,4 +175,6 @@ type SubscriptionMutationResponse { conceptId: String "The revision of the subscription." revisionId: String + "The native id of the subscription." + nativeId: String }