Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions apps/aggregator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,88 @@ const results = this.normalizationService.normalizeMany(rawPrices);
const { successful, failed } = this.normalizationService.normalizeManyWithErrors(rawPrices);
```

## Testing Strategy

The Aggregator service includes comprehensive test coverage for unit and integration testing.

### Test Structure

```
test/
β”œβ”€β”€ integration/
β”‚ └── aggregation-pipeline.integration.spec.ts # Complete pipeline tests
```

### Running Tests

**Unit Tests** (default, fast execution):
```bash
npm run test # Run all unit tests
npm run test:watch # Watch mode
npm run test:cov # With coverage report
```

**Integration Tests** (tests complete pipeline):
```bash
npm run test:integration # Run integration tests
npm run test:integration:cov # With coverage report
npm run test:all # Unit + Integration tests
```

### Test Coverage

**Unit Tests** (src/**/*.spec.ts):
- Service isolation and correctness
- Strategy implementations (Weighted Average, Median, Trimmed Mean)
- Utility functions
- Edge cases and error handling
- Target: >85% coverage

**Integration Tests** (test/integration/):
- End-to-end normalization pipeline
- Complete aggregation pipeline
- Multi-source consensus calculation
- Confidence metrics computation
- All aggregation methods comparison
- Edge cases (single source, empty arrays, many sources)
- Price spread and volatility scenarios

### Test Scenarios Covered

1. **High Confidence** - Closely agreeing prices from multiple sources
2. **Volatile Market** - High price spread scenarios
3. **Single Source** - Graceful handling of minimal data
4. **Many Sources** - Scalability with 20+ sources
5. **Different Methods** - Validation of all aggregation strategies
6. **Complete Pipeline** - Raw β†’ Normalized β†’ Aggregated flow

### Running Integration Tests

```bash
# Run integration tests with single-threaded execution
npm run test:integration

# Run with coverage
npm run test:integration:cov

# Run specific test file
npm run test:integration -- aggregation-pipeline.integration.spec

# Watch mode
npm run test:integration -- --watch
```

### Test Output

Integration tests validate:
- βœ… Normalization correctness
- βœ… Confidence scoring (high vs volatile scenarios)
- βœ… Weighted average aggregation
- βœ… Median aggregation
- βœ… Trimmed mean aggregation
- βœ… Multi-source extraction
- βœ… End-to-end pipeline

## Status

🚧 Under construction - Aggregation and filtering logic will be implemented in subsequent issues.
Expand Down
15 changes: 15 additions & 0 deletions apps/aggregator/jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
displayName: 'aggregator-integration',
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: '.',
testMatch: [
'**/test/integration/**/*.integration.spec.ts',
],
moduleFileExtensions: ['js', 'json', 'ts'],
moduleNameMapper: {
'^@oracle-stocks/shared$': '<rootDir>/../../packages/shared/src',
'^@oracle-stocks/shared/(.*)$': '<rootDir>/../../packages/shared/src/$1',
},
testTimeout: 30000,
};
7 changes: 7 additions & 0 deletions apps/aggregator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:integration": "jest --config jest.integration.config.js --runInBand",
"test:integration:cov": "jest --config jest.integration.config.js --coverage --runInBand",
"test:e2e": "jest --config jest.integration.config.js --testPathPattern=e2e --runInBand",
"test:all": "npm run test && npm run test:integration",
"check-types": "tsc --noEmit"
},
"dependencies": {
Expand Down Expand Up @@ -63,6 +67,9 @@
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"testPathIgnorePatterns": [
"<rootDir>/../test/"
],
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
Expand Down
6 changes: 0 additions & 6 deletions apps/aggregator/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { Module } from '@nestjs/common';
import { NormalizationModule } from './modules/normalization.module';
import { ConfigModule } from '@nestjs/config';
import { AggregationService } from './services/aggregation.service';
import { WeightedAverageAggregator } from './strategies/aggregators/weighted-average.aggregator';
import { MedianAggregator } from './strategies/aggregators/median.aggregator';
import { TrimmedMeanAggregator } from './strategies/aggregators/trimmed-mean.aggregator';
import { HealthModule } from './health/health.module';
import { MetricsModule } from './metrics/metrics.module';
import { DebugModule } from './debug/debug.module';
Expand All @@ -29,9 +26,6 @@ import { DataReceptionService } from './services/data-reception.service';
providers: [
DataReceptionService,
AggregationService,
WeightedAverageAggregator,
MedianAggregator,
TrimmedMeanAggregator,
],
exports: [AggregationService],
})
Expand Down
Loading