From 1cffdb0325c45222557e7b6f55426268bf722acb Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 5 May 2023 14:47:39 -0500 Subject: [PATCH 1/2] feat(shorebird_cli): shorebird releases list supports flavors --- .../releases/list_releases_command.dart | 11 ++++- .../releases/list_releases_command_test.dart | 44 ++++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart b/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart index b8487528f..cd80cb4f2 100644 --- a/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart +++ b/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart @@ -2,6 +2,7 @@ import 'package:barbecue/barbecue.dart'; import 'package:mason_logger/mason_logger.dart'; import 'package:shorebird_cli/src/auth_logger_mixin.dart'; import 'package:shorebird_cli/src/command.dart'; +import 'package:shorebird_cli/src/config/shorebird_yaml.dart'; import 'package:shorebird_cli/src/shorebird_config_mixin.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; @@ -17,7 +18,12 @@ class ListReleasesCommand extends ShorebirdCommand required super.logger, super.auth, super.buildCodePushClient, - }); + }) { + argParser.addOption( + 'flavor', + help: 'The product flavor to use when building the app.', + ); + } @override String get name => 'list'; @@ -39,7 +45,8 @@ class ListReleasesCommand extends ShorebirdCommand return ExitCode.config.code; } - final appId = getShorebirdYaml()!.appId; + final flavor = results['flavor'] as String?; + final appId = getShorebirdYaml()!.getAppId(flavor: flavor); final codePushClient = buildCodePushClient( httpClient: auth.client, diff --git a/packages/shorebird_cli/test/src/commands/releases/list_releases_command_test.dart b/packages/shorebird_cli/test/src/commands/releases/list_releases_command_test.dart index 1837b0385..77c8c7675 100644 --- a/packages/shorebird_cli/test/src/commands/releases/list_releases_command_test.dart +++ b/packages/shorebird_cli/test/src/commands/releases/list_releases_command_test.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:args/args.dart'; import 'package:http/http.dart' as http; import 'package:mason_logger/mason_logger.dart'; import 'package:mocktail/mocktail.dart'; @@ -9,6 +10,8 @@ import 'package:shorebird_cli/src/commands/commands.dart'; import 'package:shorebird_code_push_client/shorebird_code_push_client.dart'; import 'package:test/test.dart'; +class _MockArgResults extends Mock implements ArgResults {} + class _MockAuth extends Mock implements Auth {} class _MockCodePushClient extends Mock implements CodePushClient {} @@ -20,6 +23,7 @@ class _MockLogger extends Mock implements Logger {} void main() { group(ListReleasesCommand, () { const appId = 'test-app-id'; + late ArgResults argResults; late Auth auth; late http.Client httpClient; late CodePushClient codePushClient; @@ -48,6 +52,7 @@ flutter: } setUp(() { + argResults = _MockArgResults(); auth = _MockAuth(); codePushClient = _MockCodePushClient(); httpClient = _MockHttpClient(); @@ -60,7 +65,7 @@ flutter: hostedUri, }) => codePushClient, - ); + )..testArgResults = argResults; when(() => auth.client).thenReturn(httpClient); when(() => auth.isAuthenticated).thenReturn(true); @@ -118,6 +123,43 @@ flutter: verify(() => logger.info('(empty)')).called(1); }); + test('uses correct app_id when flavor is specified', () async { + const flavor = 'development'; + when(() => argResults['flavor']).thenReturn(flavor); + final tempDir = setUpTempDir(); + File( + p.join(tempDir.path, 'shorebird.yaml'), + ).writeAsStringSync(''' +app_id: productionAppId +flavors: + $flavor: $appId'''); + when(() => codePushClient.getReleases(appId: appId)).thenAnswer( + (_) async => [ + const Release( + id: 1, + appId: appId, + version: '1.0.0', + displayName: 'v1.0.0 (dev)', + ), + ], + ); + + final exitCode = await IOOverrides.runZoned( + command.run, + getCurrentDirectory: () => tempDir, + ); + + expect(exitCode, ExitCode.success.code); + verify( + () => logger.info(''' +┌─────────┬──────────────┐ +│ Version │ Name │ +├─────────┼──────────────┤ +│ 1.0.0 │ v1.0.0 (dev) │ +└─────────┴──────────────┘'''), + ).called(1); + }); + test('returns ExitCode.success and prints releases when releases exist', () async { final tempDir = setUpTempDir(); From 2ce6e733a25b14fdd39630bc10d40236f20feabf Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Fri, 5 May 2023 14:48:39 -0500 Subject: [PATCH 2/2] tweeak --- .../lib/src/commands/releases/list_releases_command.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart b/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart index cd80cb4f2..fc313922d 100644 --- a/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart +++ b/packages/shorebird_cli/lib/src/commands/releases/list_releases_command.dart @@ -21,7 +21,7 @@ class ListReleasesCommand extends ShorebirdCommand }) { argParser.addOption( 'flavor', - help: 'The product flavor to use when building the app.', + help: 'The product flavor to use when listing releases.', ); }