Skip to content

Commit

Permalink
(#33) - Add integrationTestSetup usage to the body-area.service tests
Browse files Browse the repository at this point in the history
Allow to remove the complexity to setup the integration test
environment
  • Loading branch information
marcos8896 committed Sep 7, 2018
1 parent 3ab484e commit 240d108
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
44 changes: 19 additions & 25 deletions common/services/__tests__/integration/body-area.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict';

jest.unmock( 'axios' );

const { integrationTestSetup } = require( '../../../../dev/testing/environment-utils' );

const {
getModelsSeeds,
getFakeModelsArray,
findSeedModel,
} = require( '../../../../dev/testing/fixtures-utils' );
Expand All @@ -14,47 +17,38 @@ const {
resetTables,
} = require( '../../../../dev/testing/database-utils' );

const {
getBaseURLWithPort,
createTestingDatabase,
getApiTestPort,
} = require( '../../../../dev/testing/environment-utils' );

const app = require( '../../../../server/server' );

const { BodyArea } = app.models;

let server, seedModels, bodyAreaModel, apiPort, baseURL;

const resetCurrentModels = () => {
const currentModels = [
'BodyArea', 'BodyArea_Exercise_Detail', 'Administrator', 'Customer',
];

return resetTables(
app.dataSources.mysql_ds,
['BodyArea', 'BodyArea_Exercise_Detail', 'Administrator', 'Customer']
);
const resetCurrentModels = () => resetTables( app.dataSources.mysql_ds, currentModels );

};
//---------------------------------------------------------------------

beforeAll( async () => {

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

throw err;

const {
retunedApiPort,
retunedBaseURL,
retunedSeedModels,
} = await integrationTestSetup({
datasource: app.dataSources.mysql_ds,
dbModelsToReset: currentModels,
});

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

await resetCurrentModels();
apiPort = retunedApiPort;
baseURL = retunedBaseURL;
seedModels = retunedSeedModels;

});


beforeEach( () => server = app.listen( apiPort ) );


Expand Down
9 changes: 1 addition & 8 deletions common/services/__tests__/integration/diet.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ const currentModels = ['Diet', 'Diet_Food_Detail', 'Customer', 'Administrator'];

//---------------------------------------------------------------------

const resetCurrentModels = () => {

return resetTables(
app.dataSources.mysql_ds,
currentModels,
);

};
const resetCurrentModels = () => resetTables( app.dataSources.mysql_ds, currentModels );

beforeAll( async () => {

Expand Down

0 comments on commit 240d108

Please sign in to comment.