feat(shorebird_code_push_protocol): add platformStatuses to Release (#872)
This commit is contained in:
+4
-19
@@ -1,4 +1,5 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
|
||||
|
||||
part 'create_release_response.g.dart';
|
||||
|
||||
@@ -9,11 +10,7 @@ part 'create_release_response.g.dart';
|
||||
class CreateReleaseResponse {
|
||||
/// {@macro create_release_response}
|
||||
const CreateReleaseResponse({
|
||||
required this.id,
|
||||
required this.appId,
|
||||
required this.version,
|
||||
required this.flutterRevision,
|
||||
required this.displayName,
|
||||
required this.release,
|
||||
});
|
||||
|
||||
/// Converts a Map<String, dynamic> to a [CreateReleaseResponse]
|
||||
@@ -23,18 +20,6 @@ class CreateReleaseResponse {
|
||||
/// Converts a [CreateReleaseResponse] to a Map<String, dynamic>
|
||||
Map<String, dynamic> toJson() => _$CreateReleaseResponseToJson(this);
|
||||
|
||||
/// The ID of the release;
|
||||
final int id;
|
||||
|
||||
/// The ID of the app.
|
||||
final String appId;
|
||||
|
||||
/// The version of the release.
|
||||
final String version;
|
||||
|
||||
/// The Flutter revision used to create the release.
|
||||
final String flutterRevision;
|
||||
|
||||
/// The display name for the release
|
||||
final String? displayName;
|
||||
/// The newly-created release.
|
||||
final Release release;
|
||||
}
|
||||
|
||||
+3
-16
@@ -15,28 +15,15 @@ CreateReleaseResponse _$CreateReleaseResponseFromJson(
|
||||
json,
|
||||
($checkedConvert) {
|
||||
final val = CreateReleaseResponse(
|
||||
id: $checkedConvert('id', (v) => v as int),
|
||||
appId: $checkedConvert('app_id', (v) => v as String),
|
||||
version: $checkedConvert('version', (v) => v as String),
|
||||
flutterRevision:
|
||||
$checkedConvert('flutter_revision', (v) => v as String),
|
||||
displayName: $checkedConvert('display_name', (v) => v as String?),
|
||||
release: $checkedConvert(
|
||||
'release', (v) => Release.fromJson(v as Map<String, dynamic>)),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
fieldKeyMap: const {
|
||||
'appId': 'app_id',
|
||||
'flutterRevision': 'flutter_revision',
|
||||
'displayName': 'display_name'
|
||||
},
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$CreateReleaseResponseToJson(
|
||||
CreateReleaseResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'app_id': instance.appId,
|
||||
'version': instance.version,
|
||||
'flutter_revision': instance.flutterRevision,
|
||||
'display_name': instance.displayName,
|
||||
'release': instance.release.toJson(),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
|
||||
|
||||
part 'release.g.dart';
|
||||
|
||||
@@ -15,6 +16,7 @@ class Release {
|
||||
required this.version,
|
||||
required this.flutterRevision,
|
||||
required this.displayName,
|
||||
required this.platformStatuses,
|
||||
});
|
||||
|
||||
/// Converts a Map<String, dynamic> to a [Release]
|
||||
@@ -38,4 +40,7 @@ class Release {
|
||||
|
||||
/// The display name for the release
|
||||
final String? displayName;
|
||||
|
||||
/// The status of the release for each platform.
|
||||
final Map<ReleasePlatform, ReleaseStatus> platformStatuses;
|
||||
}
|
||||
|
||||
@@ -19,13 +19,20 @@ Release _$ReleaseFromJson(Map<String, dynamic> json) => $checkedCreate(
|
||||
flutterRevision:
|
||||
$checkedConvert('flutter_revision', (v) => v as String),
|
||||
displayName: $checkedConvert('display_name', (v) => v as String?),
|
||||
platformStatuses: $checkedConvert(
|
||||
'platform_statuses',
|
||||
(v) => (v as Map<String, dynamic>).map(
|
||||
(k, e) => MapEntry($enumDecode(_$ReleasePlatformEnumMap, k),
|
||||
$enumDecode(_$ReleaseStatusEnumMap, e)),
|
||||
)),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
fieldKeyMap: const {
|
||||
'appId': 'app_id',
|
||||
'flutterRevision': 'flutter_revision',
|
||||
'displayName': 'display_name'
|
||||
'displayName': 'display_name',
|
||||
'platformStatuses': 'platform_statuses'
|
||||
},
|
||||
);
|
||||
|
||||
@@ -35,4 +42,16 @@ Map<String, dynamic> _$ReleaseToJson(Release instance) => <String, dynamic>{
|
||||
'version': instance.version,
|
||||
'flutter_revision': instance.flutterRevision,
|
||||
'display_name': instance.displayName,
|
||||
'platform_statuses': instance.platformStatuses.map((k, e) =>
|
||||
MapEntry(_$ReleasePlatformEnumMap[k]!, _$ReleaseStatusEnumMap[e]!)),
|
||||
};
|
||||
|
||||
const _$ReleaseStatusEnumMap = {
|
||||
ReleaseStatus.draft: 'draft',
|
||||
ReleaseStatus.active: 'active',
|
||||
};
|
||||
|
||||
const _$ReleasePlatformEnumMap = {
|
||||
ReleasePlatform.android: 'android',
|
||||
ReleasePlatform.ios: 'ios',
|
||||
};
|
||||
|
||||
+8
-5
@@ -5,11 +5,14 @@ void main() {
|
||||
group(CreateReleaseResponse, () {
|
||||
test('can be (de)serialized', () {
|
||||
const response = CreateReleaseResponse(
|
||||
id: 0,
|
||||
appId: 'test-app-id',
|
||||
version: '1.0.0',
|
||||
displayName: 'v1.0.0',
|
||||
flutterRevision: 'flutter-revision',
|
||||
release: Release(
|
||||
id: 0,
|
||||
appId: 'test-app-id',
|
||||
version: '1.0.0',
|
||||
displayName: 'v1.0.0',
|
||||
flutterRevision: 'flutter-revision',
|
||||
platformStatuses: {},
|
||||
),
|
||||
);
|
||||
expect(
|
||||
CreateReleaseResponse.fromJson(response.toJson()).toJson(),
|
||||
|
||||
@@ -10,6 +10,7 @@ void main() {
|
||||
version: '1.0.0',
|
||||
flutterRevision: '83305b5088e6fe327fb3334a73ff190828d85713',
|
||||
displayName: 'v1.0.0',
|
||||
platformStatuses: {ReleasePlatform.android: ReleaseStatus.active},
|
||||
);
|
||||
expect(
|
||||
Release.fromJson(release.toJson()).toJson(),
|
||||
|
||||
Reference in New Issue
Block a user