-
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-562: Export Survey Data (#1273)
* Initial commit * Updates * Initial survey export UIs * Copy changes from biohub * Experimental stream * Updates * Updates * Update export backend * Fix unit test * ignore-skip * Tweaks * Updates to support export stream configs * Update config * Working with api strams * Revert virus scan change * ignore-skip * styling for export dialog * Remove debug log * Tweaks * Fix error message * Update error logging, add unit tests. * Add more unit tests --------- Co-authored-by: Macgregor Aubertin-Young <[email protected]> Co-authored-by: Macgregor Aubertin-Young <[email protected]>
- Loading branch information
1 parent
556ba8d
commit 1c26829
Showing
37 changed files
with
3,776 additions
and
1,016 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
Large diffs are not rendered by default.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,37 @@ | ||
export interface IAnimalAdvancedFilters { | ||
/** | ||
* Filter results by keyword. | ||
* | ||
* @type {string} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
keyword?: string; | ||
/** | ||
* Filter results by ITIS TSNs. | ||
* | ||
* @type {number[]} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
itis_tsns?: number[]; | ||
/** | ||
* Filter results by ITIS TSN. | ||
* | ||
* @type {number} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
itis_tsn?: number; | ||
/** | ||
* Filter results by system user id (not necessarily the user making the request). | ||
* | ||
* @type {number} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
system_user_id?: number; | ||
/** | ||
* Filter results by survey ids | ||
* | ||
* @type {number[]} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
survey_ids?: number[]; | ||
} |
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,6 +1,37 @@ | ||
export interface IAllTelemetryAdvancedFilters { | ||
/** | ||
* Filter results by keyword. | ||
* | ||
* @type {string} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
keyword?: string; | ||
/** | ||
* Filter results by ITIS TSNs. | ||
* | ||
* @type {number[]} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
itis_tsns?: number[]; | ||
/** | ||
* Filter results by ITIS TSN. | ||
* | ||
* @type {number} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
itis_tsn?: number; | ||
/** | ||
* Filter results by system user id (not necessarily the user making the request). | ||
* | ||
* @type {number} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
system_user_id?: number; | ||
/** | ||
* Filter results by survey ids | ||
* | ||
* @type {number[]} | ||
* @memberof IAnimalAdvancedFilters | ||
*/ | ||
survey_ids?: number[]; | ||
} |
98 changes: 98 additions & 0 deletions
98
api/src/paths/project/{projectId}/survey/{surveyId}/export/index.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,98 @@ | ||
import chai, { expect } from 'chai'; | ||
import { describe } from 'mocha'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import { exportData } from '.'; | ||
import { SYSTEM_ROLE } from '../../../../../../constants/roles'; | ||
import * as db from '../../../../../../database/db'; | ||
import { HTTPError } from '../../../../../../errors/http-error'; | ||
import { SystemUser } from '../../../../../../repositories/user-repository'; | ||
import { ExportService } from '../../../../../../services/export-services/export-service'; | ||
import { getMockDBConnection, getRequestHandlerMocks } from '../../../../../../__mocks__/db'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('exportData', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('catches and re-throws error', async () => { | ||
// Setup | ||
const mockDBConnection = getMockDBConnection({ release: sinon.stub() }); | ||
sinon.stub(db, 'getDBConnection').returns(mockDBConnection); | ||
|
||
sinon.stub(ExportService.prototype, 'export').rejects(new Error('a test error')); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
|
||
mockReq.system_user = { | ||
system_user_id: 1, | ||
role_names: [SYSTEM_ROLE.PROJECT_CREATOR] | ||
} as SystemUser; | ||
|
||
mockReq.params = { | ||
projectId: '1', | ||
surveyId: '2' | ||
}; | ||
|
||
mockReq.body = { | ||
methodTechniqueIds: [1, 2, 3] | ||
}; | ||
|
||
const requestHandler = exportData(); | ||
|
||
try { | ||
// Execute | ||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
expect.fail('Expected an error to be thrown'); | ||
} catch (actualError) { | ||
// Assert | ||
expect(mockDBConnection.release).to.have.been.calledOnce; | ||
|
||
expect((actualError as HTTPError).message).to.equal('a test error'); | ||
} | ||
}); | ||
|
||
it('returns the s3 signed url for the export data file', async () => { | ||
// Setup | ||
const mockDBConnection = getMockDBConnection({ release: sinon.stub() }); | ||
sinon.stub(db, 'getDBConnection').returns(mockDBConnection); | ||
|
||
sinon.stub(ExportService.prototype, 'export').resolves(['signed-url-for:path/to/file/key']); | ||
|
||
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks(); | ||
|
||
mockReq.system_user = { | ||
system_user_id: 1, | ||
role_names: [SYSTEM_ROLE.PROJECT_CREATOR] | ||
} as SystemUser; | ||
|
||
mockReq.params = { | ||
projectId: '1', | ||
surveyId: '2' | ||
}; | ||
|
||
mockReq.body = { | ||
config: { | ||
metadata: true, | ||
sampling_data: false, | ||
observation_data: true, | ||
telemetry_data: true, | ||
animal_data: false, | ||
artifacts: false | ||
} | ||
}; | ||
|
||
// Execute | ||
const requestHandler = exportData(); | ||
|
||
await requestHandler(mockReq, mockRes, mockNext); | ||
|
||
// Assert | ||
expect(mockRes.jsonValue).to.eql({ presignedS3Urls: ['signed-url-for:path/to/file/key'] }); | ||
|
||
expect(mockDBConnection.release).to.have.been.calledOnce; | ||
}); | ||
}); |
Oops, something went wrong.