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

Commit 1295b96

Browse files
JSprumunozemilio
authored andcommitted
Adding LUIS app delete command (#352)
* Adding LUIS app delete command * Check status code before printing confirmation
1 parent 782f25c commit 1295b96

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
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 LuisApplicationDelete extends Command {
11+
static description = 'Deletes a LUIS application'
12+
13+
static examples = [`
14+
$ bf luis:application:delete --appId {APP_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+
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
21+
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}),
22+
}
23+
24+
async run() {
25+
const {flags} = this.parse(LuisApplicationDelete)
26+
const flagLabels = Object.keys(LuisApplicationDelete.flags)
27+
const configDir = this.config.configDir
28+
29+
const {
30+
appId,
31+
endpoint,
32+
subscriptionKey,
33+
} = await utils.processInputs(flags, flagLabels, configDir)
34+
35+
const requiredProps = {appId, endpoint, subscriptionKey}
36+
utils.validateRequiredProps(requiredProps)
37+
38+
const client = utils.getLUISClient(subscriptionKey, endpoint)
39+
40+
try {
41+
const result = await client.apps.deleteMethod(appId)
42+
if (result.code === 'Success') {
43+
this.log('App successfully deleted.')
44+
}
45+
} catch (err) {
46+
throw new CLIError(`Failed to delete app: ${err}`)
47+
}
48+
}
49+
}
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:application: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:application: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 LUIS application')
21+
})
22+
23+
test
24+
.stdout()
25+
.stderr()
26+
.command(['luis:application: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:application:delete', '--appId', uuidv1(), '--subscriptionKey', uuidv1()])
35+
.it('displays an error if any required input parameters are missing', ctx => {
36+
expect(ctx.stderr).to.contain(`Required input property 'endpoint' missing.`)
37+
})
38+
39+
test
40+
.nock('https://westus.api.cognitive.microsoft.com', api => api
41+
.delete(uri => uri.includes('apps'))
42+
.reply(200, {'code': 'Success'})
43+
)
44+
.stdout()
45+
.command(['luis:application:delete', '--appId', uuidv1(), '--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('App successfully deleted')
48+
})
49+
50+
test
51+
.stdout()
52+
.stderr()
53+
.command(['luis:application:delete', '--appId', uuidv1(), '--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')
56+
})
57+
58+
})

0 commit comments

Comments
 (0)