Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit be9700a

Browse files
JSprumunozemilio
authored andcommitted
Adding luis:version:delete cmd (#355)
* Adding luis:version:delete cmd * Make error mssg check more specific * Removing unused function in utils, boot test coverage
1 parent 15772dc commit be9700a

File tree

3 files changed

+107
-8
lines changed

3 files changed

+107
-8
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
7+
8+
const utils = require('../../../utils/index')
9+
10+
export default class LuisVersionDelete extends Command {
11+
static description = 'Deletes a version of a LUIS application'
12+
13+
static examples = [`
14+
$ bf luis:version:delete --appId {APP_ID} --versionId {VERSION_ID} --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY}
15+
`]
16+
17+
static flags = {
18+
help: flags.help({char: 'h'}),
19+
appId: flags.string({description: 'LUIS application Id'}),
20+
versionId: flags.string({description: 'LUIS application version Id'}),
21+
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
22+
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}),
23+
}
24+
25+
async run() {
26+
const {flags} = this.parse(LuisVersionDelete)
27+
const flagLabels = Object.keys(LuisVersionDelete.flags)
28+
const configDir = this.config.configDir
29+
30+
const {
31+
appId,
32+
versionId,
33+
endpoint,
34+
subscriptionKey,
35+
} = await utils.processInputs(flags, flagLabels, configDir)
36+
37+
const requiredProps = {appId, versionId, endpoint, subscriptionKey}
38+
utils.validateRequiredProps(requiredProps)
39+
40+
const client = utils.getLUISClient(subscriptionKey, endpoint)
41+
42+
try {
43+
await client.versions.deleteMethod(appId, versionId)
44+
this.log(`Successfully deleted version ${versionId}`)
45+
} catch (err) {
46+
throw new CLIError(`Failed to delete app version: ${err}`)
47+
}
48+
}
49+
}

packages/luis/src/utils/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ const getLUISClient = (subscriptionKey: string, endpoint: string) => {
3636
return luisClient
3737
}
3838

39-
const getPropFromConfig = async (prop: string, configDir: string) => {
40-
const config = await getUserConfig(configDir)
41-
if (config && config[prop]) {
42-
return config[prop]
43-
}
44-
}
45-
4639
const processInputs = async (flags: any, flagLabels: string[], configDir: string) => {
4740
const configPrefix = 'luis__'
4841
let config = await getUserConfig(configDir)
@@ -67,6 +60,5 @@ const validateRequiredProps = (configObj: any) => {
6760

6861
module.exports.getLUISClient = getLUISClient
6962
module.exports.getUserConfig = getUserConfig
70-
module.exports.getPropFromConfig = getPropFromConfig
7163
module.exports.processInputs = processInputs
7264
module.exports.validateRequiredProps = validateRequiredProps
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {expect, test} from '@oclif/test'
2+
const sinon = require('sinon')
3+
const uuidv1 = require('uuid/v1')
4+
const utils = require('../../../../src/utils/index')
5+
6+
describe('luis:version:delete', () => {
7+
8+
beforeEach(() => {
9+
sinon.stub(utils, 'processInputs').returnsArg(0)
10+
})
11+
12+
afterEach(() => {
13+
sinon.restore();
14+
});
15+
16+
test
17+
.stdout()
18+
.command(['luis:version:delete', '--help'])
19+
.it('should print the help contents when --help is passed as an argument', ctx => {
20+
expect(ctx.stdout).to.contain('Deletes a version of a LUIS application')
21+
})
22+
23+
test
24+
.stdout()
25+
.stderr()
26+
.command(['luis:version:delete', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
27+
.it('displays an error if any required input parameters are missing', ctx => {
28+
expect(ctx.stderr).to.contain(`Required input property 'appId' missing.`)
29+
})
30+
31+
test
32+
.stdout()
33+
.stderr()
34+
.command(['luis:version:delete', '--appId', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
35+
.it('displays an error if any required input parameters are missing', ctx => {
36+
expect(ctx.stderr).to.contain(`Required input property 'versionId' missing.`)
37+
})
38+
39+
test
40+
.nock('https://westus.api.cognitive.microsoft.com', api => api
41+
.delete(uri => uri.includes('version'))
42+
.reply(200)
43+
)
44+
.stdout()
45+
.command(['luis:version:delete', '--appId', uuidv1(), '--versionId', '0.2', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()])
46+
.it('deletes a luis app and displays a success message', ctx => {
47+
expect(ctx.stdout).to.contain('Successfully deleted version')
48+
})
49+
50+
test
51+
.stdout()
52+
.stderr()
53+
.command(['luis:version:delete', '--appId', uuidv1(), '--versionId', '0.2', '--endpoint', 'undefined', '--subscriptionKey', uuidv1()])
54+
.it('fails to delete an app and displays an error message if the endpoint is undefined', ctx => {
55+
expect(ctx.stderr).to.contain('Failed to delete app version')
56+
})
57+
58+
})

0 commit comments

Comments
 (0)