126 lines
4.4 KiB
Dart
126 lines
4.4 KiB
Dart
import 'package:cyberhybridhub/admin/models/market_history_admin_config.dart';
|
|
import 'package:cyberhybridhub/admin/models/market_history_week_coverage.dart';
|
|
import 'package:cyberhybridhub/admin/models/question_audit_asset.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('MarketHistoryAdminConfig', () {
|
|
test('parses from null JSON', () {
|
|
final config = MarketHistoryAdminConfig.fromJson(null);
|
|
expect(config.archiveEnabled, isFalse);
|
|
expect(config.windowDays, 5);
|
|
expect(config.retentionDays, 5);
|
|
expect(config.syncEnabled, isFalse);
|
|
});
|
|
|
|
test('parses from valid JSON', () {
|
|
final config = MarketHistoryAdminConfig.fromJson(<String, dynamic>{
|
|
'archiveEnabled': true,
|
|
'windowDays': 10,
|
|
'retentionDays': 30,
|
|
'syncEnabled': true,
|
|
});
|
|
expect(config.archiveEnabled, isTrue);
|
|
expect(config.windowDays, 10);
|
|
expect(config.retentionDays, 30);
|
|
expect(config.syncEnabled, isTrue);
|
|
});
|
|
});
|
|
|
|
group('QuestionAuditReport', () {
|
|
test('parses from JSON with custom slot starts', () {
|
|
final report = QuestionAuditReport.fromJson(<String, dynamic>{
|
|
'compareUntil': '2026-05-30T16:00:00Z',
|
|
'newerSlotStart': '2026-05-30T12:45:00Z',
|
|
'olderSlotStart': '2026-05-30T09:30:00Z',
|
|
'windowDays': 5,
|
|
'canStepOlder': true,
|
|
'canStepNewer': false,
|
|
'stepOlderCompareUntil': '2026-05-25T16:00:00Z',
|
|
'assets': [
|
|
{
|
|
'symbol': 'AAPL',
|
|
'priceDelta': 1.25,
|
|
'volumeDelta': 5000,
|
|
'olderSlot': {
|
|
'asOf': '2026-05-30T09:30:00Z',
|
|
'open': 150.0,
|
|
'high': 152.0,
|
|
'low': 149.0,
|
|
'close': 151.0,
|
|
'avgPrice': 150.5,
|
|
'volume': 10000,
|
|
'volumeUsd': 1505000,
|
|
},
|
|
'newerSlot': {
|
|
'asOf': '2026-05-30T12:45:00Z',
|
|
'avgPrice': 152.0,
|
|
'volume': 12000,
|
|
}
|
|
}
|
|
]
|
|
});
|
|
|
|
expect(report.compareUntil, DateTime.parse('2026-05-30T16:00:00Z').toUtc());
|
|
expect(report.newerSlotStart, DateTime.parse('2026-05-30T12:45:00Z').toUtc());
|
|
expect(report.olderSlotStart, DateTime.parse('2026-05-30T09:30:00Z').toUtc());
|
|
expect(report.canStepOlder, isTrue);
|
|
expect(report.canStepNewer, isFalse);
|
|
expect(report.stepOlderCompareUntil, DateTime.parse('2026-05-25T16:00:00Z').toUtc());
|
|
expect(report.stepNewerCompareUntil, isNull);
|
|
expect(report.assets.length, 1);
|
|
|
|
final asset = report.assets.first;
|
|
expect(asset.symbol, 'AAPL');
|
|
expect(asset.priceDelta, 1.25);
|
|
expect(asset.olderSlot.open, 150.0);
|
|
expect(asset.olderSlot.volumeUsd, 1505000);
|
|
expect(asset.newerSlot.volumeUsd, 12000 * 152.0); // fallback calculation
|
|
});
|
|
|
|
test('parses from JSON with default/missing slot starts', () {
|
|
final report = QuestionAuditReport.fromJson(<String, dynamic>{
|
|
'asOf': '2026-05-30T16:00:00Z',
|
|
'windowDays': 5,
|
|
});
|
|
expect(report.compareUntil, DateTime.parse('2026-05-30T16:00:00Z').toUtc());
|
|
expect(report.newerSlotStart, report.compareUntil.subtract(const Duration(hours: 3, minutes: 15)));
|
|
expect(report.olderSlotStart, report.compareUntil.subtract(const Duration(hours: 6, minutes: 30)));
|
|
});
|
|
});
|
|
|
|
group('MarketHistoryWeekCoverageReport', () {
|
|
test('parses from valid JSON', () {
|
|
final report = MarketHistoryWeekCoverageReport.fromJson(<String, dynamic>{
|
|
'asOf': '2026-05-30T15:00:00Z',
|
|
'windowDays': 5,
|
|
'slotsPerDay': 6,
|
|
'symbolCount': 10,
|
|
'isConsistent': true,
|
|
'days': [
|
|
{
|
|
'date': '2026-05-30',
|
|
'slotsPerDay': 6,
|
|
'completedSlots': 6,
|
|
'fullySyncedSlots': 6,
|
|
'slots': [
|
|
{
|
|
'slotStart': '2026-05-30T00:00:00Z',
|
|
'completed': true,
|
|
'fullySynced': true,
|
|
'syncedSymbolCount': 10,
|
|
'expectedSymbolCount': 10,
|
|
}
|
|
]
|
|
}
|
|
]
|
|
});
|
|
|
|
expect(report.asOf, DateTime.parse('2026-05-30T15:00:00Z').toUtc());
|
|
expect(report.days.length, 1);
|
|
expect(report.days.first.date, DateTime.parse('2026-05-30T00:00:00Z').toUtc());
|
|
expect(report.days.first.slots.first.completed, isTrue);
|
|
});
|
|
});
|
|
}
|