Expose DatabaseAdapter to simplify application tests (#1121)
* Move helper.clearData to DatabaseAdapter. Expose DatabaseAdapter in index * fix indentation * Export DatabaseAdapter in index.js * Rename clearData to destroyAllDataPermanently. Only export destroyAllDataPermanently from DatabaseAdapter. Update helper * Expose wrapped TestUtils from index.js. TestUtils exposed select functions from other modules, only in test environment
This commit is contained in:
@@ -49,6 +49,18 @@ function clearDatabaseSettings() {
|
||||
appDatabaseOptions = {};
|
||||
}
|
||||
|
||||
//Used by tests
|
||||
function destroyAllDataPermanently() {
|
||||
if (process.env.TESTING) {
|
||||
var promises = [];
|
||||
for (var conn in dbConnections) {
|
||||
promises.push(dbConnections[conn].deleteEverything());
|
||||
}
|
||||
return Promise.all(promises);
|
||||
}
|
||||
throw 'Only supported in test environment';
|
||||
}
|
||||
|
||||
function getDatabaseConnection(appId: string, collectionPrefix: string) {
|
||||
if (dbConnections[appId]) {
|
||||
return dbConnections[appId];
|
||||
@@ -71,5 +83,6 @@ module.exports = {
|
||||
setAppDatabaseOptions: setAppDatabaseOptions,
|
||||
setAppDatabaseURI: setAppDatabaseURI,
|
||||
clearDatabaseSettings: clearDatabaseSettings,
|
||||
destroyAllDataPermanently: destroyAllDataPermanently,
|
||||
defaultDatabaseURI: databaseURI
|
||||
};
|
||||
|
||||
15
src/TestUtils.js
Normal file
15
src/TestUtils.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { destroyAllDataPermanently } from './DatabaseAdapter';
|
||||
|
||||
let unsupported = function() {
|
||||
throw 'Only supported in test environment';
|
||||
};
|
||||
|
||||
let _destroyAllDataPermanently;
|
||||
if (process.env.TESTING) {
|
||||
_destroyAllDataPermanently = destroyAllDataPermanently;
|
||||
} else {
|
||||
_destroyAllDataPermanently = unsupported;
|
||||
}
|
||||
|
||||
export default {
|
||||
destroyAllDataPermanently: _destroyAllDataPermanently};
|
||||
@@ -2,6 +2,7 @@ import winston from 'winston';
|
||||
import ParseServer from './ParseServer';
|
||||
import S3Adapter from 'parse-server-s3-adapter'
|
||||
import FileSystemAdapter from 'parse-server-fs-adapter'
|
||||
import TestUtils from './TestUtils';
|
||||
import { useExternal } from './deprecated'
|
||||
|
||||
// Factory function
|
||||
@@ -15,4 +16,4 @@ _ParseServer.createLiveQueryServer = ParseServer.createLiveQueryServer;
|
||||
let GCSAdapter = useExternal('GCSAdapter', 'parse-server-gcs-adapter');
|
||||
|
||||
export default ParseServer;
|
||||
export { S3Adapter, GCSAdapter, FileSystemAdapter, _ParseServer as ParseServer };
|
||||
export { S3Adapter, GCSAdapter, FileSystemAdapter, TestUtils, _ParseServer as ParseServer };
|
||||
|
||||
Reference in New Issue
Block a user