Skip to content

Commit

Permalink
fix(updates_model): handle error on refresh (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-loose authored Oct 6, 2023
1 parent 28e49cc commit d4b9480
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
8 changes: 6 additions & 2 deletions lib/src/snapd/updates_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ class UpdatesModel extends ChangeNotifier {
_state = const AsyncValue.loading();
notifyListeners();
_state = await AsyncValue.guard(() async {
_refreshableSnaps = await snapd.find(filter: SnapFindFilter.refresh);
notifyListeners();
try {
_refreshableSnaps = await snapd.find(filter: SnapFindFilter.refresh);
notifyListeners();
} on SnapdException catch (e) {
_handleError(e);
}
});
}

Expand Down
55 changes: 39 additions & 16 deletions test/updates_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,45 @@ void main() {
verify(service.refreshMany(const ['firefox'])).called(1);
});

test('error stream', () async {
final service =
createMockSnapdService(refreshableSnaps: [const Snap(name: 'firefox')]);
final model = UpdatesModel(service);
when(service.refreshMany(any)).thenThrow(
SnapdException(message: 'error message', kind: 'error kind'));
group('error stream', () {
test('refresh', () async {
final service = createMockSnapdService();
final model = UpdatesModel(service);
when(service.find(filter: SnapFindFilter.refresh))
.thenThrow(SnapdException(
message: 'error while checking for updates',
kind: 'error kind',
));

model.errorStream.listen(
expectAsync1<void, SnapdException>(
(e) {
expect(e.kind, equals('error kind'));
expect(e.message, equals('error message'));
},
),
);
await model.refresh();
await model.updateAll();
model.errorStream.listen(
expectAsync1<void, SnapdException>(
(e) {
expect(e.kind, equals('error kind'));
expect(e.message, equals('error while checking for updates'));
},
),
);
await model.refresh();
});
test('update all', () async {
final service = createMockSnapdService(
refreshableSnaps: [const Snap(name: 'firefox')]);
final model = UpdatesModel(service);
when(service.refreshMany(any)).thenThrow(SnapdException(
message: 'error while updating snaps',
kind: 'error kind',
));

model.errorStream.listen(
expectAsync1<void, SnapdException>(
(e) {
expect(e.kind, equals('error kind'));
expect(e.message, equals('error while updating snaps'));
},
),
);
await model.refresh();
await model.updateAll();
});
});
}

0 comments on commit d4b9480

Please sign in to comment.