Skip to content

[Backend]: Add unit tests for all service modules (zero coverage today)Β #68

Closed as not planned

Description

@rishab11250

🧭 Project Area

Testing / Quality

πŸ“ Issue Summary and Problem Description

Issue summary:
The six backend service modules β€” auth, documents, verifications, vault, notifications, search β€” have zero unit test coverage. The entire test suite consists of only 19 tests across 3 files (1 integration, 2 unit), and none test any service-layer business logic.

Current test inventory:

File Tests What it covers
backend/tests/integration/app.test.js ~11 HTTP integration for documents/dashboard
backend/tests/unit/env.test.js ~7 Environment config defaults
backend/tests/unit/gracefulShutdown.test.js ~1 Shutdown signal handling

Problem description:
The service layer contains the core business logic: password hashing, token generation, document verification (SHA-256 hash comparison), vault sharing/invitation flows, email notifications, and full-text search. Without tests:

  • Regressions in critical security logic (auth, verification) go undetected
  • Refactoring carries high risk
  • New contributors lack test examples to follow
  • CI provides a false sense of coverage

Who is affected:
All developers and users. Lack of test coverage directly impacts software reliability and developer confidence.

πŸ” Current and Expected Behaviour

Current behaviour:

  • auth.service.ts β€” 0 tests (register, login, refresh, forgotPassword, resetPassword, verifyEmail, resendVerification)
  • document.service.ts β€” 0 tests (CRUD, upload, verify, search, filter, archive, favorite, summary)
  • verification.service.ts β€” 0 tests (verifyDocument, revokeVerification, getVerificationByHash)
  • vault.service.ts β€” 0 tests (invite, accept, decline, leave, getVaultMembers)
  • notification.service.ts β€” 0 tests (createNotification, getNotifications, markAsRead)
  • search.service.ts β€” 0 tests (fullTextSearch, filterDocuments)

Expected behaviour:
Each service has unit tests covering happy path, error paths, and edge cases.

🧩 Reproduction and Evidence

Step 1: Run `cd backend && npm test`
Step 2: Observe 19 passing tests
Step 3: Check coverage β€” no service files are tested

Evidence:

  • backend/tests/ directory contains only 3 test files
  • backend/src/modules/auth/auth.service.ts β€” 15+ exported functions, 0 tests
  • backend/src/modules/documents/document.service.ts β€” 15+ exported functions, 0 tests

🎯 Affected Scope

Affected files (new test files to create):

  • backend/tests/unit/auth.service.test.ts
  • backend/tests/unit/document.service.test.ts
  • backend/tests/unit/verification.service.test.ts
  • backend/tests/unit/vault.service.test.ts
  • backend/tests/unit/notification.service.test.ts
  • backend/tests/unit/search.service.test.ts

Affected APIs: All API endpoints (service tests validate the underlying business logic)
Database changes required? Yes β€” tests should use mongodb-memory-server

πŸ–₯ Environment

Operating system: All
Node.js version: v22.x
Package manager: npm 10.x
Deployment environment: Local development and CI

πŸ’‘ Solution, Alternatives, and Estimate

Priority: P1 High
Proposed solution:

  1. Install mongodb-memory-server (if not already a dev dependency)
  2. Create per-service test files under backend/tests/unit/
  3. For database-dependent tests (document, verification), use mongodb-memory-server
  4. For auth service tests, mock the database or use in-memory MongoDB
  5. Each test file covers: happy path, error paths, edge cases

Alternative solutions:
Could be split into 6 separate issues (one per service) to allow parallel contributions.

Difficulty: Advanced
Estimated time: 20-30 hours (across all 6 services)
Dependencies or blockers: mongodb-memory-server package

βœ… Acceptance Criteria and Additional Notes

  • auth.service.ts has tests for register, login, refreshToken, forgotPassword, resetPassword
  • document.service.ts has tests for create, findById, update, delete, search, filter, getSummary
  • verification.service.ts has tests for verifyDocument, revokeVerification, getVerificationByHash
  • vault.service.ts has tests for invite, accept, decline, leave
  • notification.service.ts and search.service.ts have basic happy-path tests
  • All 19 existing tests continue to pass
  • Test files use node:test and node:assert (consistent with existing tests)

Additional notes:
This is a large task that could be split into multiple issues (one per service) to allow parallel contributions by different developers.

🀝 Contributor Checklist

  • I have searched existing issues and pull requests for duplicates.
  • I can reproduce the issue, or I have clearly explained why reproduction is not applicable.
  • I will follow the contribution guidelines and target ecsoc-2026.
  • I agree to follow the Code of Conduct.
  • I have removed secrets, private documents, and personal data.

Activity

  1. added
    backendBackend API, services, workers, or domain logic
    dependenciesDependency updates and package maintenance
    devopsInfrastructure, deployment, CI/CD, or operations
    frontendReact UI, accessibility, and client experience
    performanceMeasurable speed, latency, memory, or scalability work
    securitySecurity hardening or private security coordination
    testingTest coverage, reliability, or tooling
    triageNeeds initial maintainer triage
    on Jul 22, 2026
  2. Atharv094 commented on Aug 1, 2026

    @Atharv094

    Hi team, I'd love to add unit tests for all six service modules using mongodb-memory-server and node:test/node:assert, covering key logic like auth and verification SHA-256 checks. Please assign this issue to me! Also, is this under the ECSoC program? If so, could you please add the "EcSoc26" label? Thanks!

  3. Dhruvi2006-source commented on Aug 30, 2026

    @Dhruvi2006-source

    /claim

  4. Atharv094 commented on Aug 30, 2026

    @Atharv094

    Hi! I’d like to help add unit tests for auth.service.ts using node:test and mongodb-memory-server. Could you please assign this issue to me? Also, is this an ECSoC project? If so, an admin could add the "EcSoc26" label. Thank you!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend API, services, workers, or domain logicdependenciesDependency updates and package maintenancedevopsInfrastructure, deployment, CI/CD, or operationsfrontendReact UI, accessibility, and client experienceperformanceMeasurable speed, latency, memory, or scalability worksecuritySecurity hardening or private security coordinationtestingTest coverage, reliability, or toolingtriageNeeds initial maintainer triage

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions