Skip to content

Commit 096aa73

Browse files
committed
preserve lastModifiedDate on share
1 parent 5398f02 commit 096aa73

File tree

7 files changed

+126
-91
lines changed

7 files changed

+126
-91
lines changed

lib/manager/share_in_manager.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import 'package:dartx/dartx.dart';
12
import 'package:injectable/injectable.dart';
23

4+
import '../model/feed.dart';
35
import '../model/share_dto.dart';
46
import '../service/app_service.dart';
57
import 'feeds_manager.dart';
@@ -41,5 +43,9 @@ class ShareInManager {
4143
for (final (index, feed) in _feedsManager.feeds.indexed) {
4244
feed.state = syncDto.feedStateList[index];
4345
}
46+
47+
// touch the last modified feed to preserve lastModifiedDate
48+
final latestBookKey = syncDto.feedStateList.maxBy((s) => s.dateModified ?? DateTime(1970))?.bookKey;
49+
_feedsManager.feeds.firstWhere((Feed f) => f.book.key == latestBookKey).touch();
4450
}
4551
}

lib/model/book.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import 'package:flutter/foundation.dart';
22

33
// an individual book e.g. Matthew
4+
// marking as final breaks ShareInManagerTest
45
@immutable
5-
final class Book {
6+
class Book {
67
const Book(this.key, this.name, this.chapterCount);
78

89
final String key; // e.g. mar

lib/model/feed.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ class Feed with ChangeNotifier {
4141
_state._dateModified = DateTime.now();
4242
notifyListeners();
4343
}
44+
45+
void touch() => notifyListeners();
4446
}

test/unit/manager/feeds_advance_manager_test.mocks.dart

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import 'dart:ui' as _i7;
77

88
import 'package:bible_feed/manager/feed_advance_manager.dart' as _i8;
99
import 'package:bible_feed/manager/feeds_manager.dart' as _i9;
10-
import 'package:bible_feed/model/book.dart' as _i4;
11-
import 'package:bible_feed/model/feed.dart' as _i2;
12-
import 'package:bible_feed/model/reading_list.dart' as _i6;
13-
import 'package:bible_feed/service/date_time_service.dart' as _i3;
10+
import 'package:bible_feed/model/book.dart' as _i2;
11+
import 'package:bible_feed/model/feed.dart' as _i3;
12+
import 'package:bible_feed/model/reading_list.dart' as _i5;
13+
import 'package:bible_feed/service/date_time_service.dart' as _i4;
1414
import 'package:mockito/mockito.dart' as _i1;
15-
import 'package:mockito/src/dummies.dart' as _i5;
15+
import 'package:mockito/src/dummies.dart' as _i6;
1616

1717
// ignore_for_file: type=lint
1818
// ignore_for_file: avoid_redundant_argument_values
@@ -33,15 +33,20 @@ class _FakeDateTime_0 extends _i1.SmartFake implements DateTime {
3333
: super(parent, parentInvocation);
3434
}
3535

36-
class _FakeFeedState_1 extends _i1.SmartFake implements _i2.FeedState {
37-
_FakeFeedState_1(Object parent, Invocation parentInvocation)
36+
class _FakeBook_1 extends _i1.SmartFake implements _i2.Book {
37+
_FakeBook_1(Object parent, Invocation parentInvocation)
38+
: super(parent, parentInvocation);
39+
}
40+
41+
class _FakeFeedState_2 extends _i1.SmartFake implements _i3.FeedState {
42+
_FakeFeedState_2(Object parent, Invocation parentInvocation)
3843
: super(parent, parentInvocation);
3944
}
4045

4146
/// A class which mocks [DateTimeService].
4247
///
4348
/// See the documentation for Mockito's code generation for more information.
44-
class MockDateTimeService extends _i1.Mock implements _i3.DateTimeService {
49+
class MockDateTimeService extends _i1.Mock implements _i4.DateTimeService {
4550
@override
4651
DateTime get now =>
4752
(super.noSuchMethod(
@@ -58,21 +63,18 @@ class MockDateTimeService extends _i1.Mock implements _i3.DateTimeService {
5863
/// A class which mocks [Feed].
5964
///
6065
/// See the documentation for Mockito's code generation for more information.
61-
class MockFeed extends _i1.Mock implements _i2.Feed {
66+
class MockFeed extends _i1.Mock implements _i3.Feed {
6267
@override
63-
_i4.Book get book =>
68+
_i2.Book get book =>
6469
(super.noSuchMethod(
6570
Invocation.getter(#book),
66-
returnValue: _i5.dummyValue<_i4.Book>(
67-
this,
68-
Invocation.getter(#book),
69-
),
70-
returnValueForMissingStub: _i5.dummyValue<_i4.Book>(
71+
returnValue: _FakeBook_1(this, Invocation.getter(#book)),
72+
returnValueForMissingStub: _FakeBook_1(
7173
this,
7274
Invocation.getter(#book),
7375
),
7476
)
75-
as _i4.Book);
77+
as _i2.Book);
7678

7779
@override
7880
int get bookIndex =>
@@ -102,34 +104,34 @@ class MockFeed extends _i1.Mock implements _i2.Feed {
102104
as double);
103105

104106
@override
105-
_i6.ReadingList get readingList =>
107+
_i5.ReadingList get readingList =>
106108
(super.noSuchMethod(
107109
Invocation.getter(#readingList),
108-
returnValue: _i5.dummyValue<_i6.ReadingList>(
110+
returnValue: _i6.dummyValue<_i5.ReadingList>(
109111
this,
110112
Invocation.getter(#readingList),
111113
),
112-
returnValueForMissingStub: _i5.dummyValue<_i6.ReadingList>(
114+
returnValueForMissingStub: _i6.dummyValue<_i5.ReadingList>(
113115
this,
114116
Invocation.getter(#readingList),
115117
),
116118
)
117-
as _i6.ReadingList);
119+
as _i5.ReadingList);
118120

119121
@override
120-
_i2.FeedState get state =>
122+
_i3.FeedState get state =>
121123
(super.noSuchMethod(
122124
Invocation.getter(#state),
123-
returnValue: _FakeFeedState_1(this, Invocation.getter(#state)),
124-
returnValueForMissingStub: _FakeFeedState_1(
125+
returnValue: _FakeFeedState_2(this, Invocation.getter(#state)),
126+
returnValueForMissingStub: _FakeFeedState_2(
125127
this,
126128
Invocation.getter(#state),
127129
),
128130
)
129-
as _i2.FeedState);
131+
as _i3.FeedState);
130132

131133
@override
132-
set state(_i2.FeedState? value) => super.noSuchMethod(
134+
set state(_i3.FeedState? value) => super.noSuchMethod(
133135
Invocation.setter(#state, value),
134136
returnValueForMissingStub: null,
135137
);
@@ -156,6 +158,12 @@ class MockFeed extends _i1.Mock implements _i2.Feed {
156158
returnValueForMissingStub: null,
157159
);
158160

161+
@override
162+
void touch() => super.noSuchMethod(
163+
Invocation.method(#touch, []),
164+
returnValueForMissingStub: null,
165+
);
166+
159167
@override
160168
void addListener(_i7.VoidCallback? listener) => super.noSuchMethod(
161169
Invocation.method(#addListener, [listener]),
@@ -187,7 +195,7 @@ class MockFeed extends _i1.Mock implements _i2.Feed {
187195
class MockFeedAdvanceManager extends _i1.Mock
188196
implements _i8.FeedAdvanceManager {
189197
@override
190-
void advance(_i2.Feed? feed) => super.noSuchMethod(
198+
void advance(_i3.Feed? feed) => super.noSuchMethod(
191199
Invocation.method(#advance, [feed]),
192200
returnValueForMissingStub: null,
193201
);
@@ -216,13 +224,13 @@ class MockFeedsManager extends _i1.Mock implements _i9.FeedsManager {
216224
as int);
217225

218226
@override
219-
List<_i2.Feed> get feeds =>
227+
List<_i3.Feed> get feeds =>
220228
(super.noSuchMethod(
221229
Invocation.getter(#feeds),
222-
returnValue: <_i2.Feed>[],
223-
returnValueForMissingStub: <_i2.Feed>[],
230+
returnValue: <_i3.Feed>[],
231+
returnValueForMissingStub: <_i3.Feed>[],
224232
)
225-
as List<_i2.Feed>);
233+
as List<_i3.Feed>);
226234

227235
@override
228236
bool get hasListeners =>

test/unit/manager/share_in_manager_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void main() {
4646
final json = syncDto.toJson();
4747
final mockFeed1 = MockFeed();
4848
final mockFeed2 = MockFeed();
49+
when(mockFeed1.book).thenReturn(b0);
50+
when(mockFeed2.book).thenReturn(b1);
4951
when(mockFeedsManager.feeds).thenReturn([mockFeed1, mockFeed2]);
5052
when(mockAppService.buildNumber).thenReturn('correct_build');
5153

test/unit/manager/share_in_manager_test.mocks.dart

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import 'dart:ui' as _i7;
77

88
import 'package:bible_feed/manager/feeds_manager.dart' as _i8;
9-
import 'package:bible_feed/model/book.dart' as _i5;
10-
import 'package:bible_feed/model/feed.dart' as _i2;
9+
import 'package:bible_feed/model/book.dart' as _i2;
10+
import 'package:bible_feed/model/feed.dart' as _i3;
1111
import 'package:bible_feed/model/reading_list.dart' as _i6;
12-
import 'package:bible_feed/service/app_service.dart' as _i3;
12+
import 'package:bible_feed/service/app_service.dart' as _i4;
1313
import 'package:mockito/mockito.dart' as _i1;
14-
import 'package:mockito/src/dummies.dart' as _i4;
14+
import 'package:mockito/src/dummies.dart' as _i5;
1515

1616
// ignore_for_file: type=lint
1717
// ignore_for_file: avoid_redundant_argument_values
@@ -27,24 +27,29 @@ import 'package:mockito/src/dummies.dart' as _i4;
2727
// ignore_for_file: camel_case_types
2828
// ignore_for_file: subtype_of_sealed_class
2929

30-
class _FakeFeedState_0 extends _i1.SmartFake implements _i2.FeedState {
31-
_FakeFeedState_0(Object parent, Invocation parentInvocation)
30+
class _FakeBook_0 extends _i1.SmartFake implements _i2.Book {
31+
_FakeBook_0(Object parent, Invocation parentInvocation)
32+
: super(parent, parentInvocation);
33+
}
34+
35+
class _FakeFeedState_1 extends _i1.SmartFake implements _i3.FeedState {
36+
_FakeFeedState_1(Object parent, Invocation parentInvocation)
3237
: super(parent, parentInvocation);
3338
}
3439

3540
/// A class which mocks [AppService].
3641
///
3742
/// See the documentation for Mockito's code generation for more information.
38-
class MockAppService extends _i1.Mock implements _i3.AppService {
43+
class MockAppService extends _i1.Mock implements _i4.AppService {
3944
@override
4045
String get buildNumber =>
4146
(super.noSuchMethod(
4247
Invocation.getter(#buildNumber),
43-
returnValue: _i4.dummyValue<String>(
48+
returnValue: _i5.dummyValue<String>(
4449
this,
4550
Invocation.getter(#buildNumber),
4651
),
47-
returnValueForMissingStub: _i4.dummyValue<String>(
52+
returnValueForMissingStub: _i5.dummyValue<String>(
4853
this,
4954
Invocation.getter(#buildNumber),
5055
),
@@ -55,11 +60,11 @@ class MockAppService extends _i1.Mock implements _i3.AppService {
5560
String get version =>
5661
(super.noSuchMethod(
5762
Invocation.getter(#version),
58-
returnValue: _i4.dummyValue<String>(
63+
returnValue: _i5.dummyValue<String>(
5964
this,
6065
Invocation.getter(#version),
6166
),
62-
returnValueForMissingStub: _i4.dummyValue<String>(
67+
returnValueForMissingStub: _i5.dummyValue<String>(
6368
this,
6469
Invocation.getter(#version),
6570
),
@@ -70,21 +75,18 @@ class MockAppService extends _i1.Mock implements _i3.AppService {
7075
/// A class which mocks [Feed].
7176
///
7277
/// See the documentation for Mockito's code generation for more information.
73-
class MockFeed extends _i1.Mock implements _i2.Feed {
78+
class MockFeed extends _i1.Mock implements _i3.Feed {
7479
@override
75-
_i5.Book get book =>
80+
_i2.Book get book =>
7681
(super.noSuchMethod(
7782
Invocation.getter(#book),
78-
returnValue: _i4.dummyValue<_i5.Book>(
79-
this,
80-
Invocation.getter(#book),
81-
),
82-
returnValueForMissingStub: _i4.dummyValue<_i5.Book>(
83+
returnValue: _FakeBook_0(this, Invocation.getter(#book)),
84+
returnValueForMissingStub: _FakeBook_0(
8385
this,
8486
Invocation.getter(#book),
8587
),
8688
)
87-
as _i5.Book);
89+
as _i2.Book);
8890

8991
@override
9092
int get bookIndex =>
@@ -117,31 +119,31 @@ class MockFeed extends _i1.Mock implements _i2.Feed {
117119
_i6.ReadingList get readingList =>
118120
(super.noSuchMethod(
119121
Invocation.getter(#readingList),
120-
returnValue: _i4.dummyValue<_i6.ReadingList>(
122+
returnValue: _i5.dummyValue<_i6.ReadingList>(
121123
this,
122124
Invocation.getter(#readingList),
123125
),
124-
returnValueForMissingStub: _i4.dummyValue<_i6.ReadingList>(
126+
returnValueForMissingStub: _i5.dummyValue<_i6.ReadingList>(
125127
this,
126128
Invocation.getter(#readingList),
127129
),
128130
)
129131
as _i6.ReadingList);
130132

131133
@override
132-
_i2.FeedState get state =>
134+
_i3.FeedState get state =>
133135
(super.noSuchMethod(
134136
Invocation.getter(#state),
135-
returnValue: _FakeFeedState_0(this, Invocation.getter(#state)),
136-
returnValueForMissingStub: _FakeFeedState_0(
137+
returnValue: _FakeFeedState_1(this, Invocation.getter(#state)),
138+
returnValueForMissingStub: _FakeFeedState_1(
137139
this,
138140
Invocation.getter(#state),
139141
),
140142
)
141-
as _i2.FeedState);
143+
as _i3.FeedState);
142144

143145
@override
144-
set state(_i2.FeedState? value) => super.noSuchMethod(
146+
set state(_i3.FeedState? value) => super.noSuchMethod(
145147
Invocation.setter(#state, value),
146148
returnValueForMissingStub: null,
147149
);
@@ -168,6 +170,12 @@ class MockFeed extends _i1.Mock implements _i2.Feed {
168170
returnValueForMissingStub: null,
169171
);
170172

173+
@override
174+
void touch() => super.noSuchMethod(
175+
Invocation.method(#touch, []),
176+
returnValueForMissingStub: null,
177+
);
178+
171179
@override
172180
void addListener(_i7.VoidCallback? listener) => super.noSuchMethod(
173181
Invocation.method(#addListener, [listener]),
@@ -216,13 +224,13 @@ class MockFeedsManager extends _i1.Mock implements _i8.FeedsManager {
216224
as int);
217225

218226
@override
219-
List<_i2.Feed> get feeds =>
227+
List<_i3.Feed> get feeds =>
220228
(super.noSuchMethod(
221229
Invocation.getter(#feeds),
222-
returnValue: <_i2.Feed>[],
223-
returnValueForMissingStub: <_i2.Feed>[],
230+
returnValue: <_i3.Feed>[],
231+
returnValueForMissingStub: <_i3.Feed>[],
224232
)
225-
as List<_i2.Feed>);
233+
as List<_i3.Feed>);
226234

227235
@override
228236
bool get hasListeners =>

0 commit comments

Comments
 (0)