-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdocument_test.dart
56 lines (51 loc) · 1.51 KB
/
document_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
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'package:test/test.dart';
import 'package:mockito/mockito.dart';
import 'package:typesense/src/document.dart';
import 'test_utils.mocks.dart';
void main() {
group('Document', () {
late Document document;
late MockApiCall mock;
final documentMap = {
"id": "124",
"company_name": "Stark Industries",
"num_employees": 5215,
"country": "USA"
};
setUp(() {
mock = MockApiCall();
document = Document(
'companies',
'124',
mock,
);
});
test('delete() calls ApiCall.delete()', () async {
when(
mock.delete(
'/collections/companies/documents/124',
),
).thenAnswer((realInvocation) => Future.value(documentMap));
expect(await document.delete(), equals(documentMap));
});
test('retrieve() calls ApiCall.get()', () async {
when(
mock.get(
'/collections/companies/documents/124',
),
).thenAnswer((realInvocation) => Future.value(documentMap));
expect(await document.retrieve(), equals(documentMap));
});
test('update() calls ApiCall.patch()', () async {
final partialDocument = {
"company_name": "Stark Industries",
"num_employees": 5500
};
when(
mock.patch('/collections/companies/documents/124',
bodyParameters: partialDocument),
).thenAnswer((realInvocation) => Future.value(partialDocument));
expect(await document.update(partialDocument), equals(partialDocument));
});
});
}