feat(code_push_protocol): add GetAppsResponse with createdAt and updatedAt (#1312)
This commit is contained in:
@@ -62,7 +62,12 @@ void main() {
|
||||
),
|
||||
);
|
||||
const appId = 'test-app-id';
|
||||
const app = AppMetadata(appId: appId, displayName: 'Test App');
|
||||
final app = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: 'Test App',
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const channelName = 'my-channel';
|
||||
const channel = Channel(id: 0, appId: appId, name: channelName);
|
||||
const patchId = 1;
|
||||
|
||||
@@ -806,7 +806,12 @@ flavors:
|
||||
|
||||
when(() => codePushClientWrapper.getApp(appId: any(named: 'appId')))
|
||||
.thenAnswer(
|
||||
(_) async => const AppMetadata(appId: appId, displayName: appName),
|
||||
(_) async => AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
),
|
||||
);
|
||||
when(
|
||||
() =>
|
||||
|
||||
@@ -41,7 +41,12 @@ void main() {
|
||||
const releasePlatform = ReleasePlatform.android;
|
||||
const channelName = 'stable';
|
||||
const appDisplayName = 'Test App';
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const androidPackageName = 'com.example.my_flutter_module';
|
||||
const releaseArtifact = ReleaseArtifact(
|
||||
id: 0,
|
||||
|
||||
@@ -44,7 +44,12 @@ void main() {
|
||||
const releasePlatform = ReleasePlatform.android;
|
||||
const channelName = 'stable';
|
||||
const appDisplayName = 'Test App';
|
||||
const app = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const releaseArtifact = ReleaseArtifact(
|
||||
id: 0,
|
||||
releaseId: 0,
|
||||
@@ -284,7 +289,7 @@ flutter:
|
||||
() => codePushClientWrapper.getApp(
|
||||
appId: any(named: 'appId'),
|
||||
),
|
||||
).thenAnswer((_) async => app);
|
||||
).thenAnswer((_) async => appMetadata);
|
||||
when(
|
||||
() => codePushClientWrapper.getRelease(
|
||||
appId: any(named: 'appId'),
|
||||
|
||||
@@ -90,7 +90,12 @@ flutter:
|
||||
assets:
|
||||
- shorebird.yaml''';
|
||||
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const ipaArtifact = ReleaseArtifact(
|
||||
id: 0,
|
||||
releaseId: 0,
|
||||
|
||||
+6
-1
@@ -44,7 +44,12 @@ environment:
|
||||
flutter:
|
||||
assets:
|
||||
- shorebird.yaml''';
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const arch = 'aarch64';
|
||||
const xcframeworkArtifact = ReleaseArtifact(
|
||||
id: 0,
|
||||
|
||||
@@ -30,7 +30,12 @@ void main() {
|
||||
const appId = 'test-app-id';
|
||||
const shorebirdYaml = ShorebirdYaml(appId: appId);
|
||||
const androidPackageName = 'com.example.my_flutter_module';
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const flutterRevision = '83305b5088e6fe327fb3334a73ff190828d85713';
|
||||
const versionName = '1.2.3';
|
||||
const versionCode = '1';
|
||||
|
||||
@@ -38,7 +38,12 @@ void main() {
|
||||
const appDisplayName = 'Test App';
|
||||
const arch = 'aarch64';
|
||||
const releasePlatform = ReleasePlatform.android;
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const release = Release(
|
||||
id: 0,
|
||||
appId: appId,
|
||||
|
||||
@@ -36,7 +36,12 @@ void main() {
|
||||
const arch = 'armv7';
|
||||
const releasePlatform = ReleasePlatform.ios;
|
||||
const ipaPath = 'build/ios/ipa/Runner.ipa';
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const release = Release(
|
||||
id: 0,
|
||||
appId: appId,
|
||||
|
||||
+6
-1
@@ -33,7 +33,12 @@ void main() {
|
||||
const version = '$versionName+$versionCode';
|
||||
const appDisplayName = 'Test App';
|
||||
const releasePlatform = ReleasePlatform.ios;
|
||||
const appMetadata = AppMetadata(appId: appId, displayName: appDisplayName);
|
||||
final appMetadata = AppMetadata(
|
||||
appId: appId,
|
||||
displayName: appDisplayName,
|
||||
createdAt: DateTime(2023),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
const release = Release(
|
||||
id: 0,
|
||||
appId: appId,
|
||||
|
||||
@@ -402,10 +402,10 @@ class CodePushClient {
|
||||
throw _parseErrorResponse(response.statusCode, response.body);
|
||||
}
|
||||
|
||||
final apps = json.decode(response.body) as List;
|
||||
return apps
|
||||
.map((app) => AppMetadata.fromJson(app as Map<String, dynamic>))
|
||||
.toList();
|
||||
final decoded = GetAppsResponse.fromJson(
|
||||
json.decode(response.body) as Map<String, dynamic>,
|
||||
);
|
||||
return decoded.apps;
|
||||
}
|
||||
|
||||
/// List all channels for the provided [appId].
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// Generated code. Do not modify.
|
||||
const packageVersion = '0.5.0+1';
|
||||
const packageVersion = '0.6.0+1';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: shorebird_code_push_client
|
||||
description: Library which allows Dart applications to interact with the ShoreBird CodePush API
|
||||
version: 0.5.0+1
|
||||
version: 0.6.0+1
|
||||
repository: https://github.com/shorebirdtech/shorebird
|
||||
|
||||
publish_to: none
|
||||
|
||||
@@ -1580,9 +1580,12 @@ void main() {
|
||||
});
|
||||
|
||||
test('completes when request succeeds (empty)', () async {
|
||||
final expected = <AppMetadata>[];
|
||||
when(() => httpClient.send(any())).thenAnswer(
|
||||
(_) async => http.StreamedResponse(
|
||||
Stream.value(utf8.encode(json.encode([]))),
|
||||
Stream.value(
|
||||
utf8.encode(json.encode(GetAppsResponse(apps: expected))),
|
||||
),
|
||||
HttpStatus.ok,
|
||||
),
|
||||
);
|
||||
@@ -1593,13 +1596,25 @@ void main() {
|
||||
|
||||
test('completes when request succeeds (populated)', () async {
|
||||
final expected = [
|
||||
AppMetadata(appId: '1', displayName: 'Shorebird Example'),
|
||||
AppMetadata(appId: '2', displayName: 'Shorebird Clock'),
|
||||
AppMetadata(
|
||||
appId: '1',
|
||||
displayName: 'Shorebird Example',
|
||||
createdAt: DateTime(2022),
|
||||
updatedAt: DateTime(2023),
|
||||
),
|
||||
AppMetadata(
|
||||
appId: '2',
|
||||
displayName: 'Shorebird Clock',
|
||||
createdAt: DateTime(2022),
|
||||
updatedAt: DateTime(2023),
|
||||
),
|
||||
];
|
||||
|
||||
when(() => httpClient.send(any())).thenAnswer(
|
||||
(_) async => http.StreamedResponse(
|
||||
Stream.value(utf8.encode(json.encode(expected))),
|
||||
Stream.value(
|
||||
utf8.encode(json.encode(GetAppsResponse(apps: expected))),
|
||||
),
|
||||
HttpStatus.ok,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export 'get_apps_response.dart';
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
|
||||
|
||||
part 'get_apps_response.g.dart';
|
||||
|
||||
/// {@template get_apps_response}
|
||||
/// The response body for GET /api/v1/apps
|
||||
/// {@endtemplate}
|
||||
@JsonSerializable()
|
||||
class GetAppsResponse {
|
||||
/// {@macro get_apps_response}
|
||||
const GetAppsResponse({required this.apps});
|
||||
|
||||
/// Converts a Map<String, dynamic> to a [GetAppsResponse].
|
||||
factory GetAppsResponse.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetAppsResponseFromJson(json);
|
||||
|
||||
/// Converts a [GetAppsResponse] to a Map<String, dynamic>.
|
||||
Json toJson() => _$GetAppsResponseToJson(this);
|
||||
|
||||
/// The list of apps.
|
||||
final List<AppMetadata> apps;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
// ignore_for_file: implicit_dynamic_parameter, require_trailing_commas, cast_nullable_to_non_nullable, lines_longer_than_80_chars
|
||||
|
||||
part of 'get_apps_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetAppsResponse _$GetAppsResponseFromJson(Map<String, dynamic> json) =>
|
||||
$checkedCreate(
|
||||
'GetAppsResponse',
|
||||
json,
|
||||
($checkedConvert) {
|
||||
final val = GetAppsResponse(
|
||||
apps: $checkedConvert(
|
||||
'apps',
|
||||
(v) => (v as List<dynamic>)
|
||||
.map((e) => AppMetadata.fromJson(e as Map<String, dynamic>))
|
||||
.toList()),
|
||||
);
|
||||
return val;
|
||||
},
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetAppsResponseToJson(GetAppsResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'apps': instance.apps.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
@@ -10,6 +10,7 @@ export 'create_payment_link/create_payment_link.dart';
|
||||
export 'create_release/create_release.dart';
|
||||
export 'create_release_artifact/create_release_artifact.dart';
|
||||
export 'create_user/create_user.dart';
|
||||
export 'get_apps/get_apps.dart';
|
||||
export 'get_overages/get_overages.dart';
|
||||
export 'get_release_artifacts/get_release_artifacts.dart';
|
||||
export 'get_release_patches/get_release_patches.dart';
|
||||
|
||||
@@ -11,6 +11,8 @@ class AppMetadata {
|
||||
const AppMetadata({
|
||||
required this.appId,
|
||||
required this.displayName,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
this.latestReleaseVersion,
|
||||
this.latestPatchNumber,
|
||||
});
|
||||
@@ -33,4 +35,10 @@ class AppMetadata {
|
||||
|
||||
/// The latest patch number of the app.
|
||||
final int? latestPatchNumber;
|
||||
|
||||
/// The date and time the app was created.
|
||||
final DateTime createdAt;
|
||||
|
||||
/// The date and time the app was last updated.
|
||||
final DateTime updatedAt;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ AppMetadata _$AppMetadataFromJson(Map<String, dynamic> json) => $checkedCreate(
|
||||
final val = AppMetadata(
|
||||
appId: $checkedConvert('app_id', (v) => v as String),
|
||||
displayName: $checkedConvert('display_name', (v) => v as String),
|
||||
createdAt:
|
||||
$checkedConvert('created_at', (v) => DateTime.parse(v as String)),
|
||||
updatedAt:
|
||||
$checkedConvert('updated_at', (v) => DateTime.parse(v as String)),
|
||||
latestReleaseVersion:
|
||||
$checkedConvert('latest_release_version', (v) => v as String?),
|
||||
latestPatchNumber:
|
||||
@@ -25,6 +29,8 @@ AppMetadata _$AppMetadataFromJson(Map<String, dynamic> json) => $checkedCreate(
|
||||
fieldKeyMap: const {
|
||||
'appId': 'app_id',
|
||||
'displayName': 'display_name',
|
||||
'createdAt': 'created_at',
|
||||
'updatedAt': 'updated_at',
|
||||
'latestReleaseVersion': 'latest_release_version',
|
||||
'latestPatchNumber': 'latest_patch_number'
|
||||
},
|
||||
@@ -36,4 +42,6 @@ Map<String, dynamic> _$AppMetadataToJson(AppMetadata instance) =>
|
||||
'display_name': instance.displayName,
|
||||
'latest_release_version': instance.latestReleaseVersion,
|
||||
'latest_patch_number': instance.latestPatchNumber,
|
||||
'created_at': instance.createdAt.toIso8601String(),
|
||||
'updated_at': instance.updatedAt.toIso8601String(),
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
|
||||
dependencies:
|
||||
json_annotation: ^4.8.0
|
||||
json_annotation: ^4.8.1
|
||||
money2: ^3.4.1
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group(GetAppsResponse, () {
|
||||
test('can be (de)serialized', () {
|
||||
final response = GetAppsResponse(
|
||||
apps: [
|
||||
AppMetadata(
|
||||
appId: 'app-id',
|
||||
displayName: 'display-name',
|
||||
createdAt: DateTime(2022),
|
||||
updatedAt: DateTime(2023),
|
||||
)
|
||||
],
|
||||
);
|
||||
expect(
|
||||
GetAppsResponse.fromJson(response.toJson()).toJson(),
|
||||
equals(response.toJson()),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -4,11 +4,13 @@ import 'package:test/test.dart';
|
||||
void main() {
|
||||
group(AppMetadata, () {
|
||||
test('can be (de)serialized', () {
|
||||
const appMetadata = AppMetadata(
|
||||
final appMetadata = AppMetadata(
|
||||
appId: '30370f27-dbf1-4673-8b20-fb096e38dffa',
|
||||
displayName: 'My App',
|
||||
latestReleaseVersion: '1.0.0',
|
||||
latestPatchNumber: 1,
|
||||
createdAt: DateTime(2022),
|
||||
updatedAt: DateTime(2023),
|
||||
);
|
||||
expect(
|
||||
AppMetadata.fromJson(appMetadata.toJson()).toJson(),
|
||||
|
||||
Reference in New Issue
Block a user