Skip to content

Commit

Permalink
MMT-3408: Better test URLs, throw error when required field is missin…
Browse files Browse the repository at this point in the history
…g, add util to check for draft concept ids
  • Loading branch information
macrouch committed Oct 23, 2023
1 parent 5b9e432 commit 33b3e90
Show file tree
Hide file tree
Showing 40 changed files with 379 additions and 308 deletions.
10 changes: 0 additions & 10 deletions src/cmr/concepts/__tests__/concept.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import Concept from '../concept'

describe('collection', () => {
const OLD_ENV = process.env

beforeEach(() => {
jest.resetAllMocks()

jest.restoreAllMocks()

process.env = { ...OLD_ENV }

process.env.cmrRootUrl = 'http://example.com'
})

afterEach(() => {
process.env = OLD_ENV
})

describe('concept', () => {
Expand Down
10 changes: 0 additions & 10 deletions src/cmr/concepts/__tests__/draft.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import Draft from '../draft'

describe('Draft concept', () => {
const OLD_ENV = process.env

beforeEach(() => {
jest.resetAllMocks()

jest.restoreAllMocks()

process.env = { ...OLD_ENV }

process.env.cmrRootUrl = 'http://example.com'
})

afterEach(() => {
process.env = OLD_ENV
})

describe('Draft concept', () => {
Expand Down
10 changes: 0 additions & 10 deletions src/cmr/concepts/__tests__/service.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import Service from '../service'

describe('Service concept', () => {
const OLD_ENV = process.env

beforeEach(() => {
jest.resetAllMocks()

jest.restoreAllMocks()

process.env = { ...OLD_ENV }

process.env.cmrRootUrl = 'http://example.com'
})

afterEach(() => {
process.env = OLD_ENV
})

describe('Service concept', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/cmr/concepts/draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ export default class Draft extends Concept {
*/
ingest(data, requestedKeys, providedHeaders) {
const { ummVersion } = data

if (!ummVersion) {
throw new Error('`ummVersion` is required when ingesting drafts.')
}

// Default headers
const defaultHeaders = {
Accept: 'application/json',
Expand Down
10 changes: 10 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ export const CONCEPT_TYPES = [
export const PSEUDO_FIELDS = [
'maxItemsPerOrder'
]

/**
* Draft concept ID prefixes
*/
export const DRAFT_CONCEPT_ID_PREFIXES = {
collection: 'CD',
service: 'SD',
tool: 'TD',
variable: 'VD'
}
26 changes: 13 additions & 13 deletions src/datasources/__tests__/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('collection', () => {

process.env = { ...OLD_ENV }

process.env.cmrRootUrl = 'http://example.com'
process.env.cmrRootUrl = 'http://example-cmr.com'

// Default requestInfo
requestInfo = {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('collection', () => {
})

test('returns a cursor', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand All @@ -118,7 +118,7 @@ describe('collection', () => {
}
})

nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('collection', () => {

describe('when a cursor is requested', () => {
test('requests a cursor', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand All @@ -182,7 +182,7 @@ describe('collection', () => {
}
})

nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('collection', () => {

describe('without params', () => {
test('returns the parsed collection results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('collection', () => {

describe('with params', () => {
test('returns the parsed collection results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -359,7 +359,7 @@ describe('collection', () => {
})

test('returns the parsed collection results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand All @@ -375,7 +375,7 @@ describe('collection', () => {
}
})

nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -468,7 +468,7 @@ describe('collection', () => {
})

test('returns the parsed collection results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand All @@ -485,7 +485,7 @@ describe('collection', () => {
}
})

nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -567,7 +567,7 @@ describe('collection', () => {
})

test('returns the parsed collection results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -619,7 +619,7 @@ describe('collection', () => {
})

test('catches errors received from queryCmrCollections', async () => {
nock(/example/)
nock(/example-cmr/)
.post(/collections/)
.reply(500, {
errors: ['HTTP Error']
Expand Down
6 changes: 3 additions & 3 deletions src/datasources/__tests__/collectionDraftProposal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('collectionDraftProposal', () => {

process.env = { ...OLD_ENV }

process.env.draftMmtRootUrl = 'http://example.com'
process.env.draftMmtRootUrl = 'http://example-dmmt.com'
process.env.dmmtSslCert = '-----BEGIN CERTIFICATE-----\nmock-certificate\n-----END CERTIFICATE-----'

// Default requestInfo
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('collectionDraftProposal', () => {
})

test('returns the collection draft proposal results', async () => {
nock(/example/)
nock(/example-dmmt/)
.defaultReplyHeaders({
'X-Request-Id': 'abcd-1234-efgh-5678'
})
Expand Down Expand Up @@ -74,7 +74,7 @@ describe('collectionDraftProposal', () => {
})

test('catches errors received from draftMmtQuery', async () => {
nock(/example/)
nock(/example-dmmt/)
.get(/api\/collection_draft_proposals/)
.reply(500, {
errors: ['HTTP Error']
Expand Down
14 changes: 7 additions & 7 deletions src/datasources/__tests__/dataQualitySummary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('dataQualitySummary', () => {

process.env = { ...OLD_ENV }

process.env.cmrRootUrl = 'http://example.com'
process.env.cmrRootUrl = 'http://example-cmr.com'

// Default requestInfo
requestInfo = {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('dataQualitySummary', () => {
})

test('returns a cursor', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('dataQualitySummary', () => {

describe('when a cursor is requested', () => {
test('requests a cursor', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('dataQualitySummary', () => {

describe('without params', () => {
test('returns the parsed data-quality-summary results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('dataQualitySummary', () => {

describe('with params', () => {
test('returns the parsed dataQuality summary results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -263,7 +263,7 @@ describe('dataQualitySummary', () => {
})

test('returns the parsed dataQualitySummary results', async () => {
nock(/example/)
nock(/example-cmr/)
.defaultReplyHeaders({
'CMR-Hits': 84,
'CMR-Took': 7,
Expand Down Expand Up @@ -303,7 +303,7 @@ describe('dataQualitySummary', () => {
})

test('catches errors received from querying CMR for dataQualitySummaries', async () => {
nock(/example/)
nock(/example-cmr/)
.post(/data-quality-summaries/)
.reply(500, {
errors: ['HTTP Error']
Expand Down
Loading

0 comments on commit 33b3e90

Please sign in to comment.