From 651d2939f7a7d79e568c0bc3d597429b3d99a480 Mon Sep 17 00:00:00 2001 From: diaabadr Date: Thu, 27 Apr 2023 10:18:11 +0200 Subject: [PATCH 1/6] Add master branch updates to ensure-deploymets-existence update --- src/cli/inspect.ts | 27 ++++++++++++++++++++++++++- src/test/cli.integration.spec.ts | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index b03be72..724bd45 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -7,7 +7,7 @@ import { OpenAPIV3 } from 'openapi-types'; import { Config } from '../config'; import { sleep } from './../utils'; import args, { InspectFormat } from './args'; -import { error } from './messages'; +import { error, info, warn } from './messages'; interface row { Deployments: string; @@ -216,6 +216,18 @@ const rawInspectToOpenAPIv3 = ( }); }; +const ensureDeploymentsExist = (res: Deployment[]): boolean => { + if (res.length) return true; + warn('Your MetaCall Hub account has no active deployments.'); + info( + '`metacall-deploy` is a command you can use to deploy your application.' + ); + info( + '`metacall-deploy --help` can be used to get more information about the aforementioned command.' + ); + return false; +}; + const inspectPrint: InspectPrint = { [InspectFormat.Table]: async ( config: Config, @@ -224,6 +236,9 @@ const inspectPrint: InspectPrint = { for (;;) { const res = await api.inspect(); + if (!ensureDeploymentsExist(res)) { + return; + } console.clear(); const p = new Table({ @@ -278,6 +293,10 @@ const inspectPrint: InspectPrint = { api: APIInterface ): Promise => { const res = await api.inspect(); + + if (!ensureDeploymentsExist(res)) { + return; + } console.log(JSON.stringify(res, null, 2)); }, [InspectFormat.OpenAPIv3]: async ( @@ -285,6 +304,11 @@ const inspectPrint: InspectPrint = { api: APIInterface ): Promise => { const res = await api.inspect(); + + if (!ensureDeploymentsExist(res)) { + return; + } + console.log( JSON.stringify( rawInspectToOpenAPIv3( @@ -317,3 +341,4 @@ export const inspect = async ( ): Promise => { await inspectPrint[format](config, api); }; + diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index ae18480..a60bdb4 100644 --- a/src/test/cli.integration.spec.ts +++ b/src/test/cli.integration.spec.ts @@ -33,6 +33,7 @@ describe('Integration CLI', function () { const url = 'https://github.com/metacall/examples'; const addRepoSuffix = 'metacall-examples'; + const inspectFormats = ['Table', 'Raw', 'OpenAPIv3']; const workDirSuffix = 'time-app-web'; const filePath = join( @@ -330,6 +331,26 @@ describe('Integration CLI', function () { return result; }); + // checking if there is no deployments throw inspect + it(`Should pass with --inspect if there is no active deployments`, async function () { + for (const format of inspectFormats) { + try { + await runCLI([`--inspect ${format}}`], [keys.enter]).promise; + fail( + `It gives active deployments in ${format} format while there is none` + ); + } catch (error) { + if ( + String(error).includes( + '! Your MetaCall Hub account has no active deployments.' + ) + ) + continue; + else fail(`Warning message is not right in ${format} format`); + } + } + ok(`Passes in the 3 inspect formats when there is no deployments`); + }); // --force // it('Should be able to deploy forcefully using --force flag', async () => { // const resultDel = await runCLI( @@ -513,3 +534,4 @@ describe('Integration CLI', function () { // if there is only one log file -> select it (TODO: This must be reviewed in case we use TUI) // test for mangled token, expired + From ad04be6be146b484098528c71121b3607ac54ddc Mon Sep 17 00:00:00 2001 From: Diaa Badr Eldin <77173710+diaabadr@users.noreply.github.com> Date: Thu, 27 Apr 2023 10:28:57 +0200 Subject: [PATCH 2/6] formatting --- src/cli/inspect.ts | 1 - src/test/cli.integration.spec.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index 724bd45..f819bbd 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -341,4 +341,3 @@ export const inspect = async ( ): Promise => { await inspectPrint[format](config, api); }; - diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index a60bdb4..8cf48a8 100644 --- a/src/test/cli.integration.spec.ts +++ b/src/test/cli.integration.spec.ts @@ -534,4 +534,3 @@ describe('Integration CLI', function () { // if there is only one log file -> select it (TODO: This must be reviewed in case we use TUI) // test for mangled token, expired - From f8786010de137e9dcc8d96309276ac2a3548abd7 Mon Sep 17 00:00:00 2001 From: Diaa Badr Eldin <77173710+diaabadr@users.noreply.github.com> Date: Fri, 28 Apr 2023 18:02:12 +0200 Subject: [PATCH 3/6] Refactor the inspect function to work with the updated implementation that checks the deployments existence --- src/test/cli.integration.spec.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index 8cf48a8..44c139b 100644 --- a/src/test/cli.integration.spec.ts +++ b/src/test/cli.integration.spec.ts @@ -238,11 +238,20 @@ describe('Integration CLI', function () { }); // --inspect without parameter - it('Should fail --inspect command with proper output', async () => - notStrictEqual( - await runCLI(['--inspect'], [keys.enter]).promise, - 'X Invalid format passed to inspect, valid formats are: Table, Raw, OpenAPIv3\n' - )); + it('Should fail --inspect command with proper output', async () => { + try { + const result = await runCLI(['--inspect'], [keys.enter]).promise; + notStrictEqual( + result, + 'X Invalid format passed to inspect, valid formats are: Table, Raw, OpenAPIv3\n' + ); + } catch (error) { + strictEqual( + String(error), + '! Your MetaCall Hub account has no active deployments.\n' + ); + } + }); // --delete it('Should be able to delete deployed repository using --delete flag', async () => { From 4b22b9f15fd2b1809d2ad3be05273f5c76134369 Mon Sep 17 00:00:00 2001 From: diaabadr Date: Sat, 29 Apr 2023 05:30:25 +0300 Subject: [PATCH 4/6] trigger workflow From 478f63e5d8f5814c33b008605fd6520076a68f31 Mon Sep 17 00:00:00 2001 From: diaabadr Date: Sun, 30 Apr 2023 00:03:03 +0300 Subject: [PATCH 5/6] fixing unhandled case at login using email test --- src/test/cli.integration.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index 44c139b..f93624d 100644 --- a/src/test/cli.integration.spec.ts +++ b/src/test/cli.integration.spec.ts @@ -142,7 +142,7 @@ describe('Integration CLI', function () { const workdir = await createTmpDirectory(); try { - await runCLI( + const result = await runCLI( [ `--email=${email}`, `--password=${password}`, @@ -150,6 +150,7 @@ describe('Integration CLI', function () { ], [keys.enter] ).promise; + ok(String(result).includes(`i Login Successfull!\n`)); } catch (err) { strictEqual( err, From 24bfe0977e445f8f2f8b87470d994f2f59846e24 Mon Sep 17 00:00:00 2001 From: Vicente Eduardo Ferrer Garcia <7854099+viferga@users.noreply.github.com> Date: Tue, 27 Aug 2024 17:45:31 -0400 Subject: [PATCH 6/6] Update inspect.ts --- src/cli/inspect.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index f819bbd..1c6e54f 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -217,7 +217,10 @@ const rawInspectToOpenAPIv3 = ( }; const ensureDeploymentsExist = (res: Deployment[]): boolean => { - if (res.length) return true; + if (res.length) { + return true; + } + warn('Your MetaCall Hub account has no active deployments.'); info( '`metacall-deploy` is a command you can use to deploy your application.' @@ -225,6 +228,7 @@ const ensureDeploymentsExist = (res: Deployment[]): boolean => { info( '`metacall-deploy --help` can be used to get more information about the aforementioned command.' ); + return false; };