Skip to content
Draft
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
30 changes: 29 additions & 1 deletion src/cli/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -224,6 +240,9 @@ const inspectPrint: InspectPrint = {
for (;;) {
const res = await api.inspect();

if (!ensureDeploymentsExist(res)) {
return;
}
console.clear();

const p = new Table({
Expand Down Expand Up @@ -278,13 +297,22 @@ const inspectPrint: InspectPrint = {
api: APIInterface
): Promise<void> => {
const res = await api.inspect();

if (!ensureDeploymentsExist(res)) {
return;
}
console.log(JSON.stringify(res, null, 2));
},
[InspectFormat.OpenAPIv3]: async (
config: Config,
api: APIInterface
): Promise<void> => {
const res = await api.inspect();

if (!ensureDeploymentsExist(res)) {
return;
}

console.log(
JSON.stringify(
rawInspectToOpenAPIv3(
Expand Down
43 changes: 37 additions & 6 deletions src/test/cli.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -141,14 +142,15 @@ describe('Integration CLI', function () {
const workdir = await createTmpDirectory();

try {
await runCLI(
const result = await runCLI(
[
`--email=${email}`,
`--password=${password}`,
`--workdir=${workdir}`
],
[keys.enter]
).promise;
ok(String(result).includes(`i Login Successfull!\n`));
} catch (err) {
strictEqual(
err,
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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(
Expand Down