fix: gracefully handling patching on a app with no releases (#2247)

Co-authored-by: Bryan Oltman <bryan@shorebird.dev>
This commit is contained in:
Erick
2024-06-14 15:18:52 -03:00
committed by GitHub
parent 0927c3aab1
commit 4021912be8
2 changed files with 29 additions and 0 deletions
@@ -308,6 +308,14 @@ NOTE: this is ${styleBold.wrap('not')} recommended. Asset changes cannot be incl
final releases = await codePushClientWrapper.getReleases(
appId: appId,
);
if (releases.isEmpty) {
logger.warn(
'''No releases found for app $appId. You need to make first a release before you can create a patch.''',
);
throw ProcessExit(ExitCode.usage.code);
}
return logger.chooseOne<Release>(
'Which release would you like to patch?',
choices: releases.sortedBy((r) => r.createdAt).reversed.toList(),
@@ -678,6 +678,27 @@ void main() {
);
});
group('when prompting for releases, but there is none', () {
setUp(() {
when(
() => codePushClientWrapper.getReleases(appId: any(named: 'appId')),
).thenAnswer((_) async => []);
});
test('warns and exits', () async {
await expectLater(
() => runWithOverrides(command.run),
exitsWithCode(ExitCode.usage),
);
verify(
() => logger.warn(
'''No releases found for app $appId. You need to make first a release before you can create a patch.''',
),
).called(1);
});
});
group('when running on CI', () {
setUp(() {
when(() => shorebirdEnv.canAcceptUserInput).thenReturn(false);