@@ -14,6 +14,7 @@ import 'package:subctrl/application/notifications/get_pending_notifications_use_
1414import 'package:subctrl/application/notifications/schedule_notifications_use_case.dart' ;
1515import 'package:subctrl/application/subscriptions/add_subscription_use_case.dart' ;
1616import 'package:subctrl/application/subscriptions/delete_subscription_use_case.dart' ;
17+ import 'package:subctrl/application/subscriptions/refresh_overdue_next_payments_use_case.dart' ;
1718import 'package:subctrl/application/subscriptions/update_subscription_use_case.dart' ;
1819import 'package:subctrl/application/subscriptions/watch_subscriptions_use_case.dart' ;
1920import 'package:subctrl/application/tags/watch_tags_use_case.dart' ;
@@ -38,6 +39,9 @@ class _MockUpdateSubscriptionUseCase extends Mock
3839class _MockDeleteSubscriptionUseCase extends Mock
3940 implements DeleteSubscriptionUseCase {}
4041
42+ class _MockRefreshOverdueNextPaymentsUseCase extends Mock
43+ implements RefreshOverdueNextPaymentsUseCase {}
44+
4145class _MockWatchCurrenciesUseCase extends Mock
4246 implements WatchCurrenciesUseCase {}
4347
@@ -85,6 +89,7 @@ void main() {
8589 late _MockAddSubscriptionUseCase addSubscriptionUseCase;
8690 late _MockUpdateSubscriptionUseCase updateSubscriptionUseCase;
8791 late _MockDeleteSubscriptionUseCase deleteSubscriptionUseCase;
92+ late _MockRefreshOverdueNextPaymentsUseCase refreshOverdueNextPaymentsUseCase;
8893 late _MockWatchCurrenciesUseCase watchCurrenciesUseCase;
8994 late _MockGetCurrenciesUseCase getCurrenciesUseCase;
9095 late _MockWatchCurrencyRatesUseCase watchCurrencyRatesUseCase;
@@ -107,6 +112,8 @@ void main() {
107112 addSubscriptionUseCase = _MockAddSubscriptionUseCase ();
108113 updateSubscriptionUseCase = _MockUpdateSubscriptionUseCase ();
109114 deleteSubscriptionUseCase = _MockDeleteSubscriptionUseCase ();
115+ refreshOverdueNextPaymentsUseCase =
116+ _MockRefreshOverdueNextPaymentsUseCase ();
110117 watchCurrenciesUseCase = _MockWatchCurrenciesUseCase ();
111118 getCurrenciesUseCase = _MockGetCurrenciesUseCase ();
112119 watchCurrencyRatesUseCase = _MockWatchCurrencyRatesUseCase ();
@@ -161,12 +168,16 @@ void main() {
161168 when (() => addSubscriptionUseCase (any ())).thenAnswer ((_) async {});
162169 when (() => updateSubscriptionUseCase (any ())).thenAnswer ((_) async {});
163170 when (() => deleteSubscriptionUseCase (any ())).thenAnswer ((_) async {});
171+ when (
172+ () => refreshOverdueNextPaymentsUseCase (any ()),
173+ ).thenAnswer ((_) async {});
164174
165175 viewModel = SubscriptionsViewModel (
166176 watchSubscriptionsUseCase: watchSubscriptionsUseCase,
167177 addSubscriptionUseCase: addSubscriptionUseCase,
168178 updateSubscriptionUseCase: updateSubscriptionUseCase,
169179 deleteSubscriptionUseCase: deleteSubscriptionUseCase,
180+ refreshOverdueNextPaymentsUseCase: refreshOverdueNextPaymentsUseCase,
170181 watchCurrenciesUseCase: watchCurrenciesUseCase,
171182 getCurrenciesUseCase: getCurrenciesUseCase,
172183 watchCurrencyRatesUseCase: watchCurrencyRatesUseCase,
@@ -247,6 +258,28 @@ void main() {
247258 expect (viewModel.isLoadingCurrencies, isFalse);
248259 });
249260
261+ test ('triggers overdue next payment refresh on updates' , () async {
262+ final subscription = Subscription (
263+ id: 1 ,
264+ name: 'Overdue' ,
265+ amount: 5 ,
266+ currency: 'usd' ,
267+ cycle: BillingCycle .monthly,
268+ purchaseDate: DateTime (2024 , 1 , 1 ),
269+ );
270+ subscriptionsController.add ([subscription]);
271+ tagsController.add (const []);
272+ currenciesController.add (const []);
273+ ratesController.add (const []);
274+ await Future <void >.delayed (Duration .zero);
275+
276+ verify (
277+ () => refreshOverdueNextPaymentsUseCase (
278+ any (that: predicate <List <Subscription >>((subs) => subs.length == 1 )),
279+ ),
280+ ).called (1 );
281+ });
282+
250283 test ('updateBaseCurrencyCode re-listens to currency rates stream' , () async {
251284 viewModel.updateBaseCurrencyCode ('eur' );
252285 await Future <void >.delayed (Duration .zero);
@@ -322,6 +355,7 @@ void main() {
322355 addSubscriptionUseCase: addSubscriptionUseCase,
323356 updateSubscriptionUseCase: updateSubscriptionUseCase,
324357 deleteSubscriptionUseCase: deleteSubscriptionUseCase,
358+ refreshOverdueNextPaymentsUseCase: refreshOverdueNextPaymentsUseCase,
325359 watchCurrenciesUseCase: watchCurrenciesUseCase,
326360 getCurrenciesUseCase: getCurrenciesUseCase,
327361 watchCurrencyRatesUseCase: watchCurrencyRatesUseCase,
0 commit comments