Files

Export Functionality Tests

Overview

Comprehensive test suite for FIN file export functionality covering all container formats, validation, and integration scenarios.

Test Structure

tests/
├── unit/
│   └── exports/
│       ├── identity-map.test.ts          # Payment identity correlation
│       ├── containers/
│       │   ├── raw-iso-container.test.ts  # Raw ISO 20022 format
│       │   ├── xmlv2-container.test.ts   # XML v2 format
│       │   └── rje-container.test.ts     # RJE format
│       ├── formats/
│       │   └── format-detector.test.ts   # Format auto-detection
│       └── utils/
│           └── export-validator.test.ts   # Query validation
└── integration/
    └── exports/
        ├── export-service.test.ts        # Export service integration
        └── export-routes.test.ts       # API routes integration

Running Tests

All Unit Tests (No Database Required)

npm test -- tests/unit/exports

Specific Test Suite

npm test -- tests/unit/exports/containers/raw-iso-container.test.ts

Integration Tests (Requires Database)

# Configure test database
export TEST_DATABASE_URL='postgresql://user:pass@localhost:5432/dbis_core_test'

# Run integration tests
npm test -- tests/integration/exports

All Export Tests

npm test -- tests/unit/exports tests/integration/exports

With Coverage

npm test -- tests/unit/exports --coverage --collectCoverageFrom='src/exports/**/*.ts'

Test Results

Unit Tests (All Passing)

  • Export Validator: 11 tests
  • Format Detector: 5 tests
  • Raw ISO Container: 8 tests
  • XML v2 Container: 7 tests
  • RJE Container: 8 tests

Total: 41 unit tests passing

⚠️ Integration Tests (Require Database)

  • Identity Map Service: 7 tests (requires DB)
  • Export Service: 8 tests (requires DB)
  • Export Routes: 12 tests (requires DB)

Test Coverage Areas

Format Generation

  • Raw ISO 20022 message export
  • XML v2 wrapper generation
  • RJE format with proper CRLF and delimiters
  • Batch export handling
  • Line ending normalization

Validation

  • Query parameter validation
  • Date range validation
  • UETR format validation
  • File size limits
  • Record count limits
  • Format structure validation

Identity Correlation

  • Payment ID to UETR mapping
  • Multi-identifier correlation
  • Reverse lookup (UETR → PaymentId)
  • ISO 20022 identifier extraction

API Integration

  • Authentication/authorization
  • Query parameter handling
  • Response formatting
  • Error handling

Prerequisites

For Unit Tests

  • Node.js 18+
  • No database required

For Integration Tests

  • PostgreSQL test database
  • TEST_DATABASE_URL environment variable
  • Database schema migrated

Test Data

Tests use TestHelpers utility for:

  • Creating test operators
  • Creating test payments
  • Creating test messages
  • Database cleanup

Continuous Integration

Tests are designed to run in CI/CD pipelines:

  • Unit tests run without external dependencies
  • Integration tests can be skipped if database unavailable
  • All tests are isolated and can run in parallel

Troubleshooting

Tests Timing Out

  • Check database connection
  • Verify TEST_DATABASE_URL is set
  • Ensure database schema is migrated

Import Errors

  • Verify TypeScript paths are configured
  • Check module exports in index files

Database Errors

  • Ensure test database exists
  • Run migrations: npm run migrate
  • Check connection string format

Next Steps

  1. Add E2E tests for complete workflows
  2. Add performance/load tests
  3. Add property-based tests for edge cases
  4. Increase coverage for export service
  5. Add tests for export history tracking