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: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:version:list' , '--help' ] )
31+ . it ( 'should print the help contents when --help is passed as an argument' , ctx => {
32+ expect ( ctx . stdout ) . to . contain ( 'Lists application version data' )
33+ } )
34+
35+ test
36+ . stdout ( )
37+ . stderr ( )
38+ . command ( [ 'luis:version: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 : 'version' } )
47+ )
48+ . stdout ( )
49+ . command ( [ 'luis:version:list' , '--appId' , uuidv1 ( ) , '--subscriptionKey' , uuidv1 ( ) , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' ] )
50+ . it ( 'displays a list of application versions' , 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 : 'version' } )
58+ )
59+ . stdout ( )
60+ . command ( [ 'luis:version:list' , '--out' , './testout/test.json' , '--subscriptionKey' , uuidv1 ( ) , '--appId' , uuidv1 ( ) , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' ] )
61+ . it ( 'export a list of application versions 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 : 'version' } )
70+ )
71+ . stdout ( )
72+ . command ( [ 'luis:version:list' , '--out' , './testout' , '--subscriptionKey' , uuidv1 ( ) , '--appId' , uuidv1 ( ) , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' ] )
73+ . it ( 'export a list of application versions to the specified directory, using a default file name' , ctx => {
74+ expect ( ctx . stdout ) . to . contain ( 'List successfully written to file' )
75+ expect ( ctx . stdout ) . to . contain ( 'export.json' )
76+ } )
77+
78+ test
79+ . nock ( 'https://westus.api.cognitive.microsoft.com' , api => api
80+ . get ( uri => uri . includes ( 'apps' ) )
81+ . reply ( 200 , { name : 'version' } )
82+ )
83+ . stdout ( )
84+ . stderr ( )
85+ . command ( [ 'luis:version:list' , '--out' , 'xyz' , '--subscriptionKey' , uuidv1 ( ) , '--appId' , uuidv1 ( ) , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' ] )
86+ . it ( 'displays a list of application versions and a success message in the console (since the target path provided is invalid)' , ctx => {
87+ expect ( ctx . stderr ) . to . contain ( 'Target directory path doesn\'t exist:' )
88+ } )
89+
90+ } )
0 commit comments