fix(shorebird_cli): ShorebirdYaml (de)serialization supports auto_update (#1129)

This commit is contained in:
Felix Angelov
2023-08-18 11:24:08 -05:00
committed by GitHub
parent 0b1dfd4a72
commit 0c867932cd
3 changed files with 45 additions and 3 deletions
@@ -12,7 +12,12 @@ part 'shorebird_yaml.g.dart';
)
class ShorebirdYaml {
/// {@macro shorebird_yaml}
const ShorebirdYaml({required this.appId, this.flavors, this.baseUrl});
const ShorebirdYaml({
required this.appId,
this.flavors,
this.baseUrl,
this.autoUpdate,
});
factory ShorebirdYaml.fromJson(Map<dynamic, dynamic> json) =>
_$ShorebirdYamlFromJson(json);
@@ -38,6 +43,9 @@ class ShorebirdYaml {
/// The base url used to check for updates.
final String? baseUrl;
/// Whether or not to automatically update the app.
final bool? autoUpdate;
}
extension AppIdExtension on ShorebirdYaml {
@@ -14,7 +14,7 @@ ShorebirdYaml _$ShorebirdYamlFromJson(Map json) => $checkedCreate(
($checkedConvert) {
$checkKeys(
json,
allowedKeys: const ['app_id', 'flavors', 'base_url'],
allowedKeys: const ['app_id', 'flavors', 'base_url', 'auto_update'],
);
final val = ShorebirdYaml(
appId: $checkedConvert('app_id', (v) => v as String),
@@ -24,8 +24,13 @@ ShorebirdYaml _$ShorebirdYamlFromJson(Map json) => $checkedCreate(
(k, e) => MapEntry(k as String, e as String),
)),
baseUrl: $checkedConvert('base_url', (v) => v as String?),
autoUpdate: $checkedConvert('auto_update', (v) => v as bool?),
);
return val;
},
fieldKeyMap: const {'appId': 'app_id', 'baseUrl': 'base_url'},
fieldKeyMap: const {
'appId': 'app_id',
'baseUrl': 'base_url',
'autoUpdate': 'auto_update'
},
);
@@ -37,5 +37,34 @@ base_url: https://example.com
});
expect(shorebirdYaml.baseUrl, 'https://example.com');
});
test('can be deserialized without auto-update', () {
const yaml = '''
app_id: test_app_id
''';
final shorebirdYaml = checkedYamlDecode(
yaml,
(m) => ShorebirdYaml.fromJson(m!),
);
expect(shorebirdYaml.appId, 'test_app_id');
expect(shorebirdYaml.flavors, isNull);
expect(shorebirdYaml.baseUrl, isNull);
expect(shorebirdYaml.autoUpdate, isNull);
});
test('can be deserialized with auto-update', () {
const yaml = '''
app_id: test_app_id
auto_update: true
''';
final shorebirdYaml = checkedYamlDecode(
yaml,
(m) => ShorebirdYaml.fromJson(m!),
);
expect(shorebirdYaml.appId, 'test_app_id');
expect(shorebirdYaml.flavors, isNull);
expect(shorebirdYaml.baseUrl, isNull);
expect(shorebirdYaml.autoUpdate, isTrue);
});
});
}