From 7ece99ce95c1644488ae30580b063204bc5c590d Mon Sep 17 00:00:00 2001 From: "Jonathan Spruance (Insight Global)" Date: Thu, 14 Nov 2019 11:28:28 -0800 Subject: [PATCH 1/3] Adding luis:version:delete cmd --- .../luis/src/commands/luis/version/delete.ts | 49 ++++++++++++++++ .../test/commands/luis/version/delete.test.ts | 58 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 packages/luis/src/commands/luis/version/delete.ts create mode 100644 packages/luis/test/commands/luis/version/delete.test.ts diff --git a/packages/luis/src/commands/luis/version/delete.ts b/packages/luis/src/commands/luis/version/delete.ts new file mode 100644 index 000000000..3f01dad82 --- /dev/null +++ b/packages/luis/src/commands/luis/version/delete.ts @@ -0,0 +1,49 @@ +/*! + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. + */ + +import {CLIError, Command, flags} from '@microsoft/bf-cli-command' + +const utils = require('../../../utils/index') + +export default class LuisVersionDelete extends Command { + static description = 'Deletes a version of a LUIS application' + + static examples = [` + $ bf luis:version:delete --appId {APP_ID} --versionId {VERSION_ID} --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} + `] + + static flags = { + help: flags.help({char: 'h'}), + appId: flags.string({description: 'LUIS application Id'}), + versionId: flags.string({description: 'LUIS application version Id'}), + endpoint: flags.string({description: 'LUIS endpoint hostname'}), + subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}), + } + + async run() { + const {flags} = this.parse(LuisVersionDelete) + const flagLabels = Object.keys(LuisVersionDelete.flags) + const configDir = this.config.configDir + + const { + appId, + versionId, + endpoint, + subscriptionKey, + } = await utils.processInputs(flags, flagLabels, configDir) + + const requiredProps = {appId, versionId, endpoint, subscriptionKey} + utils.validateRequiredProps(requiredProps) + + const client = utils.getLUISClient(subscriptionKey, endpoint) + + try { + await client.versions.deleteMethod(appId, versionId) + this.log(`Successfully deleted version ${versionId}`) + } catch (err) { + throw new CLIError(`Failed to delete app version: ${err}`) + } + } +} diff --git a/packages/luis/test/commands/luis/version/delete.test.ts b/packages/luis/test/commands/luis/version/delete.test.ts new file mode 100644 index 000000000..d286c9f99 --- /dev/null +++ b/packages/luis/test/commands/luis/version/delete.test.ts @@ -0,0 +1,58 @@ +import {expect, test} from '@oclif/test' +const sinon = require('sinon') +const uuidv1 = require('uuid/v1') +const utils = require('../../../../src/utils/index') + +describe('luis:version:delete', () => { + + beforeEach(() => { + sinon.stub(utils, 'processInputs').returnsArg(0) + }) + + afterEach(() => { + sinon.restore(); + }); + + test + .stdout() + .command(['luis:version:delete', '--help']) + .it('should print the help contents when --help is passed as an argument', ctx => { + expect(ctx.stdout).to.contain('Deletes a version of a LUIS application') + }) + + test + .stdout() + .stderr() + .command(['luis:version:delete', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()]) + .it('displays an error if any required input parameters are missing', ctx => { + expect(ctx.stderr).to.contain(`Required input property 'appId' missing.`) + }) + + test + .stdout() + .stderr() + .command(['luis:version:delete', '--appId', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()]) + .it('displays an error if any required input parameters are missing', ctx => { + expect(ctx.stderr).to.contain(`Required input property 'versionId' missing.`) + }) + + test + .nock('https://westus.api.cognitive.microsoft.com', api => api + .delete(uri => uri.includes('version')) + .reply(200) + ) + .stdout() + .command(['luis:version:delete', '--appId', uuidv1(), '--versionId', '0.2', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()]) + .it('deletes a luis app and displays a success message', ctx => { + expect(ctx.stdout).to.contain('Successfully deleted version') + }) + + test + .stdout() + .stderr() + .command(['luis:version:delete', '--appId', uuidv1(), '--versionId', '0.2', '--endpoint', 'undefined', '--subscriptionKey', uuidv1()]) + .it('fails to delete an app and displays an error message if the endpoint is undefined', ctx => { + expect(ctx.stderr).to.contain('Failed to delete app') + }) + +}) From 8aef155924699d499071102b83f7a6fdf0e7e2c5 Mon Sep 17 00:00:00 2001 From: "Jonathan Spruance (Insight Global)" Date: Thu, 14 Nov 2019 11:33:45 -0800 Subject: [PATCH 2/3] Make error mssg check more specific --- packages/luis/test/commands/luis/version/delete.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/luis/test/commands/luis/version/delete.test.ts b/packages/luis/test/commands/luis/version/delete.test.ts index d286c9f99..c73881019 100644 --- a/packages/luis/test/commands/luis/version/delete.test.ts +++ b/packages/luis/test/commands/luis/version/delete.test.ts @@ -52,7 +52,7 @@ describe('luis:version:delete', () => { .stderr() .command(['luis:version:delete', '--appId', uuidv1(), '--versionId', '0.2', '--endpoint', 'undefined', '--subscriptionKey', uuidv1()]) .it('fails to delete an app and displays an error message if the endpoint is undefined', ctx => { - expect(ctx.stderr).to.contain('Failed to delete app') + expect(ctx.stderr).to.contain('Failed to delete app version') }) }) From 8d6f49e679ffe1b6e3b99647874a54ede3709b3b Mon Sep 17 00:00:00 2001 From: "Jonathan Spruance (Insight Global)" Date: Thu, 14 Nov 2019 11:51:23 -0800 Subject: [PATCH 3/3] Removing unused function in utils, boot test coverage --- packages/luis/src/utils/index.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/luis/src/utils/index.ts b/packages/luis/src/utils/index.ts index 30d572823..90cb24968 100644 --- a/packages/luis/src/utils/index.ts +++ b/packages/luis/src/utils/index.ts @@ -36,13 +36,6 @@ const getLUISClient = (subscriptionKey: string, endpoint: string) => { return luisClient } -const getPropFromConfig = async (prop: string, configDir: string) => { - const config = await getUserConfig(configDir) - if (config && config[prop]) { - return config[prop] - } -} - const processInputs = async (flags: any, flagLabels: string[], configDir: string) => { const configPrefix = 'luis__' let config = await getUserConfig(configDir) @@ -67,6 +60,5 @@ const validateRequiredProps = (configObj: any) => { module.exports.getLUISClient = getLUISClient module.exports.getUserConfig = getUserConfig -module.exports.getPropFromConfig = getPropFromConfig module.exports.processInputs = processInputs module.exports.validateRequiredProps = validateRequiredProps