-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathkey_test.dart
43 lines (37 loc) · 1.1 KB
/
key_test.dart
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
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
import 'package:typesense/src/key.dart';
import 'test_utils.mocks.dart';
void main() {
group('Key', () {
late Key key;
late MockApiCall mock;
setUp(() {
mock = MockApiCall();
key = Key(1, mock);
});
test('retrieve() calls Api.get()', () async {
when(mock.get('/keys/1')).thenAnswer((realInvocation) => Future.value({
"actions": ["documents:search"],
"collections": ["*"],
"description": "Search-only key.",
"id": 1,
"value_prefix": "vxpx"
}));
expect(
await key.retrieve(),
equals({
"actions": ["documents:search"],
"collections": ["*"],
"description": "Search-only key.",
"id": 1,
"value_prefix": "vxpx"
}));
});
test('delete() calls Api.delete()', () async {
when(mock.delete('/keys/1'))
.thenAnswer((realInvocation) => Future.value({"id": 1}));
expect(await key.delete(), equals({"id": 1}));
});
});
}