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

fix(shorebird_cli): only use shorebird.yaml app_id when no flavors are present #1543

Merged
merged 1 commit into from
Nov 29, 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
12 changes: 9 additions & 3 deletions packages/shorebird_cli/lib/src/commands/preview_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ class PreviewCommand extends ShorebirdCommand {
return error.exitCode.code;
}

final appId = results['app-id'] as String? ??
shorebirdEnv.getShorebirdYaml()?.appId ??
await promptForApp();
final shorebirdYaml = shorebirdEnv.getShorebirdYaml();
final String? appId;
if (results.wasParsed('app-id')) {
appId = results['app-id'] as String;
} else if (shorebirdYaml != null && shorebirdYaml.flavors == null) {
appId = shorebirdYaml.appId;
} else {
appId = await promptForApp();
}

if (appId == null) {
logger.info('No apps found');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void main() {
shorebirdValidator = MockShorebirdValidator();
command = PreviewCommand()..testArgResults = argResults;

when(() => argResults.wasParsed('app-id')).thenReturn(true);
when(() => argResults['app-id']).thenReturn(appId);
when(() => argResults['release-version']).thenReturn(releaseVersion);
when(() => argResults['staging']).thenReturn(false);
Expand Down Expand Up @@ -520,10 +521,12 @@ void main() {
verify(() => logger.err(output)).called(1);
});

test('does not prompt or query for app when in a shorebird project',
test(
'''does not prompt or query for app when in a shorebird project without flavors''',
() async {
when(() => shorebirdEnv.getShorebirdYaml())
.thenReturn(const ShorebirdYaml(appId: 'test-app-id'));
when(() => argResults.wasParsed('app-id')).thenReturn(false);
when(() => argResults['app-id']).thenReturn(null);

await runWithOverrides(command.run);
Expand All @@ -538,6 +541,35 @@ void main() {
verifyNever(() => codePushClientWrapper.getApps());
});

test('prompts for app id when in shorebird project with flavors',
() async {
when(() => shorebirdEnv.getShorebirdYaml()).thenReturn(
const ShorebirdYaml(
appId: 'test-app-id',
flavors: {'dev': 'dev-app-id'},
),
);
when(() => argResults.wasParsed('app-id')).thenReturn(false);
when(() => argResults['app-id']).thenReturn(null);
when(
() => logger.chooseOne<AppMetadata>(
any(),
choices: any(named: 'choices'),
display: any(named: 'display'),
),
).thenReturn(app);

await runWithOverrides(command.run);

verify(
() => logger.chooseOne<AppMetadata>(
'Which app would you like to preview?',
choices: any(named: 'choices'),
display: any(named: 'display'),
),
).called(1);
});

test('queries for apps when app-id is not specified', () async {
when(
() => artifactManager.extractZip(
Expand All @@ -546,6 +578,7 @@ void main() {
),
).thenAnswer(createShorebirdYaml);

when(() => argResults.wasParsed('app-id')).thenReturn(false);
when(() => argResults['app-id']).thenReturn(null);
when(
() => logger.chooseOne<AppMetadata>(
Expand Down Expand Up @@ -604,6 +637,7 @@ void main() {
});

test('exits early when no apps are found', () async {
when(() => argResults.wasParsed('app-id')).thenReturn(false);
when(() => argResults['app-id']).thenReturn(null);
when(() => codePushClientWrapper.getApps()).thenAnswer((_) async => []);
final result = await runWithOverrides(command.run);
Expand Down