Skip to content

Commit

Permalink
refactor(shorebird_cli): simplify organization name in `shorebird ini…
Browse files Browse the repository at this point in the history
…t` (#2521)
  • Loading branch information
felangel authored Oct 9, 2024
1 parent 6577946 commit 75e51be
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 111 deletions.
12 changes: 0 additions & 12 deletions packages/shorebird_cli/lib/src/code_push_client_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ class CodePushClientWrapper {
);
}

/// Returns the currently logged in user, or null if no user is logged in.
Future<PrivateUser?> getCurrentUser() async {
final progress = logger.progress('Fetching user');
try {
final user = await codePushClient.getCurrentUser();
progress.complete();
return user;
} catch (error) {
_handleErrorAndExit(error, progress: progress);
}
}

Future<List<OrganizationMembership>> getOrganizationMemberships() async {
final progress = logger.progress('Fetching organizations');
final List<OrganizationMembership> memberships;
Expand Down
4 changes: 1 addition & 3 deletions packages/shorebird_cli/lib/src/commands/init_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:shorebird_cli/src/code_push_client_wrapper.dart';
import 'package:shorebird_cli/src/config/config.dart';
import 'package:shorebird_cli/src/doctor.dart';
import 'package:shorebird_cli/src/executables/executables.dart';
import 'package:shorebird_cli/src/extensions/organization.dart';
import 'package:shorebird_cli/src/logger.dart';
import 'package:shorebird_cli/src/platform/ios.dart';
import 'package:shorebird_cli/src/pubspec_editor.dart';
Expand Down Expand Up @@ -74,13 +73,12 @@ Please make sure you are running "shorebird init" from within your Flutter proje
return ExitCode.software.code;
}

final user = await codePushClientWrapper.getCurrentUser();
final Organization organization;
if (orgs.length > 1) {
organization = logger.chooseOne(
'Which organization should this app belong to?',
choices: orgs.map((o) => o.organization).toList(),
display: (o) => o.displayName(user: user!),
display: (o) => o.name,
);
} else {
organization = orgs.first.organization;
Expand Down
12 changes: 0 additions & 12 deletions packages/shorebird_cli/lib/src/extensions/organization.dart

This file was deleted.

35 changes: 0 additions & 35 deletions packages/shorebird_cli/test/src/code_push_client_wrapper_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,41 +212,6 @@ void main() {
).thenAnswer((_) async => flutterVersion);
});

group('getCurrentUser', () {
group('when getCurrentUser request fails', () {
setUp(() {
when(
() => codePushClient.getCurrentUser(),
).thenThrow(Exception('something went wrong'));
});

test('exits with code 70', () async {
await expectLater(
() async => runWithOverrides(codePushClientWrapper.getCurrentUser),
exitsWithCode(ExitCode.software),
);
verify(() => progress.fail(any())).called(1);
});
});

group('when getCurrentUser request succeeds', () {
final user = PrivateUser.forTest();
setUp(() {
when(() => codePushClient.getCurrentUser()).thenAnswer(
(_) async => user,
);
});

test('returns current user', () async {
final result = await runWithOverrides(
codePushClientWrapper.getCurrentUser,
);
expect(result, user);
verify(() => progress.complete()).called(1);
});
});
});

group('app', () {
const organizationId = 123;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ version: $version
environment:
sdk: ">=2.19.0 <3.0.0"''';
const organizationId = 123;
final currentUser = PrivateUser.forTest();

late ArgResults argResults;
late Doctor doctor;
Expand Down Expand Up @@ -94,9 +93,6 @@ environment:
shorebirdEnv = MockShorebirdEnv();
shorebirdValidator = MockShorebirdValidator();

when(() => codePushClientWrapper.getCurrentUser()).thenAnswer(
(_) async => currentUser,
);
when(() => codePushClientWrapper.getOrganizationMemberships()).thenAnswer(
(_) async => [
OrganizationMembership(
Expand Down Expand Up @@ -379,8 +375,8 @@ Please make sure you are running "shorebird init" from within your Flutter proje
display: captureAny(named: 'display'),
),
).captured.single as String Function(Organization);
expect(capturedDisplay(org1), equals(currentUser.email));
expect(capturedDisplay(org2), equals('org2'));
expect(capturedDisplay(org1), equals(org1.name));
expect(capturedDisplay(org2), equals(org2.name));
verify(
() => codePushClientWrapper.createApp(
appName: appName,
Expand Down
43 changes: 0 additions & 43 deletions packages/shorebird_cli/test/src/extensions/organization_test.dart

This file was deleted.

0 comments on commit 75e51be

Please sign in to comment.