Skip to content

Add Backend Unit Tests [backend]Β #29

@salazarsebas

Description

@salazarsebas

πŸ§ͺ Add Backend Unit Tests βœ…

πŸ“ Description

Implement unit tests for the backend to ensure the reliability of compilerController, commandExecutor, and fileManager. Tests will validate request handling, command execution, and file operations, aligning with the project’s emphasis on code quality and maintainability. This will help catch regressions early and ensure robust backend functionality.

🎯 Objective

Create unit tests in apps/backend/src/ using a testing framework like Jest to cover compilerController, commandExecutor, and fileManager.

πŸ—‚ Structure

  • Directory: apps/backend/src/
  • Files:
    • apps/backend/src/controllers/compilerController.spec.ts
    • apps/backend/src/utils/commandExecutor.spec.ts
    • apps/backend/src/utils/fileManager.spec.ts
  • Expected structure:
    apps/backend/
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ controllers/
    β”‚   β”‚   └── compilerController.spec.ts
    β”‚   β”œβ”€β”€ utils/
    β”‚   β”‚   β”œβ”€β”€ commandExecutor.spec.ts
    β”‚   β”‚   └── fileManager.spec.ts
    

βœ… Requirements

  • Install Jest with bun add -d jest @types/jest ts-jest.
  • Configure Jest in package.json or jest.config.js for TypeScript.
  • Create tests for compilerController:
    • Validate request handling for /api/compile and /api/test.
    • Mock utility functions to isolate controller logic.
  • Create tests for commandExecutor:
    • Test successful command execution and error handling.
    • Mock child_process.spawn to avoid real shell commands.
  • Create tests for fileManager:
    • Test project setup and cleanup with mock file system.
  • Run tests with bun test.
  • Commit changes with a message like test: add backend unit tests.
  • Push changes to the GitHub repository.

πŸ† Expected Outcomes

  • Unit tests pass for compilerController, commandExecutor, and fileManager.
  • Tests cover request handling, command execution, and file operations.
  • Tests run successfully with bun test.
  • Changes are committed and pushed to GitHub.

πŸ”— References

πŸ“‹ Notes

  • Use mocks to isolate dependencies (e.g., child_process, fs).
  • Focus on critical paths; expand coverage in later milestones.

Metadata

Metadata

Assignees

Labels

backendIssues for the development of the backend of the online soroban compilerenhancementNew feature or requestexpressjsIssues related to the application backend and the Express js framework

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions