-
Notifications
You must be signed in to change notification settings - Fork 4
/
detail_local_service_test.dart
77 lines (63 loc) · 2.16 KB
/
detail_local_service_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'package:fpdart/fpdart.dart';
import 'package:mocktail/mocktail.dart';
import 'package:now_in_dart_flutter/features/detail/core/data/detail_dto.dart';
import 'package:test/test.dart';
import '../../../../helpers/mocks.dart';
void main() {
final isar = MockIsar();
final isarDb = MockIsarDatabase();
final isarCollection = MockIsarCollection<DetailDTO>();
final detailLocalService = MockDetailLocalService(isarDb: isarDb);
group(
'DetailLocalService |',
() {
const fakeDetailDTO = DetailDTO(id: 1, html: 'html');
setUpAll(() => when(() => isarDb.instance).thenReturn(isar));
test(
'should instantiate IsarDatabase() when not injected',
() => expect(MockDetailLocalService(), isNotNull),
);
test(
'The method `upsertDetail` should either update or insert the passed '
'DetailDTO',
() async {
when(
() => isar.writeTxn<Unit>(
any(that: isA<Function>()),
silent: any(named: 'silent', that: isA<bool>()),
),
).thenAnswer((_) async => unit);
final result =
await detailLocalService.upsertDetail(fakeDetailDTO).run();
expect(result, isA<Unit>());
},
);
group(
'The method `getDetail`',
() {
setUpAll(
() => when(() => isar.detailDTOs).thenReturn(isarCollection),
);
test(
'should return DetailDTO object for the passed id',
() async {
when(() => isarCollection.get(any(that: isA<int>())))
.thenAnswer((_) async => fakeDetailDTO);
final result = await detailLocalService.getDetail(1).run();
expect(result, fakeDetailDTO);
},
);
test(
'should return null if invalid id is passed',
() async {
when(() => isarCollection.get(any(that: isA<int>())))
.thenAnswer((_) async => null);
final result = await detailLocalService.getDetail(1).run();
expect(result, isNull);
},
);
},
);
},
);
}