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