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

feat(shorebird_cli): shorebird releases list supports --flavor #444

Merged
merged 2 commits into from
May 5, 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 @@ -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';

Expand All @@ -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 listing releases.',
);
}

@override
String get name => 'list';
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {}
Expand All @@ -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;
Expand Down Expand Up @@ -48,6 +52,7 @@ flutter:
}

setUp(() {
argResults = _MockArgResults();
auth = _MockAuth();
codePushClient = _MockCodePushClient();
httpClient = _MockHttpClient();
Expand All @@ -60,7 +65,7 @@ flutter:
hostedUri,
}) =>
codePushClient,
);
)..testArgResults = argResults;

when(() => auth.client).thenReturn(httpClient);
when(() => auth.isAuthenticated).thenReturn(true);
Expand Down Expand Up @@ -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();
Expand Down