-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'SIMSBIOHUB-239' of github.com:bcgov/biohubbc into SIMSB…
…IOHUB-239
- Loading branch information
Showing
10 changed files
with
267 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { CritterbaseService } from '../../../services/critterbase-service'; | ||
import { getRequestHandlerMocks } from '../../../__mocks__/db'; | ||
import { getFamilyById } from './{familyId}'; | ||
|
||
describe('getFamilyById', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('gets a family by id', async () => { | ||
const mockFamily = { id: '1', name: 'family1' }; | ||
const mockGetFamilyById = sinon.stub(CritterbaseService.prototype, 'getFamilyById').resolves(mockFamily); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getFamilyById(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(mockGetFamilyById.calledOnce).to.be.true; | ||
expect(mockRes.json.calledOnce).to.be.true; | ||
expect(mockRes.json.args[0][0]).to.deep.equal(mockFamily); | ||
}); | ||
|
||
it('handles errors', async () => { | ||
const mockError = new Error('error'); | ||
const mockGetFamilyById = sinon.stub(CritterbaseService.prototype, 'getFamilyById').rejects(mockError); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getFamilyById(); | ||
|
||
try { | ||
await requestHandler(mockReq, mockRes, mockNext); | ||
expect.fail(); | ||
} catch (actualError) { | ||
expect(actualError).to.equal(mockError); | ||
expect(mockGetFamilyById.calledOnce).to.be.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { CritterbaseService } from '../../services/critterbase-service'; | ||
import { getRequestHandlerMocks } from '../../__mocks__/db'; | ||
import { signUp } from './signup'; | ||
|
||
describe('signUp', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
it('adds a user to critterbase and returns status 200', async () => { | ||
const mockAddUser = sinon.stub(CritterbaseService.prototype, 'signUp').resolves({ message: 'User created' }); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = signUp(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(mockAddUser.calledOnce).to.be.true; | ||
expect(mockRes.status.calledOnce).to.be.true; | ||
expect(mockRes.status.args[0][0]).to.equal(200); | ||
expect(mockRes.json.calledOnce).to.be.true; | ||
expect(mockRes.json.args[0][0]).to.deep.equal({ message: 'User created' }); | ||
}); | ||
it('catches and re-throws error', async () => { | ||
const mockError = new Error('mockError'); | ||
const mockAddUser = sinon.stub(CritterbaseService.prototype, 'signUp').rejects(mockError); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = signUp(); | ||
|
||
try { | ||
await requestHandler(mockReq, mockRes, mockNext); | ||
expect.fail(); | ||
} catch (actualError) { | ||
expect(actualError).to.equal(mockError); | ||
expect(mockAddUser.calledOnce).to.be.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
45 changes: 45 additions & 0 deletions
45
api/src/paths/critter-data/xref/taxon-marking-body-locations.test.ts
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,45 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { CritterbaseService } from '../../../services/critterbase-service'; | ||
import { getRequestHandlerMocks } from '../../../__mocks__/db'; | ||
import { getTaxonBodyLocations } from './taxon-marking-body-locations'; | ||
|
||
describe('getTaxonBodyLocations', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('gets taxon body locations', async () => { | ||
const mockTaxonBodyLocations = ['bodyLocation1', 'bodyLocation2']; | ||
const mockGetTaxonBodyLocations = sinon | ||
.stub(CritterbaseService.prototype, 'getTaxonBodyLocations') | ||
.resolves(mockTaxonBodyLocations); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getTaxonBodyLocations(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(mockGetTaxonBodyLocations.calledOnce).to.be.true; | ||
expect(mockRes.status.calledOnceWith(200)).to.be.true; | ||
expect(mockRes.json.calledOnceWith(mockTaxonBodyLocations)).to.be.true; | ||
}); | ||
|
||
it('handles errors', async () => { | ||
const mockError = new Error('mock error'); | ||
const mockGetTaxonBodyLocations = sinon | ||
.stub(CritterbaseService.prototype, 'getTaxonBodyLocations') | ||
.rejects(mockError); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getTaxonBodyLocations(); | ||
|
||
try { | ||
await requestHandler(mockReq, mockRes, mockNext); | ||
expect.fail(); | ||
} catch (actualError) { | ||
expect(actualError).to.equal(mockError); | ||
expect(mockGetTaxonBodyLocations.calledOnce).to.be.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
45 changes: 45 additions & 0 deletions
45
api/src/paths/critter-data/xref/taxon-measurements.test.ts
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,45 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { CritterbaseService } from '../../../services/critterbase-service'; | ||
import { getRequestHandlerMocks } from '../../../__mocks__/db'; | ||
import { getTaxonMeasurements } from './taxon-measurements'; | ||
|
||
describe('getTaxonMeasurements', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('gets taxon measurements', async () => { | ||
const mockTaxonMeasurements = ['measurement1', 'measurement2']; | ||
const mockGetTaxonMeasurements = sinon | ||
.stub(CritterbaseService.prototype, 'getTaxonMeasurements') | ||
.resolves(mockTaxonMeasurements); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getTaxonMeasurements(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(mockGetTaxonMeasurements.calledOnce).to.be.true; | ||
expect(mockRes.statusValue).to.equal(200); | ||
expect(mockRes.json.calledWith(mockTaxonMeasurements)).to.be.true; | ||
}); | ||
|
||
it('handles errors', async () => { | ||
const mockError = new Error('mock error'); | ||
const mockGetTaxonMeasurements = sinon | ||
.stub(CritterbaseService.prototype, 'getTaxonMeasurements') | ||
.rejects(mockError); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getTaxonMeasurements(); | ||
|
||
try { | ||
await requestHandler(mockReq, mockRes, mockNext); | ||
expect.fail(); | ||
} catch (actualError) { | ||
expect(actualError).to.equal(mockError); | ||
expect(mockGetTaxonMeasurements.calledOnce).to.be.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
47 changes: 47 additions & 0 deletions
47
api/src/paths/critter-data/xref/taxon-qualitative-measurement-options.test.ts
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,47 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { CritterbaseService } from '../../../services/critterbase-service'; | ||
import { getRequestHandlerMocks } from '../../../__mocks__/db'; | ||
import { getQualMeasurementOptions } from './taxon-qualitative-measurement-options'; | ||
|
||
describe('getQualMeasurementOptions', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('gets qualitative measurement options', async () => { | ||
const mockQualMeasurementOptions = ['qualMeasurementOption1', 'qualMeasurementOption2']; | ||
const mockGetQualMeasurementOptions = sinon | ||
.stub(CritterbaseService.prototype, 'getQualitativeOptions') | ||
.resolves(mockQualMeasurementOptions); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getQualMeasurementOptions(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(mockGetQualMeasurementOptions.calledOnce).to.be.true; | ||
expect(mockRes.status.calledOnce).to.be.true; | ||
expect(mockRes.status.getCall(0).args[0]).to.equal(200); | ||
expect(mockRes.json.calledOnce).to.be.true; | ||
expect(mockRes.json.getCall(0).args[0]).to.deep.equal(mockQualMeasurementOptions); | ||
}); | ||
|
||
it('handles errors', async () => { | ||
const mockError = new Error('mockError'); | ||
const mockGetQualMeasurementOptions = sinon | ||
.stub(CritterbaseService.prototype, 'getQualitativeOptions') | ||
.rejects(mockError); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
const requestHandler = getQualMeasurementOptions(); | ||
|
||
try { | ||
await requestHandler(mockReq, mockRes, mockNext); | ||
expect.fail(); | ||
} catch (actualError) { | ||
expect(actualError).to.equal(mockError); | ||
expect(mockGetQualMeasurementOptions.calledOnce).to.be.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