Skip to content

Commit 6ffaaef

Browse files
committed
chore: Add more tests.
1 parent 0cf6980 commit 6ffaaef

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

http_cache_client/test/http_cache_client_cache_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ void main() {
5555
expect(resp304.statusCode, equals(200));
5656
final cacheResp2 = await store.get(key);
5757

58-
expect(cacheResp1, equals(cacheResp2));
58+
expect(
59+
cacheResp1!.copyWith(
60+
requestDate: cacheResp2!.requestDate,
61+
responseDate: cacheResp2.responseDate),
62+
equals(cacheResp2));
5963
});
6064

6165
test('Fetch noCache policy', () async {

http_cache_core/lib/src/model/cache/cache_response.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ class CacheResponse {
253253
other.maxStale == maxStale &&
254254
other.priority == priority &&
255255
other.url == url &&
256-
other.statusCode == statusCode;
256+
other.statusCode == statusCode &&
257+
other.requestDate == requestDate &&
258+
other.responseDate == responseDate;
257259
}
258260

259261
@override
@@ -269,6 +271,8 @@ class CacheResponse {
269271
maxStale.hashCode ^
270272
priority.hashCode ^
271273
url.hashCode ^
272-
statusCode.hashCode;
274+
statusCode.hashCode ^
275+
requestDate.hashCode ^
276+
responseDate.hashCode;
273277
}
274278
}

http_cache_store_tester/lib/common_store_testing.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Future<void> _addFooResponse(
1313
List<int>? headers,
1414
DateTime? maxStale,
1515
String url = 'https://foo.com',
16+
CachePriority priority = CachePriority.normal,
1617
}) {
1718
final resp = CacheResponse(
1819
cacheControl: cacheControl ?? CacheControl(),
@@ -24,7 +25,7 @@ Future<void> _addFooResponse(
2425
key: key,
2526
lastModified: lastModified,
2627
maxStale: maxStale,
27-
priority: CachePriority.normal,
28+
priority: priority,
2829
requestDate: DateTime.now().subtract(const Duration(milliseconds: 50)),
2930
responseDate: DateTime.now(),
3031
url: url,
@@ -49,27 +50,33 @@ Future<void> getItem(CacheStore store) async {
4950
contentTypeHeader: [jsonContentType]
5051
}));
5152
final cacheControl = CacheControl(maxAge: 10, privacy: 'public');
53+
final expires = DateTime.now();
54+
final lastModified = HttpDate.format(DateTime.now());
5255

5356
await _addFooResponse(
5457
store,
5558
maxStale: DateTime.now().add(const Duration(days: 1)),
5659
headers: headers,
5760
cacheControl: cacheControl,
61+
priority: CachePriority.high,
62+
expires: expires,
63+
lastModified: lastModified,
5864
);
5965

6066
final resp = await store.get('foo');
6167
expect(resp, isNotNull);
6268
expect(resp?.key, equals('foo'));
6369
expect(resp?.url, equals('https://foo.com'));
6470
expect(resp?.eTag, equals('an, etag'));
65-
expect(resp?.lastModified, isNull);
71+
expect(resp?.lastModified, lastModified);
6672
expect(resp?.maxStale, isNotNull);
6773
expect(resp?.content, equals(utf8.encode('foo')));
6874
expect(resp?.headers, equals(headers));
69-
expect(resp?.priority, CachePriority.normal);
70-
expect(resp?.cacheControl.maxAge, equals(cacheControl.maxAge));
71-
expect(resp?.cacheControl.privacy, equals(cacheControl.privacy));
75+
expect(resp?.priority, CachePriority.high);
76+
expect(resp?.cacheControl, equals(cacheControl));
7277
expect(resp?.statusCode, equals(200));
78+
expect(resp!.expires!.millisecondsSinceEpoch ~/ 1000,
79+
equals(expires.millisecondsSinceEpoch ~/ 1000));
7380
}
7481

7582
Future<void> deleteItem(CacheStore store) async {

0 commit comments

Comments
 (0)