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:
Steven Shipton
2016-04-08 18:00:16 +01:00
committed by Drew
parent ab6925a5e2
commit 30197a7d84
4 changed files with 32 additions and 10 deletions

View File

@@ -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
};