From 5ced16410bcdcfdf7462e983f824c11a95f276d6 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Tue, 16 May 2023 15:51:56 -0500 Subject: [PATCH] feat(code_push_protocol): add `Collaborator` model (#500) --- .../lib/src/models/collaborator.dart | 25 ++++++++++++++++ .../lib/src/models/collaborator.g.dart | 29 +++++++++++++++++++ .../lib/src/models/models.dart | 1 + .../test/src/models/app_metadata_test.dart | 2 +- .../test/src/models/app_test.dart | 2 +- .../test/src/models/channel_test.dart | 2 +- .../test/src/models/collaborator_test.dart | 17 +++++++++++ .../test/src/models/error_response_test.dart | 2 +- .../test/src/models/patch_artifact_test.dart | 2 +- .../test/src/models/patch_test.dart | 2 +- .../src/models/release_artifact_test.dart | 2 +- .../test/src/models/release_test.dart | 2 +- .../test/src/models/user_test.dart | 2 +- 13 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/collaborator.dart create mode 100644 packages/shorebird_code_push_protocol/lib/src/models/collaborator.g.dart create mode 100644 packages/shorebird_code_push_protocol/test/src/models/collaborator_test.dart diff --git a/packages/shorebird_code_push_protocol/lib/src/models/collaborator.dart b/packages/shorebird_code_push_protocol/lib/src/models/collaborator.dart new file mode 100644 index 00000000..cd516617 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/collaborator.dart @@ -0,0 +1,25 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'collaborator.g.dart'; + +/// {@template collaborator} +/// A user who has permission to collaborate on an app. +/// {@endtemplate} +@JsonSerializable() +class Collaborator { + /// {@macro collaborator} + const Collaborator({required this.userId, required this.email}); + + /// Converts a Map to an [Collaborator] + factory Collaborator.fromJson(Map json) => + _$CollaboratorFromJson(json); + + /// Converts a [Collaborator] to a Map + Map toJson() => _$CollaboratorToJson(this); + + /// The unique identifier for the user. + final int userId; + + /// The email address of the user. + final String email; +} diff --git a/packages/shorebird_code_push_protocol/lib/src/models/collaborator.g.dart b/packages/shorebird_code_push_protocol/lib/src/models/collaborator.g.dart new file mode 100644 index 00000000..aef05c93 --- /dev/null +++ b/packages/shorebird_code_push_protocol/lib/src/models/collaborator.g.dart @@ -0,0 +1,29 @@ +// 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 'collaborator.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +Collaborator _$CollaboratorFromJson(Map json) => + $checkedCreate( + 'Collaborator', + json, + ($checkedConvert) { + final val = Collaborator( + userId: $checkedConvert('user_id', (v) => v as int), + email: $checkedConvert('email', (v) => v as String), + ); + return val; + }, + fieldKeyMap: const {'userId': 'user_id'}, + ); + +Map _$CollaboratorToJson(Collaborator instance) => + { + 'user_id': instance.userId, + 'email': instance.email, + }; diff --git a/packages/shorebird_code_push_protocol/lib/src/models/models.dart b/packages/shorebird_code_push_protocol/lib/src/models/models.dart index 7cb4f1d5..ec77bf2c 100644 --- a/packages/shorebird_code_push_protocol/lib/src/models/models.dart +++ b/packages/shorebird_code_push_protocol/lib/src/models/models.dart @@ -1,6 +1,7 @@ export 'app.dart'; export 'app_metadata.dart'; export 'channel.dart'; +export 'collaborator.dart'; export 'error_response.dart'; export 'patch.dart'; export 'patch_artifact.dart'; diff --git a/packages/shorebird_code_push_protocol/test/src/models/app_metadata_test.dart b/packages/shorebird_code_push_protocol/test/src/models/app_metadata_test.dart index 7dfaa2a0..993da2c9 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/app_metadata_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/app_metadata_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('AppMetadata', () { + group(AppMetadata, () { test('can be (de)serialized', () { const appMetadata = AppMetadata( appId: '30370f27-dbf1-4673-8b20-fb096e38dffa', diff --git a/packages/shorebird_code_push_protocol/test/src/models/app_test.dart b/packages/shorebird_code_push_protocol/test/src/models/app_test.dart index a1902a2c..9d1bdf03 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/app_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/app_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('App', () { + group(App, () { test('can be (de)serialized', () { const app = App( id: '30370f27-dbf1-4673-8b20-fb096e38dffa', diff --git a/packages/shorebird_code_push_protocol/test/src/models/channel_test.dart b/packages/shorebird_code_push_protocol/test/src/models/channel_test.dart index b15d0561..6da70d5b 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/channel_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/channel_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('Channel', () { + group(Channel, () { test('can be (de)serialized', () { const channel = Channel( id: 1, diff --git a/packages/shorebird_code_push_protocol/test/src/models/collaborator_test.dart b/packages/shorebird_code_push_protocol/test/src/models/collaborator_test.dart new file mode 100644 index 00000000..f6efce68 --- /dev/null +++ b/packages/shorebird_code_push_protocol/test/src/models/collaborator_test.dart @@ -0,0 +1,17 @@ +import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; +import 'package:test/test.dart'; + +void main() { + group(Collaborator, () { + test('can be (de)serialized', () { + const collaborator = Collaborator( + userId: 1, + email: 'jane.doe@shorebird.dev', + ); + expect( + Collaborator.fromJson(collaborator.toJson()).toJson(), + equals(collaborator.toJson()), + ); + }); + }); +} diff --git a/packages/shorebird_code_push_protocol/test/src/models/error_response_test.dart b/packages/shorebird_code_push_protocol/test/src/models/error_response_test.dart index dc42887c..566996ba 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/error_response_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/error_response_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('ErrorResponse', () { + group(ErrorResponse, () { test('can be (de)serialized', () { const response = ErrorResponse( code: 'code', diff --git a/packages/shorebird_code_push_protocol/test/src/models/patch_artifact_test.dart b/packages/shorebird_code_push_protocol/test/src/models/patch_artifact_test.dart index 385d01e9..f357a9ba 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/patch_artifact_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/patch_artifact_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('PatchArtifact', () { + group(PatchArtifact, () { test('can be (de)serialized', () { const artifact = PatchArtifact( id: 1, diff --git a/packages/shorebird_code_push_protocol/test/src/models/patch_test.dart b/packages/shorebird_code_push_protocol/test/src/models/patch_test.dart index e8ceeb7f..bc182fea 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/patch_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/patch_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('Patch', () { + group(Patch, () { test('can be (de)serialized', () { const patch = Patch(id: 1, number: 2); expect( diff --git a/packages/shorebird_code_push_protocol/test/src/models/release_artifact_test.dart b/packages/shorebird_code_push_protocol/test/src/models/release_artifact_test.dart index a4cfb3fb..de77081b 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/release_artifact_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/release_artifact_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('ReleaseArtifact', () { + group(ReleaseArtifact, () { test('can be (de)serialized', () { const artifact = ReleaseArtifact( id: 1, diff --git a/packages/shorebird_code_push_protocol/test/src/models/release_test.dart b/packages/shorebird_code_push_protocol/test/src/models/release_test.dart index 7a623cd5..dc813338 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/release_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/release_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('Release', () { + group(Release, () { test('can be (de)serialized', () { const release = Release( id: 1, diff --git a/packages/shorebird_code_push_protocol/test/src/models/user_test.dart b/packages/shorebird_code_push_protocol/test/src/models/user_test.dart index 6b7704f8..2782cbd7 100644 --- a/packages/shorebird_code_push_protocol/test/src/models/user_test.dart +++ b/packages/shorebird_code_push_protocol/test/src/models/user_test.dart @@ -2,7 +2,7 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; import 'package:test/test.dart'; void main() { - group('User', () { + group(User, () { test('can be (de)serialized', () { const user = User( id: 1,