From 9e6abfe7bab43d2335406e1f17879b01255cf684 Mon Sep 17 00:00:00 2001 From: diaabadr Date: Mon, 3 Apr 2023 03:34:13 +0200 Subject: [PATCH 1/3] validating-deployments-existence --- src/cli/inspect.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index 59f97c8..f643546 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -7,6 +7,7 @@ import { OpenAPIV3 } from 'openapi-types'; import { Config } from '../config'; import { sleep } from './../utils'; import args, { InspectFormat } from './args'; +import { info, warn } from './messages'; interface row { Deployments: string; @@ -215,6 +216,15 @@ const rawInspectToOpenAPIv3 = ( }); }; +const ensureDeploymentsExist = (res: Deployment[]): boolean => { + if (res.length === 0) { + warn('No Active Deployments found'); + info('You can deploy a new one with command `metacall-deploy`'); + return false; + } + return true; +}; + const inspectPrint: InspectPrint = { [InspectFormat.Table]: async ( config: Config, @@ -222,7 +232,9 @@ const inspectPrint: InspectPrint = { ): Promise => { for (;;) { const res = await api.inspect(); - + if (!ensureDeploymentsExist(res)) { + return; + } console.clear(); const p = new Table({ @@ -277,6 +289,9 @@ 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 ( @@ -284,6 +299,9 @@ const inspectPrint: InspectPrint = { api: APIInterface ): Promise => { const res = await api.inspect(); + if (!ensureDeploymentsExist(res)) { + return; + } console.log( JSON.stringify( rawInspectToOpenAPIv3( From 7ef61add80328348153e6c23df4f1d89730673fa Mon Sep 17 00:00:00 2001 From: Raj Aryan <65965202+Creatoon@users.noreply.github.com> Date: Tue, 4 Apr 2023 00:03:57 +0530 Subject: [PATCH 2/3] Update #150 - changed info messages --- src/cli/inspect.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index f643546..0802ccb 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -217,12 +217,13 @@ const rawInspectToOpenAPIv3 = ( }; const ensureDeploymentsExist = (res: Deployment[]): boolean => { - if (res.length === 0) { - warn('No Active Deployments found'); - info('You can deploy a new one with command `metacall-deploy`'); - return false; - } - 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.'); + info('`metacall-deploy --help` can be used to get more information about the aforementioned command.'); + return false; + + }; const inspectPrint: InspectPrint = { From f9712c77b94a3ea540b6ae06e6ec6839d1b6ee58 Mon Sep 17 00:00:00 2001 From: diaabadr Date: Tue, 4 Apr 2023 02:43:29 +0200 Subject: [PATCH 3/3] Adding tests for the inspect when there is no active deployments --- src/cli/inspect.ts | 14 ++++++++------ src/test/cli.integration.spec.ts | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index 0802ccb..07f5a1c 100644 --- a/src/cli/inspect.ts +++ b/src/cli/inspect.ts @@ -218,12 +218,14 @@ 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; - - + 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 = { diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index 545f563..4551bbb 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( @@ -181,6 +182,21 @@ describe('Integration CLI', function () { } }); + // checking if there is no deployments throw inspect + it(`Should fail 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) { + continue; + } + } + ok(`Passes in the 3 inspect formats when there is no deployments`); + }); + // --help it('Should be able to print help guide using --help flag', async () => { const result = await runCLI(['--help'], [keys.enter]).promise;