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

refactor(code_push_protocol): create collaborators via email #506

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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