Skip to content

Commit

Permalink
feat(globe_cli): Added login url in output of login command (#34)
Browse files Browse the repository at this point in the history
* feat(globe_cli): added login url in output of login command

* feat(globe_cli): formatting

* feat(globe_cli): updated test cases

* feat(globe_cli): formatting

* feat(globe_cli): analyzer
  • Loading branch information
kaziwaseef committed Jan 19, 2024
1 parent 71c5988 commit 5294dcb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/globe_cli/lib/src/commands/login_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class LoginCommand extends BaseGlobeCommand {
onConnected: (port) async {
logger.info('Please authenticate via the opened browser window.');
// TODO can we react to openUrl close, to have the command emit a "failed to login"?
final url =
'$endpoint/login/cli?callback=http://localhost:$port/callback?strategy=${GlobeHttpServerRedirectStrategy.redirect.name}';
logger.info('\nOr go to this link: $url\n');
await openUrl(
'$endpoint/login/cli?callback=http://localhost:$port/callback?strategy=${GlobeHttpServerRedirectStrategy.redirect.name}',
url,
);
},
);
Expand Down
3 changes: 1 addition & 2 deletions packages/globe_cli/lib/src/utils/open_url.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ String get _openUrlCommand {
return 'open';
} else {
throw UnsupportedError(
'Operating system not supported by the open_url '
'package: ${Platform.operatingSystem}',
'Operating system not supported: ${Platform.operatingSystem}',
);
}
}
16 changes: 14 additions & 2 deletions packages/globe_cli/test/login_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ void main() {
),
);

const url =
'https://globe.dev/login/cli?callback=http://localhost:4242/callback?strategy=redirect';

await expectLater(
result.testOutputByLines,
emitsInOrder([
'Please authenticate via the opened browser window.',
'',
'Or go to this link: $url',
'',
'Successfully logged in.',
emitsDone,
]),
);

verify(
openUrlMock(
'https://globe.dev/login/cli?callback=http://localhost:4242/callback?strategy=redirect',
url,
),
).called(1);
verifyNoMoreInteractions(openUrlMock);
Expand Down Expand Up @@ -109,18 +115,24 @@ void main() {
),
);

const url =
'https://globe.dev/login/cli?callback=http://localhost:4242/callback?strategy=redirect';

await expectLater(
result.testOutputByLines,
emitsInOrder([
'Please authenticate via the opened browser window.',
'',
'Or go to this link: $url',
'',
'err: Failed to login.',
emitsDone,
]),
);

verify(
openUrlMock(
'https://globe.dev/login/cli?callback=http://localhost:4242/callback?strategy=redirect',
url,
),
).called(1);
verifyNoMoreInteractions(openUrlMock);
Expand Down

0 comments on commit 5294dcb

Please sign in to comment.