Skip to content

Commit

Permalink
refactor(code_push_protocol): create collaborators via email (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel authored May 17, 2023
1 parent d42d3b0 commit 7ba4c11
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class CodePushClient {
/// Collaborators can manage the app including its releases and patches.
Future<void> createAppCollaborator({
required String appId,
required int userId,
required String email,
}) async {
final response = await _httpClient.post(
Uri.parse('$_v1/apps/$appId/collaborators'),
body: json.encode(CreateAppCollaboratorRequest(userId: userId).toJson()),
body: json.encode(CreateAppCollaboratorRequest(email: email).toJson()),
);

if (response.statusCode != HttpStatus.created) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void main() {

group('createAppCollaborator', () {
const appId = 'test-app-id';
const userId = 42;
const email = '[email protected]';

test('throws an exception if the http request fails (unknown)', () async {
when(
Expand All @@ -69,7 +69,7 @@ void main() {
);

expect(
codePushClient.createAppCollaborator(appId: appId, userId: userId),
codePushClient.createAppCollaborator(appId: appId, email: email),
throwsA(
isA<CodePushException>().having(
(e) => e.message,
Expand All @@ -95,7 +95,7 @@ void main() {
);

expect(
codePushClient.createAppCollaborator(appId: appId, userId: userId),
codePushClient.createAppCollaborator(appId: appId, email: email),
throwsA(
isA<CodePushException>().having(
(e) => e.message,
Expand All @@ -115,10 +115,7 @@ void main() {
),
).thenAnswer((_) async => http.Response('', HttpStatus.created));

await codePushClient.createAppCollaborator(
appId: appId,
userId: userId,
);
await codePushClient.createAppCollaborator(appId: appId, email: email);

final uri = verify(
() => httpClient.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ part 'create_app_collaborator_request.g.dart';
@JsonSerializable()
class CreateAppCollaboratorRequest {
/// {@macro create_app_collaborator_request}
const CreateAppCollaboratorRequest({required this.userId});
const CreateAppCollaboratorRequest({required this.email});

/// Converts a Map<String, dynamic> to a [CreateAppCollaboratorRequest]
factory CreateAppCollaboratorRequest.fromJson(Map<String, dynamic> json) =>
Expand All @@ -17,6 +17,6 @@ class CreateAppCollaboratorRequest {
/// Converts a [CreateAppCollaboratorRequest] to a Map<String, dynamic>
Map<String, dynamic> toJson() => _$CreateAppCollaboratorRequestToJson(this);

/// The unique identifier of the collaborator to add.
final int userId;
/// The email of the collaborator to add.
final String email;
}

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
Expand Up @@ -4,7 +4,9 @@ import 'package:test/test.dart';
void main() {
group(CreateAppCollaboratorRequest, () {
test('can be (de)serialized', () {
const request = CreateAppCollaboratorRequest(userId: 42);
const request = CreateAppCollaboratorRequest(
email: '[email protected]',
);
expect(
CreateAppCollaboratorRequest.fromJson(request.toJson()).toJson(),
equals(request.toJson()),
Expand Down

0 comments on commit 7ba4c11

Please sign in to comment.