In Chapter 7, Data Storage and Retrieval, we developed MongoDB support for Notes, and since then we've focused on Sequelize. To make up for that slight, let's make sure we at least test our MongoDB support. Testing on MongoDB would simply require defining a container for the MongoDB database and a little bit of configuration.
Visit https://hub.docker.com/_/mongo/ for the official MongoDB container. You'll be able to retrofit this to allow deploying the Notes application running on MongoDB.
Add this to test-compose/docker-compose.yml:
db-notes-mongo-test:
image: mongo:3.6-jessie
container_name: db-notes-mongo-test
networks:
- frontnet-test
volumes:
- ./db-notes-mongo:/data/db
That's all that's required to add a MongoDB container to a Docker Compose file. We've connected it to frontnet so that the notes (notes-test) container can access the service.
Then in notes/test/package.json we add a line to facilitate running tests on MongoDB:
"test-notes-mongodb": "MONGO_URL=mongodb://db-notes-mongo-test/ MONGO_DBNAME=chap11-test NOTES_MODEL=mongodb mocha --no-timeouts test-model"
Simply by adding the MongoDB container to frontnet-test, the database is available at the URL shown here. Hence, it's simple to now run the test suite using the Notes MongoDB model.
The --no-timeouts option was necessary to avoid a spurious error while testing the suite against MongoDB. This option instructs Mocha to not check whether a test case execution takes too long.
The final requirement is to add this line in run.sh (or run.ps1 for Windows):
docker exec -it --workdir /notesapp/test -e DEBUG= notes-test npm run test-notes-mongodb
That, then, ensures MongoDB is tested during every test run.
We can now report to the manager the final test results matrix:
- models-fs: PASS
- models-memory: PASS
- models-levelup: PASS
- models-sqlite3: Two failures, now fixed, PASS
- models-sequelize with SQLite3: PASS
- models-sequelize with MySQL: PASS
- models-mongodb: PASS
The manager will tell you "good job" and then remember that the Models are only a portion of the Notes application. We've left two areas completely untested:
- The REST API for the user authentication service
- Functional testing of the user interface
Let's get on with those testing areas.