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:version:import' , ( ) => {
7+
8+ beforeEach ( ( ) => {
9+ sinon . stub ( utils , 'processInputs' ) . returnsArg ( 0 )
10+
11+ } )
12+
13+ afterEach ( ( ) => {
14+ sinon . restore ( ) ;
15+ } ) ;
16+
17+ test
18+ . stdout ( )
19+ . command ( [ 'luis:version:import' , '--help' ] )
20+ . it ( 'should print the help contents when --help is passed as an argument' , ctx => {
21+ expect ( ctx . stdout ) . to . contain ( 'Imports a new version into a LUIS application' )
22+ } )
23+
24+ test
25+ . stdout ( )
26+ . stderr ( )
27+ . command ( [ 'luis:version:import' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
28+ . it ( 'displays an error if any required input parameters are missing' , ctx => {
29+ expect ( ctx . stderr ) . to . contain ( `Required input property 'appId' missing.` )
30+ } )
31+
32+ test
33+ . stdout ( )
34+ . stderr ( )
35+ . command ( [ 'luis:version:import' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--appId' , uuidv1 ( ) ] )
36+ . it ( 'displays an error if any required input parameters are missing' , ctx => {
37+ expect ( ctx . stderr ) . to . contain ( `Required input property 'subscriptionKey' missing.` )
38+ } )
39+
40+ test
41+ . nock ( 'https://westus.api.cognitive.microsoft.com' , api => api
42+ . post ( uri => uri . includes ( 'apps' ) )
43+ . reply ( 201 , '0.9' )
44+ )
45+ . stdout ( )
46+ . stderr ( )
47+ . command ( [ 'luis:version:import' , '--appId' , uuidv1 ( ) , '--in' , './test/fixtures/sample-app-version.json' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) , '--appId' , uuidv1 ( ) ] )
48+ . it ( 'imports a luis app version from a file and returns the app\'s new version id' , ctx => {
49+ expect ( ctx . stdout ) . to . contain ( 'App version successfully imported as version 0.9' )
50+ } )
51+
52+ test
53+ . nock ( 'https://westus.api.cognitive.microsoft.com' , api => api
54+ . post ( uri => uri . includes ( 'apps' ) )
55+ . reply ( 201 , '0.7' )
56+ )
57+ . stdout ( )
58+ . stderr ( )
59+ . command ( [ 'luis:version:import' , '--versionId' , '0.7' , '--appId' , uuidv1 ( ) , '--in' , './test/fixtures/sample-app-version.json' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) , '--appId' , uuidv1 ( ) ] )
60+ . it ( 'imports a luis app version from a file and returns the app\'s new version id, as specified by the versionId flag' , ctx => {
61+ expect ( ctx . stdout ) . to . contain ( 'App version successfully imported as version 0.7' )
62+ } )
63+
64+ test
65+ . stdout ( )
66+ . stderr ( )
67+ . command ( [ 'luis:version:import' , '--appId' , uuidv1 ( ) , '--in' , './test/fixtures/xyz.json' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
68+ . it ( 'displays an error message if the import file cannot be found' , ctx => {
69+ expect ( ctx . stderr ) . to . contain ( 'Failed to read app JSON' )
70+ } )
71+
72+ test
73+ . stdout ( )
74+ . stderr ( )
75+ . command ( [ 'luis:version:import' , '--appId' , uuidv1 ( ) , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
76+ . it ( 'displays an error message if no input data detected' , ctx => {
77+ expect ( ctx . stderr ) . to . contain ( 'No import data found - please provide input through stdin or the --in flag' )
78+ } )
79+
80+ test
81+ . stdin ( '{"luis_schema_version": "4.0.0","versionId": "0.9","name": "sampleapp","desc": "test description","culture": "en-us","tokenizerVersion": "1.0.0","intents": [{"name": "None"}],"entities": [],"composites": [],"closedLists": [],"patternAnyEntities": [],"regex_entities": [],"prebuiltEntities": [],"model_features": [],"regex_features": [],"patterns": [],"utterances": [],"settings": []}' )
82+ . stdout ( )
83+ . stderr ( )
84+ . command ( [ 'luis:version:import' , '--appId' , uuidv1 ( ) , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
85+ . it ( 'imports a luis app version from stdin and returns the app\'s id' , ctx => {
86+ process . stdin . setEncoding ( 'utf8' )
87+ process . stdin . once ( 'data' , data => {
88+ expect ( ctx . stderr ) . to . contain ( 'App version successfully imported as version 0.9' )
89+ } )
90+ } )
91+
92+ } )
0 commit comments