From c3cf9bd4d68b906a65ab1b56722dad1a46e646a9 Mon Sep 17 00:00:00 2001 From: Victor Nguyen Date: Sun, 8 Dec 2024 17:19:51 +0700 Subject: [PATCH] feat: add test for cleaning both stale and non-stale cache objects (#160) --- .../test/common_store_testing.dart | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/dio_cache_interceptor/test/common_store_testing.dart b/dio_cache_interceptor/test/common_store_testing.dart index 24044c7..727bb35 100644 --- a/dio_cache_interceptor/test/common_store_testing.dart +++ b/dio_cache_interceptor/test/common_store_testing.dart @@ -97,18 +97,29 @@ Future deleteItem(CacheStore store) async { Future 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 expires(CacheStore store) async {