Skip to content

feat: Add comprehensive unit tests for core services#106

Open
bbjiggy wants to merge 6 commits into
GuardZero144:mainfrom
bbjiggy:feat/add-service-unit-tests
Open

feat: Add comprehensive unit tests for core services#106
bbjiggy wants to merge 6 commits into
GuardZero144:mainfrom
bbjiggy:feat/add-service-unit-tests

Conversation

@bbjiggy

@bbjiggy bbjiggy commented Jun 14, 2026

Copy link
Copy Markdown

Description

This PR adds comprehensive unit tests for the core backend services to improve code quality and reliability.

Changes

  • IdentityService Tests: Complete test coverage for all CRUD operations

    • Create, read, update, delete, and revoke operations
    • Finding identities by wallet address and document hash
    • Error handling for not found scenarios
  • VerificationService Tests: Full verification workflow coverage

    • Create and retrieve verifications
    • Approve and reject verification flows with reasons
    • Finding verifications by identity ID
    • Error handling for invalid operations
  • AuthService Tests: Authentication logic coverage

    • Wallet validation (placeholder for future implementation)
    • JWT token generation on login
    • Token verification and decoding
    • Proper mocking of JwtService and ConfigService

Testing Approach

  • Mocked all repository and service dependencies using Jest
  • Tested both happy paths and error cases
  • Included NotFoundException scenarios
  • Clean test structure with beforeEach/afterEach hooks
  • Followed NestJS testing best practices

Benefits

  • Code Quality: Ensures services work as expected
  • Regression Prevention: Catch bugs before they reach production
  • Documentation: Tests serve as usage examples
  • Confidence: Safe refactoring with test safety net
  • CI/CD Ready: Foundation for automated testing pipeline

Test Statistics

  • 3 service test suites created
  • 20+ individual test cases
  • Coverage for critical business logic

How to Run Tests

cd backend
npm install
npm test

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Code quality improvement
  • Testing infrastructure

Notes

  • All tests follow Jest and NestJS testing conventions
  • Repository mocks ensure isolated unit testing
  • Ready for CI/CD integration

- Added unit tests for IdentityService with full CRUD coverage
- Added unit tests for VerificationService including approve/reject flows
- Added unit tests for AuthService covering authentication logic
- All tests include proper mocking of dependencies
- Tests cover both happy paths and error cases (NotFoundException)
- Achieves high code coverage for critical business logic
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@meshackyaro is attempting to deploy a commit to the Josie's projects Team on Vercel.

A member of the Team first needs to authorize it.

- Fixed formatting in access_control.rs
- Fixed formatting in data_sharing.rs
- Fixed formatting in identity_registry.rs
- Fixed formatting in lib.rs
- Fixed formatting in verification.rs
- Ensures CI formatting checks pass
Resolved conflicts in Rust smart contracts:
- Accepted upstream changes with improved error handling using Result types
- Applied proper Rust formatting with cargo fmt
- Maintained consistency with upstream code style
- All conflicts resolved in access_control.rs, data_sharing.rs, identity_registry.rs, lib.rs, and verification.rs
- Changed tuple key from &(&owner, &document_hash) to (owner.clone(), document_hash.clone())
- Soroban storage requires owned values in tuple keys, not references
- Fixes E0277 trait bound error for TryFromVal
- All clippy checks now pass
- Added [features] section with testutils feature that enables soroban-sdk/testutils
- Fixes CI test failure where cargo test --features testutils was failing
- Allows CI to run tests with testutils feature enabled
- Updated soroban-sdk from 21.0.0 to 21.7.7 for consistency
- Added panic = "abort" to release profile for WASM compatibility
- Fixes E0152 duplicate lang item error (panic_impl)
- WASM build now compiles successfully for wasm32-unknown-unknown target
@Josie123-Dev

Copy link
Copy Markdown
Member

Kindly fix conflicts @bbjiggy
Files
backend/src/identity/identity.service.spec.ts
backend/src/verification/verification.service.spec.ts
contracts/src/lib.rs

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants