diff --git a/src/cli/inspect.ts b/src/cli/inspect.ts index b03be72..1c6e54f 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,22 @@ 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 +240,9 @@ const inspectPrint: InspectPrint = { for (;;) { const res = await api.inspect(); + if (!ensureDeploymentsExist(res)) { + return; + } console.clear(); const p = new Table({ @@ -278,6 +297,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 +308,11 @@ const inspectPrint: InspectPrint = { api: APIInterface ): Promise => { const res = await api.inspect(); + + if (!ensureDeploymentsExist(res)) { + return; + } + console.log( JSON.stringify( rawInspectToOpenAPIv3( diff --git a/src/test/cli.integration.spec.ts b/src/test/cli.integration.spec.ts index ae18480..f93624d 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( @@ -141,7 +142,7 @@ describe('Integration CLI', function () { const workdir = await createTmpDirectory(); try { - await runCLI( + const result = await runCLI( [ `--email=${email}`, `--password=${password}`, @@ -149,6 +150,7 @@ describe('Integration CLI', function () { ], [keys.enter] ).promise; + ok(String(result).includes(`i Login Successfull!\n`)); } catch (err) { strictEqual( err, @@ -237,11 +239,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 () => { @@ -330,6 +341,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(