Closed rpineda26 closed 11 months ago
🛠️ Fix:
The middleware file_upload.js
uses the process.env.MONGODB_URI
linking to the main database so the image uploaded by the test goes to the main database instead of the test database.
With this, the developers should keep in mind which URL to use in the file_upload.js
. The process.env.TEST_MONGODB_URI
must be used when the developer is following a test-driven development approach while the other url should be used when the developer will manually use the server.
📝 Sidenote: This is a big hindrance to the flow of test-driven development so possible alternatives to manually commenting out which url will not be used will be explored. This should be enough as a solution for now but the issue will remain open.
Fix: new branch is created for testing environment called test_branch
💾 Description: The test seems to use the developer's database even when programmed to connect to its own separate database for testing. The image uploads from the test also persist in the database of the developer. This bug is caused in the test environment which affects the developer environment when the test is run with the command
npm test
. In the test environment, the database should erase its data for each test which is why it should use a separate database from the developer's database.⏰ Expected Outcome: The developer's database contents should not be erased by the test. The test database should be empty/non-existing in the MongoDB compass after a test run is completed.
☎️ Actual Outcome: The
upload.files
andupload.chunks
from the test are not deleted after a test run and are saved in the database of the developer. The other collections from the developer's database are wiped out. There is no sign of a test database being created at each test run.🎶 Steps to Reproduce 1.Populate the non-image file collections of the database used by the developer. (Image file collections refer to
uploads.chunks
anduploads.files
). 2.Run the test withnpm test
. 3.Check the database, theuploads.chunks
anduploads.files
are the only collections that remain.:memo: Sidenote: There are no pictures/screenshots in this issue because this is a backlog report of a bug that is now fixed before writing. This fixed bug is still reported to highlight a major consequence in the code that the developers must be aware of.