async function configureYggdrasilForFunctionalTesting (yggdrasil, _yggdrasil) {
  _yggdrasil.fire('log', 'info', '💉  Injecting fixtures');
  _yggdrasil.functionalTestingMode = true;

  if (_yggdrasil.fixtures === undefined) {
    throw new Error('configureYggdrasilForFunctionalTesting: you should have injected fixtures into yggdrasil.fixtures first');
  }

  Object.keys(yggdrasil.repositories).forEach(key => {
    if (key !== 'yggdrasil') {
      _yggdrasil.fire('log', 'info', `🧪  configuring repository "${key}" to have "testing_${_yggdrasil.repositories[key].index}" as index`);
      _yggdrasil.repositories[key]._setIndexCollection('testing_' + yggdrasil.repositories[key].index);
    }
  });

  // injects fixtures
  Object.keys(yggdrasil.fixtures).forEach(index => {
    Object.keys(yggdrasil.fixtures[index]).forEach(collection => {
      _yggdrasil.fixtures[index][collection].forEach(async item => {
        await _yggdrasil.storageService.set({
          index: index,
          collection: collection,
          meta: {},
          ...item
        });
      });
    });
  });

  _yggdrasil.functionalTestingInitDone = true;

  _yggdrasil.fire('log', 'info', '💉  Fixtures injected');

  /**
   * Helps to cleanup the testing fixtures
   * @param currentInstance
   */
  _yggdrasil.cleanupFunctionalTestingdata = async (currentInstance) => {
    currentInstance.fire('log', 'info', '🧹  Deleting fixtures');
    if (currentInstance.fixtures === undefined) {
      throw new Error('configureYggdrasilForFunctionalTesting: you should have injected fixtures into yggdrasil.fixtures first');
    }
    currentInstance.fire('log', 'info', '🧹  Indexes to delete', Object.keys(currentInstance.fixtures));

    try {
      currentInstance.storageService.dropDatabase(Object.keys(currentInstance.fixtures));
    } catch (e) {
      console.log(e);
    }

    currentInstance.fire('log', 'info', '🧹  Fixtures deleted');

    return currentInstance;
  };

  return _yggdrasil;
}
/**
 * Reconfigure the current yggdrasil instance repositories to use the testing indexes and inject fixtures into the database
 */
Reconfigure the current yggdrasil instance repositories to use the testing indexes and inject fixtures into the database
Reconfigure the current yggdrasil instance repositories to use the testing indexes and inject fixtures into the database
async function configureYggdrasilForFunctionalTesting (yggdrasil, _yggdrasil) {
  _yggdrasil.fire('log', 'info', '💉  Injecting fixtures');
  _yggdrasil.functionalTestingMode = true;
  if (_yggdrasil.fixtures === undefined) {
    throw new Error('configureYggdrasilForFunctionalTesting: you should have injected fixtures into yggdrasil.fixtures first');
  }
  Object.keys(yggdrasil.repositories).forEach(key => {
    if (key !== 'yggdrasil') {
      _yggdrasil.fire('log', 'info', `🧪  configuring repository "${key}" to have "testing_${_yggdrasil.repositories[key].index}" as index`);
      _yggdrasil.repositories[key]._setIndexCollection('testing_' + yggdrasil.repositories[key].index);
    }
  });
  Object.keys(yggdrasil.fixtures).forEach(index => {
    Object.keys(yggdrasil.fixtures[index]).forEach(collection => {
      _yggdrasil.fixtures[index][collection].forEach(async item => {
        await _yggdrasil.storageService.set({
          index: index,
          collection: collection,
          meta: {},
          ...item
        });
      });
    });
  });
  _yggdrasil.functionalTestingInitDone = true;
  _yggdrasil.fire('log', 'info', '💉  Fixtures injected');
  _yggdrasil.cleanupFunctionalTestingdata = async (currentInstance) => {
    currentInstance.fire('log', 'info', '🧹  Deleting fixtures');
    if (currentInstance.fixtures === undefined) {
      throw new Error('configureYggdrasilForFunctionalTesting: you should have injected fixtures into yggdrasil.fixtures first');
    }
    currentInstance.fire('log', 'info', '🧹  Indexes to delete', Object.keys(currentInstance.fixtures));
    try {
      currentInstance.storageService.dropDatabase(Object.keys(currentInstance.fixtures));
    } catch (e) {
      console.log(e);
    }
    currentInstance.fire('log', 'info', '🧹  Fixtures deleted');
    return currentInstance;
  };
  return _yggdrasil;
}
async function configureYggdrasilForFunctionalTesting ( yggdrasil , _yggdrasil ) { _yggdrasil . fire ( 'log' , 'info' , '💉  Injecting fixtures'); _yggdrasil . functionalTestingMode = true ; if ( _yggdrasil . fixtures === undefined ) { throw new Error ( 'configureYggdrasilForFunctionalTesting: you should have injected fixtures into yggdrasil.fixtures first' ) ; } Object . keys ( yggdrasil . repositories ) . forEach ( key => { if ( key !== 'yggdrasil' ) { _yggdrasil . fire ( 'log' , 'info' , ` ey }"  t yg gdrasil.re p ositories[ke y ].i n d ex}"  a _yggdrasil . repositories [ key ] . _setIndexCollection ( 'testing_' + yggdrasil . repositories [ key ] . index ) ; } } ) ; Object . keys ( yggdrasil . fixtures ) . forEach ( index => { Object . keys ( yggdrasil . fixtures [ index ] ) . forEach ( collection => { _yggdrasil . fixtures [ index ] [ collection ] . forEach ( async item => { await _yggdrasil . storageService . set ( { index : index , collection : collection , meta : { } , ... item } ) ; } ) ; } ) ; } ) ; _yggdrasil . functionalTestingInitDone = true ; _yggdrasil . fire ( 'log' , 'info' , '💉  Fixtures injected'); _yggdrasil . cleanupFunctionalTestingdata = async ( currentInstance ) => { currentInstance . fire ( 'log' , 'info' , '🧹  Deleting fixtures'); if ( currentInstance . fixtures === undefined ) { throw new Error ( 'configureYggdrasilForFunctionalTesting: you should have injected fixtures into yggdrasil.fixtures first' ) ; } currentInstance . fire ( 'log' , 'info' , '🧹  Indexes to delete', O b ect.ke y s(cu r rentInstance.fi x tures)); try { currentInstance . storageService . dropDatabase ( Object . keys ( currentInstance . fixtures ) ) ; } catch ( e ) { console . log ( e ) ; } currentInstance . fire ( 'log' , 'info' , '🧹  Fixtures deleted'); return currentInstance ; } ; return _yggdrasil ; }
Reconfigure the current yggdrasil instance repositories to use the testing indexes and inject fixtures into the database
Reconfigure the current yggdrasil instance repositories to use the testing indexes and inject fixtures into the database
// injects fixtures /**
   * Helps to cleanup the testing fixtures
   * @param currentInstance
   */