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

Commit 0a3344a

Browse files
author
JSpru
authored
Adding luis:application:rename cmd (#377)
1 parent 1da7e1c commit 0a3344a

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 LuisApplicationRename extends Command {
11+
static description = 'Renames the application and updates its description'
12+
13+
static examples = [`
14+
$ bf luis:application:rename --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} --appId {APP_ID} --name {NAME} --description {DESCRIPTION}
15+
`]
16+
17+
static flags = {
18+
help: flags.help({char: 'h'}),
19+
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
20+
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}),
21+
appId: flags.string({description: 'LUIS applicaton id'}),
22+
name: flags.string({description: 'LUIS application name'}),
23+
description: flags.string({description: 'LUIS application description'}),
24+
}
25+
26+
async run() {
27+
const {flags} = this.parse(LuisApplicationRename)
28+
const flagLabels = Object.keys(LuisApplicationRename.flags)
29+
const configDir = this.config.configDir
30+
31+
const {
32+
endpoint,
33+
subscriptionKey,
34+
appId,
35+
name,
36+
description
37+
} = await utils.processInputs(flags, flagLabels, configDir)
38+
39+
const requiredProps = {endpoint, subscriptionKey, appId, name}
40+
utils.validateRequiredProps(requiredProps)
41+
42+
const client = utils.getLUISClient(subscriptionKey, endpoint)
43+
44+
const applicationUpdateObject = {name, description}
45+
46+
try {
47+
const appUpdateStatus = await client.apps.update(appId, applicationUpdateObject)
48+
if (appUpdateStatus.code === 'Success') {
49+
this.log('App successfully renamed')
50+
}
51+
} catch (err) {
52+
throw new CLIError(`Failed to rename app: ${err}`)
53+
}
54+
}
55+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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:rename', () => {
7+
8+
before(() => {
9+
const newAppId = uuidv1()
10+
})
11+
12+
beforeEach(() => {
13+
sinon.stub(utils, 'processInputs').returnsArg(0)
14+
})
15+
16+
afterEach(() => {
17+
sinon.restore();
18+
});
19+
20+
test
21+
.stdout()
22+
.command(['luis:application:rename', '--help'])
23+
.it('should print the help contents when --help is passed as an argument', ctx => {
24+
expect(ctx.stdout).to.contain('Renames the application and updates its description')
25+
})
26+
27+
test
28+
.stdout()
29+
.stderr()
30+
.command(['luis:application:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--description', 'test description'])
31+
.it('displays an error if any required input parameters are missing', ctx => {
32+
expect(ctx.stderr).to.contain(`Required input property 'name' missing.`)
33+
})
34+
35+
test
36+
.stdout()
37+
.stderr()
38+
.command(['luis:application:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--name', 'sample-app', '--description', 'test description'])
39+
.it('displays an error if any required input parameters are missing', ctx => {
40+
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
41+
})
42+
43+
test
44+
.nock('https://westus.api.cognitive.microsoft.com', api => api
45+
.put(uri => uri.includes('apps'))
46+
.reply(200, {"code":"Success","message":"Operation Successful"})
47+
)
48+
.stdout()
49+
.stderr()
50+
.command(['luis:application:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--appId', uuidv1(), '--name', 'sample-app', '--description', 'test description'])
51+
.it('renames a LUIS application and displays a success message', ctx => {
52+
expect(ctx.stdout).to.contain('App successfully renamed')
53+
})
54+
55+
test
56+
.stdout()
57+
.stderr()
58+
.command(['luis:application:rename', '--endpoint', 'undefined', '--subscriptionKey', uuidv1(), '--appId', uuidv1(), '--name', 'sample-app', '--description', 'test description'])
59+
.it('fails to create an app and displays an error message if the endpoint is null', ctx => {
60+
expect(ctx.stderr).to.contain('Access denied due to invalid subscription key or wrong API endpoint.')
61+
})
62+
63+
})

0 commit comments

Comments
 (0)