Files
social-app/apps/test/data/cache/hybrid_cache_store_test.dart
T

45 lines
1.3 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:social_app/data/cache/cache_scope.dart';
import 'package:social_app/data/cache/cache_store.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('HybridCacheStore', () {
test('falls back to persistent and backfills memory', () async {
SharedPreferences.setMockInitialValues(<String, Object>{});
final prefs = await SharedPreferences.getInstance();
final persistent = PersistentCacheStore(prefs: prefs);
await persistent.write<String>('k', 'v');
final hybrid = HybridCacheStore(
memory: MemoryCacheStore(),
persistent: persistent,
);
final firstRead = await hybrid.read<String>('k');
expect(firstRead, 'v');
await persistent.remove('k');
final secondRead = await hybrid.read<String>('k');
expect(secondRead, 'v');
});
test('cache invalidator no-ops without configured scope', () async {
CacheScope.resetProvider();
final invalidator = CacheInvalidator(
store: HybridCacheStore(
memory: MemoryCacheStore(),
persistent: PersistentCacheStore(),
),
);
expect(
() => invalidator.invalidate('calendar:day:2026-03-31'),
returnsNormally,
);
});
});
}