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

Redirect users to login flow when signing up with an existing email (#174) #175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ const authSignup = async (config: Config): Promise<string> => {

email = password = passwordConfirmation = userAlias = '';

await askData();
if (!errorMessage.includes('alias is already taken')) {
await authSelection(config);
} else {
await askData();
}
}
}
return process.exit(ErrorCode.Ok);
Expand Down
29 changes: 24 additions & 5 deletions src/test/login.cli.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ describeTest('Integration CLI (Login)', function () {
});

// signup already taken email
it('Should fail with taken email', async () => {
it('Should fail with taken email and redirect to login', async () => {
await clearCache();
let stdout = '';
try {
const result = await runCLI(
const result = runCLI(
[],
[
keys.down,
Expand All @@ -132,17 +133,35 @@ describeTest('Integration CLI (Login)', function () {
keys.enter,
'diaa',
keys.enter,
'diaa',
'non-existing-alias',
keys.enter
]
).promise;
);

// Attach an event listener to capture stdout
result.child.stdout?.on('data', (data: Buffer) => {
stdout += data.toString();
});

await result.promise;

fail(
`The CLI passed without errors and it should fail. Result: ${String(
result
)}`
);
} catch (error) {
ok(String(error).includes('Account already exists'));
// Check the error message
ok(
String(error).includes(`Account already exists.`),
'Expected error message for existing account was not found.'
);

// Validate that the login method menu is printed after the error
ok(
String(stdout).includes('Select the login method'),
'The CLI did not print the login method menu after the error.'
);
}
});

Expand Down