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

Commit 623658a

Browse files
author
JSpru
authored
Adding luis:version:rename cmd (#378)
* Adding luis:version:rename cmd * INcrease mocha timeout * Add flags type * Remove example files
1 parent 14b8ff8 commit 623658a

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-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 LuisVersionRename extends Command {
11+
static description = 'Renames application version'
12+
13+
static examples = [`
14+
$ bf luis:version:rename --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} --appId {APP_ID} --name {NAME} --description {DESCRIPTION}
15+
`]
16+
17+
static flags: any = {
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 applicaton name'}),
23+
versionId: flags.string({description: 'Version to update (mandatory, defaults to config:LUIS:versionId'}),
24+
newVersionId: flags.string({description: 'New version name (mandatory)'}),
25+
}
26+
27+
async run() {
28+
const {flags} = this.parse(LuisVersionRename)
29+
const flagLabels = Object.keys(LuisVersionRename.flags)
30+
const configDir = this.config.configDir
31+
32+
const {
33+
endpoint,
34+
subscriptionKey,
35+
appId,
36+
name,
37+
versionId,
38+
newVersionId,
39+
} = await utils.processInputs(flags, flagLabels, configDir)
40+
41+
const requiredProps = {endpoint, subscriptionKey, appId, name, newVersionId}
42+
utils.validateRequiredProps(requiredProps)
43+
44+
const client = utils.getLUISClient(subscriptionKey, endpoint)
45+
46+
const versionUpdateObject = {name, version: newVersionId}
47+
48+
try {
49+
await client.versions.update(appId, versionId, versionUpdateObject)
50+
this.log('App version successfully renamed')
51+
} catch (err) {
52+
throw new CLIError(`Failed to rename app version: ${err}`)
53+
}
54+
}
55+
}
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:rename', () => {
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:rename', '--help'])
19+
.it('should print the help contents when --help is passed as an argument', ctx => {
20+
expect(ctx.stdout).to.contain('Renames application version')
21+
})
22+
23+
test
24+
.stdout()
25+
.stderr()
26+
.command(['luis:version:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--versionId', '0.1', '--newVersionId', '0.2'])
27+
.it('displays an error if any required input parameters are missing', ctx => {
28+
expect(ctx.stderr).to.contain(`Required input property 'name' missing.`)
29+
})
30+
31+
test
32+
.stdout()
33+
.stderr()
34+
.command(['luis:version:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--name', 'sample-app', '--versionId', '0.1', '--newVersionId', '0.2'])
35+
.it('displays an error if any required input parameters are missing', ctx => {
36+
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
37+
})
38+
39+
test
40+
.nock('https://westus.api.cognitive.microsoft.com', api => api
41+
.put(uri => uri.includes('apps'))
42+
.reply(200)
43+
)
44+
.stdout()
45+
.command(['luis:version:rename', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--appId', uuidv1(), '--name', 'sample-app', '--versionId', '0.1', '--newVersionId', '0.2'])
46+
.it('renames a LUIS application version and displays a success message', ctx => {
47+
expect(ctx.stdout).to.contain('App version successfully renamed')
48+
})
49+
50+
test
51+
.stdout()
52+
.stderr()
53+
.command(['luis:version:rename', '--endpoint', 'undefined', '--subscriptionKey', uuidv1(), '--appId', uuidv1(), '--name', 'sample-app', '--versionId', '0.1', '--newVersionId', '0.2'])
54+
.it('fails to rename application version and displays an error message if the endpoint is null', ctx => {
55+
expect(ctx.stderr).to.contain('Access denied due to invalid subscription key or wrong API endpoint.')
56+
})
57+
58+
})

0 commit comments

Comments
 (0)