diff --git a/goofy-client/apps/goofy-e2e/src/plugins/index.js b/goofy-client/apps/goofy-e2e/src/plugins/index.js index 232ec66bc71746d07c117e46debd59c555aa59ad..bf52fe00a0944b8febe65a0465a71522c9ccfe4e 100644 --- a/goofy-client/apps/goofy-e2e/src/plugins/index.js +++ b/goofy-client/apps/goofy-e2e/src/plugins/index.js @@ -56,6 +56,11 @@ module.exports = (on, config) => { console.log('dropCollections: ', collections); dropCollectionsFromDatabase(config, collections); return 0; + }, + dropUserManagerCollections(collections) { + console.log('dropUserManagerCollections: ', collections); + dropUserManagerCollectionsFromDatabase(config, collections); + return 0; } }); @@ -215,11 +220,19 @@ function createNumberLong(numberValue){ } function insertIntoDatabase(config, collection, data) { - MongoClient.connect(buildDatabaseUrl(config), (error, connection) => { + insert(getDatabaseUrl(config), getDatabase(config), collection, data); +} + +function insertIntoUserManagerDatabase(config, collection, data){ + insert(getUserManagerDatabaseUrl(config), getUserManagerDatabase(config), collection, data); +} + +function insert(databaseUrl, databaseName, collection, data){ + MongoClient.connect(databaseUrl, (error, connection) => { console.log('connect to database...') if (!error) { console.log('success'); - var db = connection.db(config.env.database); + var db = connection.db(databaseName); db.collection(collection).drop(() => { db.createCollection(collection, (error) => handleCreateCollection(db, connection, collection, data, error)); @@ -253,12 +266,29 @@ function handleInsertMany(connection, error) { } function dropCollectionsFromDatabase(config, collections) { - MongoClient.connect(buildDatabaseUrl(config), (error, connection) => { + dropCollections(getDatabaseUrl(config), getDatabase(config), collections); +} + +function getDatabaseUrl(config){ + return config.env.dbUrl; +} + +function getDatabase(config){ + return config.env.database +} + +function dropUserManagerCollectionsFromDatabase(config, collections){ + dropCollections(getUserManagerDatabaseUrl(config), getUserManagerDatabase(config), collections); +} + +function dropCollections(databaseUrl, databaseName, collections){ + MongoClient.connect(databaseUrl, (error, connection) => { if (!error) { - var db = connection.db(config.env.database); + var db = connection.db(databaseName); collections.forEach((oneCollection, index) => { console.log('drop collection', oneCollection); db.collection(oneCollection).drop(() => { + //CHECKME Ist die Abfrage notwendig? if(index == collections.length){ console.log('close connection'); connection.close(); @@ -267,28 +297,4 @@ function dropCollectionsFromDatabase(config, collections) { }); } }); -} - -function buildDatabaseUrl(config) { - return config.env.dbUrl; -} - -function insertIntoUserManagerDatabase(config, collection, data){ - MongoClient.connect(buildUsermanagerDatabaseUrl(config), (error, connection) => { - console.log('connect to database...') - if (!error) { - console.log('success'); - var db = connection.db(config.env.userManager.database); - - db.collection(collection).drop(() => { - db.createCollection(collection, (error) => handleCreateCollection(db, connection, collection, data, error)); - }); - } else { - console.log('fail', error); - } - }); -} - -function buildUsermanagerDatabaseUrl(config){ - return config.env.userManager.dbUrl; } \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts b/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts index 91b16ab54160f3518505c814c09cd44ebdf7ea50..20642b9371085595d0e1fdeb3acb8cff1ccc4d48 100644 --- a/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts +++ b/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts @@ -6,8 +6,8 @@ import { VorgangE2E } from '../model/vorgang'; import { VorgangAttachedItemE2E } from '../model/vorgang-attached-item'; enum CypressTasks { - DROP_COLLECTION = 'dropCollection', DROP_COLLECTIONS = 'dropCollections', + DROP_USER_MANAGER_COLLECTIONS = 'dropUserManagerCollections', INIT_COMMAND_DATA = 'initCommandData', INIT_GRID_FS_FILE_DATA = 'initGridFsFileData', INIT_GRID_FS_CHUNK_DATA = 'initGridFsChunkData', @@ -80,7 +80,8 @@ export function initUsermanagerData(data: UsermanagerUserE2E[]): void { } export function dropCollections() { - cy.task(CypressTasks.DROP_COLLECTIONS, [MongoCollections.COMMAND, MongoCollections.VORGANG, MongoCollections.VORGANG_ATTACHED_ITEM, MongoCollections.FS_FILES, MongoCollections.FS_CHUNKS, MongoCollections.USER]); + cy.task(CypressTasks.DROP_COLLECTIONS, [MongoCollections.COMMAND, MongoCollections.VORGANG, MongoCollections.VORGANG_ATTACHED_ITEM, MongoCollections.FS_FILES, MongoCollections.FS_CHUNKS]); + cy.task(CypressTasks.DROP_USER_MANAGER_COLLECTIONS, [MongoCollections.USER]); } export function scrollToWindowBottom(): void {