-
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.
SIMSBIOHUB-653: Observation CSV Import (#1474)
- Observation CSV Import using new CSVConfig structure - New cell validators - Taxon row validator - Sampling information row validator - Shared qualitative quantitative value validators - Environment validators + measurement validators
- Loading branch information
Showing
65 changed files
with
4,275 additions
and
2,537 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
82 changes: 82 additions & 0 deletions
82
api/src/paths/project/{projectId}/survey/{surveyId}/observations/import.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,82 @@ | ||
import chai, { expect } from 'chai'; | ||
import { describe } from 'mocha'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import * as db from '../../../../../../database/db'; | ||
import { HTTP422CSVValidationError } from '../../../../../../errors/http-error'; | ||
import { ImportObservationsService } from '../../../../../../services/import-services/observation/import-observations-service'; | ||
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../../../__mocks__/db'; | ||
import { importObservationCSV } from './import'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('importObservationCSV', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('status 204 when successful', async () => { | ||
const mockDBConnection = getMockDBConnection({ open: sinon.stub(), commit: sinon.stub(), release: sinon.stub() }); | ||
const getDBConnectionStub = sinon.stub(db, 'getDBConnection').returns(mockDBConnection); | ||
|
||
const importCSVWorksheetStub = sinon.stub(ImportObservationsService.prototype, 'importCSVWorksheet'); | ||
|
||
importCSVWorksheetStub.resolves([]); | ||
|
||
const mockFile = { originalname: 'test.csv', mimetype: 'test.csv', buffer: Buffer.alloc(1) } as Express.Multer.File; | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
|
||
mockReq.files = [mockFile]; | ||
mockReq.params.surveyId = '1'; | ||
|
||
const requestHandler = importObservationCSV(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect(mockDBConnection.open).to.have.been.calledOnce; | ||
|
||
expect(getDBConnectionStub).to.have.been.calledOnce; | ||
|
||
expect(importCSVWorksheetStub).to.have.been.calledOnce; | ||
|
||
expect(mockRes.status).to.have.been.calledOnceWithExactly(204); | ||
expect(mockRes.send).to.have.been.calledOnceWithExactly(); | ||
|
||
expect(mockDBConnection.commit).to.have.been.calledOnce; | ||
expect(mockDBConnection.release).to.have.been.calledOnce; | ||
}); | ||
|
||
it('status 422 when CSV validation errors', async () => { | ||
const mockDBConnection = getMockDBConnection({ open: sinon.stub(), commit: sinon.stub(), release: sinon.stub() }); | ||
const getDBConnectionStub = sinon.stub(db, 'getDBConnection').returns(mockDBConnection); | ||
|
||
const importCSVWorksheetStub = sinon.stub(ImportObservationsService.prototype, 'importCSVWorksheet'); | ||
|
||
importCSVWorksheetStub.resolves([{ error: 'error', solution: 'solution' }]); | ||
|
||
const mockFile = { originalname: 'test.csv', mimetype: 'test.csv', buffer: Buffer.alloc(1) } as Express.Multer.File; | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
|
||
mockReq.files = [mockFile]; | ||
mockReq.params.surveyId = '1'; | ||
|
||
const requestHandler = importObservationCSV(); | ||
|
||
try { | ||
await requestHandler(mockReq, mockRes, mockNext); | ||
expect.fail('Expected an 422 error to be thrown'); | ||
} catch (err) { | ||
expect(mockDBConnection.open).to.have.been.calledOnce; | ||
|
||
expect(getDBConnectionStub).to.have.been.calledOnce; | ||
|
||
expect(importCSVWorksheetStub).to.have.been.calledOnce; | ||
|
||
expect(mockDBConnection.commit).to.have.not.been.called; | ||
expect(mockDBConnection.release).to.have.been.calledOnce; | ||
expect(err).to.be.instanceOf(HTTP422CSVValidationError); | ||
} | ||
}); | ||
}); |
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
67 changes: 0 additions & 67 deletions
67
api/src/paths/project/{projectId}/survey/{surveyId}/observations/process.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.