Testing our MongoDB integration layer
Yes, we have made the migration and everything seems to be running fine, but we need to ensure that the tests work as expected. Currently, the tests use the filesystem to store data, so we need to change the tests to make them use MongoDB.
Update the utilities
We will edit the test/utils.js
file to use MongoDB instead of the filesystem. As we are now using MongoDB, we need to load the fixtures in the database to know the IDs. So now, the fixtures will keep the same structure, but they will be stored and collected in the database using populateDb
and the new getFixtures
function:
import mongoose from 'mongoose' import { Whisper } from '../database.js' const ensureDbConnection = async () => { try { if (mongoose.connection.readyState !== 1) { await mongoose.connect(process...