From 4af1472a1edb9f471961b7199dc07899e0748260 Mon Sep 17 00:00:00 2001 From: Huthaifa Date: Mon, 27 Jan 2025 14:55:59 +0200 Subject: [PATCH 1/4] Fix sign-up flow for existing email --- src/auth.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/auth.ts b/src/auth.ts index 5a6e39d..81fbc17 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -163,7 +163,11 @@ const authSignup = async (config: Config): Promise => { email = password = passwordConfirmation = userAlias = ''; - await askData(); + if (!errorMessage.includes('alias is already taken')) { + await authSelection(config); + } else { + await askData(); + } } } return process.exit(ErrorCode.Ok); From 77d6ba71a5eaa835e5f18ba4c94e3c3b1e92a3ec Mon Sep 17 00:00:00 2001 From: Huthaifa Omar <55454534+HuzaifaOmar@users.noreply.github.com> Date: Mon, 27 Jan 2025 15:04:38 +0200 Subject: [PATCH 2/4] Update auth.ts removes additional spaces to apply linter rules --- src/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auth.ts b/src/auth.ts index 81fbc17..270496f 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -167,7 +167,7 @@ const authSignup = async (config: Config): Promise => { await authSelection(config); } else { await askData(); - } + } } } return process.exit(ErrorCode.Ok); From 6fc1d81dc0c37fd023696c79fa031bdd77659266 Mon Sep 17 00:00:00 2001 From: Huthaifa Omar <55454534+HuzaifaOmar@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:47:07 +0200 Subject: [PATCH 3/4] test: Add test for CLI login with existing email --- src/test/login.cli.integration.spec.ts | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/test/login.cli.integration.spec.ts b/src/test/login.cli.integration.spec.ts index f18314b..eb86936 100644 --- a/src/test/login.cli.integration.spec.ts +++ b/src/test/login.cli.integration.spec.ts @@ -207,6 +207,52 @@ describeTest('Integration CLI (Login)', function () { } }); + it('Should redirect to login when email is already associated with an account', async () => { + await clearCache(); + + let stdout = ''; + + try { + const process = runCLI( + [], + [ + keys.down, + keys.down, + keys.enter, + 'noot@noot.com', + keys.enter, + 'password123', + keys.enter, + 'password123', + keys.enter, + 'non-existing-alias', + keys.enter + ] + ); + + // Attach an event listener to capture stdout + process.child.stdout?.on('data', (data: Buffer) => { + stdout += data.toString(); + }); + + await process.promise; + + fail('The CLI did not throw an error when it should have.'); + } catch (error) { + // 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.' + ); + } + }); + // Note: Disable this test for now, I do not want to spam the FaaS // success signup /* From 90290d16a392f53ce944f9ad383b639a3ebf9510 Mon Sep 17 00:00:00 2001 From: Huthaifa Omar <55454534+HuzaifaOmar@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:54:00 +0200 Subject: [PATCH 4/4] modified the test to remove redundant test from last commit --- src/test/login.cli.integration.spec.ts | 75 +++++++++----------------- 1 file changed, 24 insertions(+), 51 deletions(-) diff --git a/src/test/login.cli.integration.spec.ts b/src/test/login.cli.integration.spec.ts index eb86936..f0c0062 100644 --- a/src/test/login.cli.integration.spec.ts +++ b/src/test/login.cli.integration.spec.ts @@ -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, @@ -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.' + ); } }); @@ -207,52 +226,6 @@ describeTest('Integration CLI (Login)', function () { } }); - it('Should redirect to login when email is already associated with an account', async () => { - await clearCache(); - - let stdout = ''; - - try { - const process = runCLI( - [], - [ - keys.down, - keys.down, - keys.enter, - 'noot@noot.com', - keys.enter, - 'password123', - keys.enter, - 'password123', - keys.enter, - 'non-existing-alias', - keys.enter - ] - ); - - // Attach an event listener to capture stdout - process.child.stdout?.on('data', (data: Buffer) => { - stdout += data.toString(); - }); - - await process.promise; - - fail('The CLI did not throw an error when it should have.'); - } catch (error) { - // 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.' - ); - } - }); - // Note: Disable this test for now, I do not want to spam the FaaS // success signup /*