|
| 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:version:export', () => { |
| 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:version:export', '--help']) |
| 31 | + .it('should print the help contents when --help is passed as an argument', ctx => { |
| 32 | + expect(ctx.stdout).to.contain('Exports a LUIS application to JSON format') |
| 33 | + }) |
| 34 | + |
| 35 | + test |
| 36 | + .stdout() |
| 37 | + .stderr() |
| 38 | + .command(['luis:version:export', '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--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 'appId' missing.`) |
| 41 | + }) |
| 42 | + |
| 43 | + test |
| 44 | + .stdout() |
| 45 | + .stderr() |
| 46 | + .command(['luis:version:export', '--appId', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1()]) |
| 47 | + .it('displays an error if any required input parameters are missing', ctx => { |
| 48 | + expect(ctx.stderr).to.contain(`Required input property 'versionId' missing.`) |
| 49 | + }) |
| 50 | + |
| 51 | + test |
| 52 | + .nock('https://westus.api.cognitive.microsoft.com', api => api |
| 53 | + .get(uri => uri.includes('export')) |
| 54 | + .reply(200, {name: 'testname'}) |
| 55 | + ) |
| 56 | + .stdout() |
| 57 | + .command(['luis:version:export', '--appId', uuidv1(), '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 58 | + .it('exports a luis app and displays the export contents in the console', ctx => { |
| 59 | + expect(ctx.stdout).to.contain('testname') |
| 60 | + }) |
| 61 | + |
| 62 | + test |
| 63 | + .nock('https://westus.api.cognitive.microsoft.com', api => api |
| 64 | + .get(uri => uri.includes('export')) |
| 65 | + .reply(200, {name: 'testname'}) |
| 66 | + ) |
| 67 | + .stdout() |
| 68 | + .command(['luis:version:export', '--appId', uuidv1(), '--out', './testout/test.json', '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 69 | + .it('exports a luis app, displays a success message in the console and the export contents to the specified file', ctx => { |
| 70 | + expect(ctx.stdout).to.contain('File successfully written:') |
| 71 | + }) |
| 72 | + |
| 73 | + test |
| 74 | + .nock('https://westus.api.cognitive.microsoft.com', api => api |
| 75 | + .get(uri => uri.includes('export')) |
| 76 | + .reply(200, {name: 'testname'}) |
| 77 | + ) |
| 78 | + .stdout() |
| 79 | + .stderr() |
| 80 | + .command(['luis:version:export', '--appId', uuidv1(), '--out', 'xyz', '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 81 | + .it('exports a luis app and displays a success message and the export contents in the console (since the target path provided is invalid)', ctx => { |
| 82 | + expect(ctx.stderr).to.contain('Target directory path doesn\'t exist:') |
| 83 | + }) |
| 84 | + |
| 85 | + test |
| 86 | + .nock('https://westus.api.cognitive.microsoft.com', api => api |
| 87 | + .get(uri => uri.includes('export')) |
| 88 | + .reply(200, {name: 'testname'}) |
| 89 | + ) |
| 90 | + .stdout() |
| 91 | + .stderr() |
| 92 | + .command(['luis:version:export', '--appId', uuidv1(), '--out', './testout/test.json', '--force', '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 93 | + .it('exports a luis app, displays a success message in the console and the export contents to the specified file, overwriting the existing file of the same name', ctx => { |
| 94 | + expect(ctx.stdout).to.contain('File successfully written') |
| 95 | + }) |
| 96 | + |
| 97 | + test |
| 98 | + .nock('https://westus.api.cognitive.microsoft.com', api => api |
| 99 | + .get(uri => uri.includes('export')) |
| 100 | + .reply(200, {name: 'testname'}) |
| 101 | + ) |
| 102 | + .stdout() |
| 103 | + .command(['luis:version:export', '--appId', uuidv1(), '--out', './testout/test.json', '--versionId', '0.1', '--subscriptionKey', uuidv1(), '--endpoint', 'https://westus.api.cognitive.microsoft.com']) |
| 104 | + .it('exports a luis app, displays a success message in the console and the export contents to the specified file, incrementing the filename', ctx => { |
| 105 | + expect(ctx.stdout).to.contain('File successfully written') |
| 106 | + expect(ctx.stdout).to.contain('test(1).json') |
| 107 | + }) |
| 108 | + |
| 109 | +}) |
0 commit comments