|
| 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