Skip to content
Snippets Groups Projects
Commit 8d4cd7a8 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2737 OZG-2950 adjust drop usermanager collections

parent 37990412
Branches
No related tags found
No related merge requests found
...@@ -56,6 +56,11 @@ module.exports = (on, config) => { ...@@ -56,6 +56,11 @@ module.exports = (on, config) => {
console.log('dropCollections: ', collections); console.log('dropCollections: ', collections);
dropCollectionsFromDatabase(config, collections); dropCollectionsFromDatabase(config, collections);
return 0; return 0;
},
dropUserManagerCollections(collections) {
console.log('dropUserManagerCollections: ', collections);
dropUserManagerCollectionsFromDatabase(config, collections);
return 0;
} }
}); });
...@@ -215,11 +220,19 @@ function createNumberLong(numberValue){ ...@@ -215,11 +220,19 @@ function createNumberLong(numberValue){
} }
function insertIntoDatabase(config, collection, data) { 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...') console.log('connect to database...')
if (!error) { if (!error) {
console.log('success'); console.log('success');
var db = connection.db(config.env.database); var db = connection.db(databaseName);
db.collection(collection).drop(() => { db.collection(collection).drop(() => {
db.createCollection(collection, (error) => handleCreateCollection(db, connection, collection, data, error)); db.createCollection(collection, (error) => handleCreateCollection(db, connection, collection, data, error));
...@@ -253,12 +266,29 @@ function handleInsertMany(connection, error) { ...@@ -253,12 +266,29 @@ function handleInsertMany(connection, error) {
} }
function dropCollectionsFromDatabase(config, collections) { 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) { if (!error) {
var db = connection.db(config.env.database); var db = connection.db(databaseName);
collections.forEach((oneCollection, index) => { collections.forEach((oneCollection, index) => {
console.log('drop collection', oneCollection); console.log('drop collection', oneCollection);
db.collection(oneCollection).drop(() => { db.collection(oneCollection).drop(() => {
//CHECKME Ist die Abfrage notwendig?
if(index == collections.length){ if(index == collections.length){
console.log('close connection'); console.log('close connection');
connection.close(); connection.close();
...@@ -268,27 +298,3 @@ function dropCollectionsFromDatabase(config, collections) { ...@@ -268,27 +298,3 @@ function dropCollectionsFromDatabase(config, collections) {
} }
}); });
} }
\ No newline at end of file
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
...@@ -6,8 +6,8 @@ import { VorgangE2E } from '../model/vorgang'; ...@@ -6,8 +6,8 @@ import { VorgangE2E } from '../model/vorgang';
import { VorgangAttachedItemE2E } from '../model/vorgang-attached-item'; import { VorgangAttachedItemE2E } from '../model/vorgang-attached-item';
enum CypressTasks { enum CypressTasks {
DROP_COLLECTION = 'dropCollection',
DROP_COLLECTIONS = 'dropCollections', DROP_COLLECTIONS = 'dropCollections',
DROP_USER_MANAGER_COLLECTIONS = 'dropUserManagerCollections',
INIT_COMMAND_DATA = 'initCommandData', INIT_COMMAND_DATA = 'initCommandData',
INIT_GRID_FS_FILE_DATA = 'initGridFsFileData', INIT_GRID_FS_FILE_DATA = 'initGridFsFileData',
INIT_GRID_FS_CHUNK_DATA = 'initGridFsChunkData', INIT_GRID_FS_CHUNK_DATA = 'initGridFsChunkData',
...@@ -80,7 +80,8 @@ export function initUsermanagerData(data: UsermanagerUserE2E[]): void { ...@@ -80,7 +80,8 @@ export function initUsermanagerData(data: UsermanagerUserE2E[]): void {
} }
export function dropCollections() { 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 { export function scrollToWindowBottom(): void {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment