Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe Test Runner for Mongoose Models #1070

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

Mike-Popovych
Copy link
Contributor

Description

This PR introduces safe tests for database models. These tests are designed to connect to a real database and verify model functionality.

Key Changes

  1. Added Tests for Database Models:

    • New tests are included to ensure the integrity of database models.
    • These tests connect to a database specified in the .env.test.local file.
  2. Environment Variable:

    • To run the tests, you need to add the following variable to your .env.test.local file:
      MONGODB_URL_READONLY_TEST=<your-local-database-url>
      
      For now, it is recommended to use your local database while writing tests.
  3. Running Tests:

    • You can execute the model tests using the following command:
      npm run test:models
  4. Removed Model Tests from General Testing Workflow:

    • Model tests are temporarily excluded from the general testing workflow (triggered on push) until the database structure is fully prepared.

How to Test

  1. Add the required environment variable MONGODB_URL_READONLY_TEST to your .env.test.local file.
  2. Run the tests using npm run test:models.
  3. Verify that all tests pass successfully.

Notes

  • This setup connects to a real database, so ensure you use a safe and isolated environment for testing.
  • Once the database is organized, model tests will be re-integrated into the general testing pipeline.

const { restrictedOperations } = require('~/test/test-consts')

const connectToDatabase = async () => {
const dbUri = process.env.MONGODB_URL_READONLY_TEST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add process.env.MONGODB_URL_READONLY_TEST to config in \src\configs\config.js for consistency as the the setup is done within src
and import as const { config: { MONGODB_URL } } = require('~/configs/config') then

await connectToDatabase()
initialization(app)

const server = app.listen(process.env.SERVER_PORT || 8080)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could SERVER_PORT be imported from ~/configs/config for consistency?

Copy link

sonarcloud bot commented Dec 18, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(SP:1) Safe Test Runner for Mongoose Models
3 participants