Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shorebird_code_push_protocol): add RecordPatchInstallRequest type #826

Merged
merged 10 commits into from
Aug 9, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export 'create_app_collaborator/create_app_collaborator.dart';
export 'create_channel/create_channel.dart';
export 'create_patch/create_patch.dart';
export 'create_patch_artifact/create_patch_artifact.dart';
export 'record_patch_install/record_patch_install.dart';
export 'create_payment_link/create_payment_link.dart';
export 'create_release/create_release.dart';
export 'create_release_artifact/create_release_artifact.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'record_patch_install_request.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';

part 'record_patch_install_request.g.dart';

/// {@template record_patch_install_request}
/// Request to record a patch install.
/// {@endtemplate}
@JsonSerializable()
class RecordPatchInstallRequest {
/// {@macro record_patch_install_request}
RecordPatchInstallRequest({
required this.clientId,
required this.appId,
required this.releaseVersion,
required this.patchNumber,
required this.platform,
required this.arch,
});

/// Converts a Map<String, dynamic> to a [RecordPatchInstallRequest]
factory RecordPatchInstallRequest.fromJson(Map<String, dynamic> json) =>
_$RecordPatchInstallRequestFromJson(json);

/// Converts a [RecordPatchInstallRequest] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$RecordPatchInstallRequestToJson(this);

/// The client id of the device being updated.
final String clientId;

/// The id of the app being updated.
final String appId;

/// The id of the app being updated.
final String releaseVersion;

/// The patch number being installed.
final int patchNumber;

/// The platform of the device being updated.
final ReleasePlatform platform;

/// The architecture of the device being updated.
final String arch;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart';
import 'package:test/test.dart';

void main() {
group(RecordPatchInstallRequest, () {
test('can be (de)serialized', () {
final response = RecordPatchInstallRequest(
clientId: 'some-client-id',
appId: 'some-app-id',
patchNumber: 2,
arch: 'arm64',
platform: ReleasePlatform.android,
releaseVersion: '1.0.0',
);
expect(
RecordPatchInstallRequest.fromJson(response.toJson()).toJson(),
equals(response.toJson()),
);
});
});
}