Skip to content

Commit

Permalink
fix: shorebird preview to identify shorebird projects with flavors (#…
Browse files Browse the repository at this point in the history
…1854)

Co-authored-by: Bryan Oltman <bryan@shorebird.dev>
  • Loading branch information
erickzanardo and bryanoltman authored Apr 3, 2024
1 parent ce39c85 commit 87f5d43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
12 changes: 11 additions & 1 deletion packages/shorebird_cli/lib/src/commands/preview_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,20 @@ class PreviewCommand extends ShorebirdCommand {

final shorebirdYaml = shorebirdEnv.getShorebirdYaml();
final String? appId;

final flavors = shorebirdYaml?.flavors;

if (results.wasParsed('app-id')) {
appId = results['app-id'] as String;
} else if (shorebirdYaml != null && shorebirdYaml.flavors == null) {
} else if (shorebirdYaml != null && flavors == null) {
appId = shorebirdYaml.appId;
} else if (shorebirdYaml != null && flavors != null) {
final flavorOptions = flavors.keys.toList();
final choosenFlavor = logger.chooseOne<String>(
'Which app flavor?',
choices: flavorOptions,
);
appId = flavors[choosenFlavor];
} else {
appId = await promptForApp();
}
Expand Down
19 changes: 10 additions & 9 deletions packages/shorebird_cli/test/src/commands/preview_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,31 +712,32 @@ channel: ${track.channel}
verifyNever(() => codePushClientWrapper.getApps());
});

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

await runWithOverrides(command.run);

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

0 comments on commit 87f5d43

Please sign in to comment.