Skip to content

Commit

Permalink
feat: add test for cleaning both stale and non-stale cache objects (#160
Browse files Browse the repository at this point in the history
)
  • Loading branch information
VinhNgT authored Dec 8, 2024
1 parent 4c5b85d commit c3cf9bd
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions dio_cache_interceptor/test/common_store_testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,29 @@ Future<void> deleteItem(CacheStore store) async {
Future<void> clean(CacheStore store) async {
await _addFooResponse(
store,
key: 'not-stale',
maxStale: DateTime.now().add(const Duration(days: 1)),
);
expect(await store.exists('foo'), isTrue);
await _addFooResponse(
store,
key: 'stale',
maxStale: DateTime.now().subtract(const Duration(days: 1)),
);

await store.clean(staleOnly: true);
expect(await store.exists('foo'), isTrue);
expect(await store.exists('not-stale'), isTrue);
expect(await store.exists('stale'), isTrue);

await store.clean(priorityOrBelow: CachePriority.low);
expect(await store.exists('foo'), isTrue);
expect(await store.exists('not-stale'), isTrue);
expect(await store.exists('stale'), isTrue);

await store.clean(staleOnly: true);
expect(await store.exists('not-stale'), isTrue);
expect(await store.exists('stale'), isFalse);

await store.clean();
expect(await store.exists('foo'), isFalse);
expect(await store.exists('not-stale'), isFalse);
expect(await store.exists('stale'), isFalse);
}

Future<void> expires(CacheStore store) async {
Expand Down

0 comments on commit c3cf9bd

Please sign in to comment.