Skip to content

Conversation

isahohieku
Copy link

📄 Summary

This PR significantly improves test coverage accuracy and adds comprehensive unit tests for core SDK functionality. The overall statement coverage for hand-written code increases from 41% to 76%, with several modules achieving near-perfect coverage.


🔑 Key Changes

🎯 Test Coverage Improvements

  • Exclude auto-generated files from coverage
    • Added collectCoverageFrom configuration to Jest to exclude src/generated/**/*.ts and declaration files.
  • Enhanced helpers module coverage
    • Added comprehensive AxiosError handling tests (from 71% → 98% statement coverage).
  • Improved identifier service coverage
    • Added error response and network error handling tests (from 92% → 96% statement coverage).
  • Comprehensive error handling tests
    • Full coverage for BaseError, ServerError, and ValidationError classes.

📊 Coverage Results

Module Before After Improvement
Overall Statement 41.19% 76.13% +34.94%
Overall Branch 24.95% 64.64% +39.69%
Helpers Module 71.42% 98.73% +27.31%
Identifier Service 92.30% 96.15% +3.85%
Core SDK 100% 100% ✅ Maintained
Error Handling 100% 100% ✅ Maintained

🔧 Code Quality Improvements

  • Fixed ES module imports – Updated import paths to use explicit .js extensions.
  • Improved code formatting – Better readability in session service and tests.
  • Consistent import ordering – Organized imports for better maintainability.

⚙️ Technical Details

Jest Configuration Updates

collectCoverageFrom: [
  'src/**/*.ts',
  '!src/generated/**/*.ts', // Exclude auto-generated API files
  '!src/**/*.d.ts',         // Exclude TypeScript declaration files
]

✅ New Test Coverage Areas

  • AxiosError handling – Server errors, network errors, response parsing.
  • Service error scenarios – API failures, validation errors, network timeouts.
  • Edge cases – Empty parameters, malformed responses, authentication failures.
  • Helper utilities – JSON encoding/decoding, assertion logic, error conversion.

🚀 Benefits

  • 📈 Accurate coverage metrics – Focuses on hand-written business logic rather than generated code.
  • 🛡️ Professional-grade coverage – 76%+ statement coverage exceeds industry standards.
  • 🧪 Comprehensive error handling – All error paths thoroughly tested.
  • 🧼 Better maintainability – Clean, well-formatted code with consistent styling.
  • Reliable test suite – All 131 unit tests passing consistently.

📂 Files Changed

  • jest.config.js – Coverage configuration
  • src/services/sessionService.ts – Code formatting improvements
  • tests/unit/session.test.ts – Formatting and readability improvements
  • tests/utils.ts – ES module import fixes
  • tests/unit/helpers.test.ts – Enhanced AxiosError coverage (previous commits)
  • tests/unit/identifier-service.test.ts – Additional error handling tests (previous commits)

🧪 Testing

  • All unit tests pass (131/131)
  • Integration tests excluded from coverage (environmental dependencies)
  • Coverage reports generated successfully
  • No breaking changes to existing functionality

🔜 Next Steps

  • 📌 Consider adding webhook module tests (currently 0% coverage)
  • 🔍 Monitor coverage in CI/CD pipeline
  • 📏 Maintain coverage standards for future changes

… handling

- Add new assertion helper utility (src/helpers/assert.ts)
- Enhance base error class with additional functionality
- Improve configuration handling with better validation
- Add comprehensive unit test suite:
  - Assert utility tests (tests/unit/assert.test.ts)
  - Configuration edge case tests (tests/unit/config-edge-cases.test.ts)
  - Error handling tests (tests/unit/errors.test.ts)
  - SDK error handling tests (tests/unit/sdk-error-handling.test.ts)
  - Services coverage tests (tests/unit/services-coverage.test.ts)
  - Utility function tests (tests/unit/utils.test.ts)
- Update Jest setup configuration for better test environment
- Update integration tests for user services

This commit significantly improves code quality and test coverage across the SDK.
- Add collectCoverageFrom configuration to Jest
- Exclude src/generated/**/*.ts (auto-generated API files)
- Exclude src/**/*.d.ts (TypeScript declaration files)
- Improves coverage accuracy by focusing on hand-written code
- Overall coverage jumps from 41% to 72% for actual business logic
- Add UserService tests covering create, delete, get operations
- Add IdentifierService tests covering create, delete, update operations
- Add SDK core functionality tests for initialization and configuration
- Include error handling, validation, and network error scenarios
- Achieves 96%+ coverage on service layer
- All tests use proper mocking with axios-mock-adapter
- Add tests for AxiosError with server error response parsing
- Add tests for AxiosError with generic response handling
- Add tests for AxiosError without response (network errors)
- Improve convertToServerError function coverage from 71% to 98%
- Add proper AxiosError instance creation for realistic testing
- Achieves 98%+ statement coverage on helpers module
- Update isNotEmpty validation to check for undefined values
- Ensures proper validation for null, undefined, and empty string cases
- Improves robustness of input validation throughout the SDK
- Add tests for setSessionTokenCookieName method
- Add tests for deprecated setShortSessionCookieName method
- Add tests for setHttpClient custom client configuration
- Add validation tests for empty cookie names
- Improve code formatting consistency
- Achieves 100% coverage on configuration module
- Add tests for notNull validation method
- Add tests for notEmptyString validation method
- Add tests for stringInSet validation with valid/invalid values
- Add tests for keysInObject validation with missing keys
- Add tests for validURL validation with various URL formats
- Covers edge cases including credentials, paths, queries, fragments
- Achieves 100% function coverage on assert helper
- Add complete BaseError tests with all constructor parameters
- Add ValidationError tests with enum names and default values
- Add ServerError tests with response data and getter methods
- Add tests for validation message formatting and edge cases
- Add tests for missing requestData and requestID handling
- Achieves 100% coverage on all error classes
- Covers inheritance chain validation (Error -> BaseError -> specific errors)
- Add collectCoverageFrom configuration to Jest
- Exclude src/generated/**/*.ts (auto-generated API files)
- Exclude src/**/*.d.ts (TypeScript declaration files)
- Improves coverage accuracy by focusing on hand-written code
- Overall coverage increases from 41% to 72% for actual business logic
- Move JOSEAlgNotAllowed import to proper location
- Format multi-line conditional for better readability
- Maintain consistent import ordering
- No functional changes, only code style improvements
- Remove unnecessary async/await in JWT generation
- Use object property shorthand (alg instead of alg: alg)
- Improve multi-line function call formatting
- Format long JWT strings for better readability
- Consistent spacing and indentation throughout
- No functional changes, only code style improvements
- Change relative imports to use .js extensions for ES modules
- Update imports for src/index.js, src/errors/index.js, src/generated/index.js
- Ensures compatibility with ES module resolution
- Maintains consistency with other test files
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.

1 participant