martin-markovic / learn-connect

Multi-feature platform designed to enhance the online learning experience.
MIT License
0 stars 0 forks source link

Quizzes #8

Closed martin-markovic closed 2 months ago

martin-markovic commented 2 months ago

Pull Request Description

Summary

This pull request includes various updates and enhancements to the quiz API functionality, middleware integration, and testing structure. Below are the detailed changes made:

Features


  1. Quiz API integration:

    • Implemented CRUD operations for quizzes.

    • Integrated controller functions into quizRoutes.js for handling respective API endpoints.

    • Integrated new route into router.js.

  2. JWT integration:

    • Integrated middleware into quizRoutes.js to validate tokens and protect routes.

    • Implemented quizModel.js to handle quiz functionality with mongoose schema

    • Created quizModel.js to define the Mongoose schema and handle quiz-related data operations.

    • Integrated protect middleware into quizRoutes.js along with controller functions.

    • Applied protect middleware to quizRoutes.js to secure the endpoints alongside the controller functions.

  3. Cleanup and refactoring:

    • Introduced separate scripts for unit and integration tests in package.json.

    • Removed redundant protect import from userRoutes.js.

    • Added a .env.test file to separate environment configurations for testing.

    • Updated .gitignore to exclude .env.test from version control.

    • Modified test setup to create a new quiz before each test run, ensuring consistent and reliable test conditions.

    • Modified the test script path to point to test/backend.

    • Relocated server.test.js and userAuth.test.js to test/backend/integration to distinguish between unit and integration tests.

    • Removed quiz.test.js pending fixes.

    • Established a mock repository in the project root for mocking unit tests.

    • Added mockDatabase.js to facilitate mocking of database interactions in unit tests.

Testing

  1. Integration Tests:

    • Added tests for POST requests to quiz API endpoints to verify functionality and correctness.

    • Ensured that API responses contain the expected status codes and messages for all endpoints.

  2. Unit Tests:

Conclusion

These changes aim to improve the structure, security, and testing reliability of the quiz API. Each modification enhances the project by addressing specific areas of functionality, middleware integration, and testing strategy. Please review the changes and provide feedback.

Thank you for your attention and assistance in merging these updates.