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:publish' , ( ) => {
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:publish' , '--help' ] )
23+ . it ( 'should print the help contents when --help is passed as an argument' , ctx => {
24+ expect ( ctx . stdout ) . to . contain ( 'Publishes a specific version of the application' )
25+ } )
26+
27+ test
28+ . stdout ( )
29+ . stderr ( )
30+ . command ( [ 'luis:application:publish' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) , '--appId' , uuidv1 ( ) ] )
31+ . it ( 'displays an error if any required input parameters are missing' , ctx => {
32+ expect ( ctx . stderr ) . to . contain ( `Required input property 'versionId' missing.` )
33+ } )
34+
35+ test
36+ . stdout ( )
37+ . stderr ( )
38+ . command ( [ 'luis:application:publish' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--appId' , uuidv1 ( ) , '--versionId' , '0.01' ] )
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+ . post ( uri => uri . includes ( 'publish' ) )
46+ . reply ( 201 , { "versionId" :"0.1" , "isStaging" :true , "endpointUrl" :"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/4e3d6aec-f79e-4688-b686-feaf6dc2feee" , "region" :"westus" , "endpointRegion" :"westus" , "failedRegions" :"" , "publishedDateTime" :"2019-11-21T21:54:30Z" } )
47+ )
48+ . stdout ( )
49+ . command ( [ 'luis:application:publish' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--appId' , uuidv1 ( ) , '--subscriptionKey' , uuidv1 ( ) , '--versionId' , '0.01' ] )
50+ . it ( 'publishes a luis app and displays the published app data' , ctx => {
51+ expect ( ctx . stdout ) . to . contain ( 'versionId' )
52+ expect ( ctx . stdout ) . to . contain ( 'isStaging' )
53+ expect ( ctx . stdout ) . to . contain ( 'endpointUrl' )
54+ expect ( ctx . stdout ) . to . contain ( 'publishedDateTime' )
55+ } )
56+
57+ test
58+ . nock ( 'https://westus.api.cognitive.microsoft.com' , api => api
59+ . post ( uri => uri . includes ( 'publish' ) )
60+ . reply ( 201 , { "versionId" :"0.1" , "isStaging" :true , "endpointUrl" :"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/4e3d6aec-f79e-4688-b686-feaf6dc2feee" , "region" :"westus" , "endpointRegion" :"westus" , "failedRegions" :"" , "publishedDateTime" :"2019-11-21T21:54:30Z" } )
61+ )
62+ . stdout ( )
63+ . command ( [ 'luis:application:publish' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--appId' , uuidv1 ( ) , '--subscriptionKey' , uuidv1 ( ) , '--versionId' , '0.01' , '--staging' , 'true' , '--direct' , 'false' ] )
64+ . it ( 'publishes a luis app with optional flags and displays the published app data' , ctx => {
65+ expect ( ctx . stdout ) . to . contain ( 'versionId' )
66+ expect ( ctx . stdout ) . to . contain ( 'isStaging' )
67+ expect ( ctx . stdout ) . to . contain ( 'endpointUrl' )
68+ expect ( ctx . stdout ) . to . contain ( 'publishedDateTime' )
69+ } )
70+
71+ } )
0 commit comments