forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemories_http_result_test.dart
More file actions
51 lines (40 loc) · 1.86 KB
/
Copy pathmemories_http_result_test.dart
File metadata and controls
51 lines (40 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/backend/http/api/memories.dart';
void main() {
test('a 503 is a failed result, not an empty success', () {
const body = '{"detail":"Historical memory unavailable"}';
final result = memoriesResultFromHttp(statusCode: 503, body: body);
expect(result.ok, isFalse, reason: 'a 503 must not be presented as a successful empty list');
expect(result.memories, isEmpty);
expect(result.failureReason, MemoriesFetchFailureReason.httpError);
expect(result.statusCode, 503);
});
test('a 200 with an empty list is a genuine empty account', () {
final result = memoriesResultFromHttp(statusCode: 200, body: '[]');
expect(result.ok, isTrue);
expect(result.memories, isEmpty);
expect(result.failureReason, isNull);
});
test('a missing response is a failed result, not an empty success', () {
final result = memoriesResultFromHttp(statusCode: null, body: null);
expect(result.ok, isFalse);
expect(result.failureReason, MemoriesFetchFailureReason.noResponse);
expect(result.memories, isEmpty);
});
test('thisDeviceOnly plus a 503 is still a fetch failure, not unsupported device_scope', () {
final result = memoriesResultFromHttp(statusCode: 503, body: 'unavailable');
expect(result.ok, isFalse);
expect(result.failureReason, MemoriesFetchFailureReason.httpError);
expect(
result.deviceScopeSupported,
isTrue,
reason: 'a 503 must not flip deviceScopeSupported; that flag is only for the 400 fallback',
);
});
test('a 200 body that cannot be decoded is a failed result, not an empty success', () {
final result = memoriesResultFromHttp(statusCode: 200, body: 'not-json');
expect(result.ok, isFalse);
expect(result.failureReason, MemoriesFetchFailureReason.decodeError);
expect(result.memories, isEmpty);
});
}