-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIMSBIOHUB-457: Taxonomy Endpoints (#235)
Design BioHub taxonomy endpoint + services/repositories. - Taxon Search endpoint - Search by term to SOLR service from frontend - Taxon ids lookup endpoint - Query DB for cached tsn's - Search SOLR for tsn's not found in DB, update accordingly - Return list of Taxons
- Loading branch information
Showing
22 changed files
with
1,357 additions
and
533 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"git.ignoreLimitWarning": true | ||
} | ||
"git.ignoreLimitWarning": true | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,97 @@ | ||
import Ajv from 'ajv'; | ||
import chai, { expect } from 'chai'; | ||
import { describe } from 'mocha'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import { findTaxonBySearchTerms, GET } from '.'; | ||
import * as db from '../../../database/db'; | ||
import { HTTPError } from '../../../errors/http-error'; | ||
import { ItisService } from '../../../services/itis-service'; | ||
import { getMockDBConnection, getRequestHandlerMocks } from '../../../__mocks__/db'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('taxon', () => { | ||
describe('openapi schema', () => { | ||
const ajv = new Ajv(); | ||
|
||
it('is valid openapi v3 schema', () => { | ||
expect(ajv.validateSchema(GET.apiDoc as unknown as object)).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('findTaxonBySearchTerms', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('returns an empty array if no species are found', async () => { | ||
const dbConnectionObj = getMockDBConnection(); | ||
|
||
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj); | ||
|
||
const getSpeciesFromIdsStub = sinon.stub(ItisService.prototype, 'searchItisByTerm').resolves([]); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
mockReq.query = { | ||
terms: '' | ||
}; | ||
|
||
const requestHandler = findTaxonBySearchTerms(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(getSpeciesFromIdsStub).to.have.been.calledWith(''); | ||
|
||
expect(mockRes.statusValue).to.equal(200); | ||
expect(mockRes.jsonValue).to.eql({ searchResponse: [] }); | ||
}); | ||
|
||
it('returns an array of species', async () => { | ||
const dbConnectionObj = getMockDBConnection(); | ||
|
||
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj); | ||
|
||
const mock1 = { id: '1', commonName: 'something', scientificName: 'string' } as unknown as any; | ||
const mock2 = { id: '2', commonName: null, scientificName: 'string' } as unknown as any; | ||
|
||
const getSpeciesFromIdsStub = sinon.stub(ItisService.prototype, 'searchItisByTerm').resolves([mock1, mock2]); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
mockReq.query = { | ||
terms: 't' | ||
}; | ||
|
||
const requestHandler = findTaxonBySearchTerms(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(getSpeciesFromIdsStub).to.have.been.calledWith('t'); | ||
|
||
expect(mockRes.jsonValue).to.eql({ searchResponse: [mock1, mock2] }); | ||
expect(mockRes.statusValue).to.equal(200); | ||
}); | ||
|
||
it('catches error, and re-throws error', async () => { | ||
const dbConnectionObj = getMockDBConnection({ rollback: sinon.stub(), release: sinon.stub() }); | ||
|
||
sinon.stub(db, 'getDBConnection').returns(dbConnectionObj); | ||
|
||
sinon.stub(ItisService.prototype, 'searchItisByTerm').rejects(new Error('a test error')); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
mockReq.query = { | ||
ids: 'a' | ||
}; | ||
|
||
try { | ||
const requestHandler = findTaxonBySearchTerms(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
expect.fail(); | ||
} catch (actualError) { | ||
expect((actualError as HTTPError).message).to.equal('a test error'); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.