Skip to content

Commit

Permalink
Add new error status
Browse files Browse the repository at this point in the history
  • Loading branch information
zbarbuto committed Sep 20, 2024
1 parent 191cf2b commit f469b49
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# manUp

## [9.2.0]

- Add a new `error` ManUpStatus that can be handled via the `ManUpService` `ChangeNotifier`

## [9.1.0]

- `ManUpService` now implements `ChangeNotifier` and the most recent status can be retrieved from the `status` getter
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ packages:
path: ".."
relative: true
source: path
version: "9.1.0"
version: "9.2.0"
matcher:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions lib/src/man_up_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract class ManUpService with ChangeNotifier {
this._handleManUpStatus(status);
return status;
} catch (e) {
this._handleManUpStatus(ManUpStatus.error);
rethrow;
} finally {
await _storeManUpFile();
Expand Down Expand Up @@ -143,6 +144,7 @@ abstract class ManUpService with ChangeNotifier {
case ManUpStatus.disabled:
return _manUpData.disabledMessage;
case ManUpStatus.latest:
case ManUpStatus.error:
return "";
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/src/man_up_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ part of manup;

/// Possible ManUp Status
enum ManUpStatus {
/// There was a problem fetching or validating the config file
error,

/// This is the latest version available (current version >= latestVersion)
latest,

Expand Down
4 changes: 4 additions & 0 deletions lib/src/ui/man_up_app_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ManUpAppDialog {
switch (status) {
case ManUpStatus.latest:
return Future.value(true);
case ManUpStatus.error:
// Default configuration is to not prevent the user from using the app
// in the event of connectivity issues etc.
return Future.value(true);
case ManUpStatus.supported:
final confirmed = await ManUpAppDialog.showAlertDialog(
context: context,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: manup
description: Mandatory update for Flutter Apps that prompts or forces app update by querying a hosted JSON file.
version: 9.1.0
version: 9.2.0
homepage: https://github.com/NextFaze/flutter_manup

environment:
Expand Down
29 changes: 29 additions & 0 deletions test/http_man_up_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ void main() {
storage: mockFileStorage);
var result = await service.validate();
expect(result, ManUpStatus.unsupported);
expect(service.status, ManUpStatus.unsupported);
});

test('the minimum version version', () async {
var packageInfo = MockPackageInfo("2.1.0");
var client;
Expand Down Expand Up @@ -225,7 +227,9 @@ void main() {

var result = await service.validate();
expect(result, ManUpStatus.supported);
expect(service.status, ManUpStatus.supported);
});

test('some supported version', () async {
var packageInfo = MockPackageInfo("2.3.3");
var client;
Expand All @@ -248,7 +252,9 @@ void main() {

var result = await service.validate();
expect(result, ManUpStatus.supported);
expect(service.status, ManUpStatus.supported);
});

test('the latest version', () async {
var packageInfo = MockPackageInfo("2.4.1");
var response = http.Response('''
Expand All @@ -269,7 +275,9 @@ void main() {
storage: mockFileStorage);
var result = await service.validate();
expect(result, ManUpStatus.latest);
expect(service.status, ManUpStatus.latest);
});

test('allow greater than latest version', () async {
var packageInfo = MockPackageInfo("3.4.1");
var response = http.Response('''
Expand All @@ -290,7 +298,9 @@ void main() {
storage: mockFileStorage);
var result = await service.validate();
expect(result, ManUpStatus.latest);
expect(service.status, ManUpStatus.latest);
});

test('marked as disabled', () async {
var packageInfo = MockPackageInfo("2.4.1");
var response = http.Response('''
Expand All @@ -312,7 +322,26 @@ void main() {
storage: mockFileStorage);
var result = await service.validate();
expect(result, ManUpStatus.disabled);
expect(service.status, ManUpStatus.disabled);
});

test('error status', () async {
var packageInfo = MockPackageInfo("1.1.0");
final error = Error();
var client;
client = MockClient((r) => Future.error(error));
var service = HttpManUpService('https://example.com/manup.json',
packageInfoProvider: packageInfo,
http: client,
os: osGetter(),
storage: mockFileStorage);
var result = await service.validate().catchError((error) {
return ManUpStatus.error;
});
expect(result, ManUpStatus.error);
expect(service.status, ManUpStatus.error);
});

test('throws an exception if the lookup failed', () async {
var packageInfo = MockPackageInfo("2.4.1");
var client = MockClient((r) => Future.error(Exception("text error")));
Expand Down

0 comments on commit f469b49

Please sign in to comment.