Skip to content

Commit

Permalink
(#33) - Add integrationTestSetup to abstract away the setup complexity
Browse files Browse the repository at this point in the history
Abstract away the setup complexity needed to configure the testing
environment.
  • Loading branch information
marcos8896 committed Sep 7, 2018
1 parent 21a20f8 commit e7958fa
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions dev/testing/environment-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,51 @@ const createTestingDatabase = () => {

};


/**
* Creates all the environment for the integration test.
*
* @returns {Promise<Object>} Return a promise which contains an
* object an apiPort in which the testing API port can be mounted,
* a baseURL where the axios api calls with have to point to,
* and the seedModels which contains all the seedModel to generate
* fake data.
*/
const integrationTestSetup = async ({ datasource, dbModelsToReset }) => {

const { getModelsSeeds } = require( './fixtures-utils' );
const { resetTables } = require( './database-utils' );

const [allModelSeeds] = await Promise.all( [
getModelsSeeds(),
createTestingDatabase(),
] ).catch( err => {

throw err;

});

const apiPort = getApiTestPort();
const baseURL = getBaseURLWithPort( apiPort );
const seedModels = allModelSeeds;

await resetTables( datasource, dbModelsToReset );

return {
retunedApiPort: apiPort,
retunedBaseURL: baseURL,
retunedSeedModels: seedModels,
};

};

if ( process.env.NODE_ENV === 'test' ) {

module.exports = {
getBaseURLWithPort,
createTestingDatabase,
getApiTestPort,
integrationTestSetup,
};

}

0 comments on commit e7958fa

Please # to comment.