Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ISSUE: Server: NPM Scripts for Testing #7
I moved database seeding to a dedicated tests/setup.js file from src/index.js.
src/index.js now exports httpServer wich will be imported by setup.js and starts it only when not in test mode.
tests/user.spec.js imports setup.js initializes the database in the before() function that is executed at the very beginning of the suite; likewise, the after() function terminates the process in order to prevent execution hanging for ever.
I also added a timeout in npm run test command to take into account the delay caused by seeding the database and set an IS_TEST environment test that is used to identify the enviroment (IMHO cleaner than testing for the existence of the test database name which can be now declared in .env).
To make all work in my environment I had to switch from pg to mssql and I apologise for this additional change being included in the PR, but this way I am sure this is a working project. To revert, just replace tedious with pg in package.json and replace 'mssql' with 'postgres' in models/index.js.
I also added the host parameter to account for a remote database (such as the one I am using): it is defined .env as well. Since the default is localhost, I guess that if not defined it will be ignored by Sequelize constructor.
Other changes, again not required:
.babelrc: useful for debug
.vscode/launch.json: debug startup for server and tests respectively