|
| 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 | +const fs = require('fs-extra') |
| 6 | +import * as rimraf from 'rimraf' |
| 7 | + |
| 8 | +describe('luis:application:list', () => { |
| 9 | + |
| 10 | + before(() => { |
| 11 | + fs.mkdirSync('./testout'); |
| 12 | + }); |
| 13 | + |
| 14 | + after(() => { |
| 15 | + rimraf('./testout', (err) => { |
| 16 | + if (err) console.log(err); |
| 17 | + }) |
| 18 | + }); |
| 19 | + |
| 20 | + beforeEach(() => { |
| 21 | + sinon.stub(utils, 'processInputs').returnsArg(0) |
| 22 | + }) |
| 23 | + |
| 24 | + afterEach(() => { |
| 25 | + sinon.restore(); |
| 26 | + }); |
| 27 | + |
| 28 | + test |
| 29 | + .stdout() |
| 30 | + .command(['luis:application:list', '--help']) |
| 31 | + .it('should print the help contents when --help is passed as an argument', ctx => { |
| 32 | + expect(ctx.stdout).to.contain('Lists all applications on LUIS service.') |
| 33 | + }) |
| 34 | + |
| 35 | + test |
| 36 | + .stdout() |
| 37 | + .stderr() |
| 38 | + .command(['luis:application:list', '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 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 | + .get(uri => uri.includes('apps')) |
| 46 | + .reply(200, {name: 'testapp'}) |
| 47 | + ) |
| 48 | + .stdout() |
| 49 | + .command(['luis:application:list', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 50 | + .it('displays a list of applications', ctx => { |
| 51 | + expect(ctx.stdout).to.contain('List successfully output to console') |
| 52 | + }) |
| 53 | + |
| 54 | + test |
| 55 | + .nock('https://westus.api.cognitive.microsoft.com', api => api |
| 56 | + .get(uri => uri.includes('apps')) |
| 57 | + .reply(200, {name: 'testapp'}) |
| 58 | + ) |
| 59 | + .stdout() |
| 60 | + .command(['luis:application:list', '--out', './testout/test.json', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 61 | + .it('export a list of applications to the specified file', ctx => { |
| 62 | + expect(ctx.stdout).to.contain('List successfully written to file') |
| 63 | + expect(ctx.stdout).to.contain('test.json') |
| 64 | + }) |
| 65 | + |
| 66 | + test |
| 67 | + .nock('https://westus.api.cognitive.microsoft.com', api => api |
| 68 | + .get(uri => uri.includes('apps')) |
| 69 | + .reply(200, {name: 'testapp'}) |
| 70 | + ) |
| 71 | + .stdout() |
| 72 | + .stderr() |
| 73 | + .command(['luis:application:list', '--out', 'xyz', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 74 | + .it('displays a list of applications and a success message in the console (since the target path provided is invalid)', ctx => { |
| 75 | + expect(ctx.stderr).to.contain('Target directory path doesn\'t exist:') |
| 76 | + }) |
| 77 | + |
| 78 | +}) |
0 commit comments