1+ import { expect , test } from '@oclif/test'
2+ import * as cp from 'child_process' ;
3+ const sinon = require ( 'sinon' )
4+ const uuidv1 = require ( 'uuid/v1' )
5+ const utils = require ( '../../../../src/utils/index' )
6+
7+ describe ( 'luis:application:import' , ( ) => {
8+
9+ beforeEach ( ( ) => {
10+ sinon . stub ( utils , 'processInputs' ) . returnsArg ( 0 )
11+
12+ } )
13+
14+ afterEach ( ( ) => {
15+ sinon . restore ( ) ;
16+ } ) ;
17+
18+ test
19+ . stdout ( )
20+ . command ( [ 'luis:application:import' , '--help' ] )
21+ . it ( 'should print the help contents when --help is passed as an argument' , ctx => {
22+ expect ( ctx . stdout ) . to . contain ( 'Imports an application to LUIS' )
23+ } )
24+
25+ test
26+ . stdout ( )
27+ . stderr ( )
28+ . command ( [ 'luis:application:import' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
29+ . it ( 'displays an error if any required input parameters are missing' , ctx => {
30+ expect ( ctx . stderr ) . to . contain ( `Required input property 'name' missing.` )
31+ } )
32+
33+ test
34+ . stdout ( )
35+ . stderr ( )
36+ . command ( [ 'luis:application:import' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--name' , 'sample_app' ] )
37+ . it ( 'displays an error if any required input parameters are missing' , ctx => {
38+ expect ( ctx . stderr ) . to . contain ( `Required input property 'subscriptionKey' missing.` )
39+ } )
40+
41+ test
42+ . nock ( 'https://westus.api.cognitive.microsoft.com' , api => api
43+ . post ( uri => uri . includes ( 'apps' ) )
44+ . reply ( 201 , '99999' )
45+ )
46+ . stdout ( )
47+ . stderr ( )
48+ . command ( [ 'luis:application:import' , '--name' , 'Sample' , '--in' , './test/fixtures/sample-app.json' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
49+ . it ( 'imports a luis app from a file and returns the app\'s id' , ctx => {
50+ expect ( ctx . stdout ) . to . contain ( 'App successfully imported with id 99999' )
51+ } )
52+
53+ test
54+ . stdout ( )
55+ . stderr ( )
56+ . command ( [ 'luis:application:import' , '--name' , 'Sample' , '--in' , './test/fixtures/xyz.json' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
57+ . it ( 'displays an error message if the import file cannot be found' , ctx => {
58+ expect ( ctx . stderr ) . to . contain ( 'Failed to read app JSON' )
59+ } )
60+
61+ test
62+ . stdout ( )
63+ . stderr ( )
64+ . command ( [ 'luis:application:import' , '--name' , 'Sample' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
65+ . it ( 'displays an error message if no input data detected' , ctx => {
66+ expect ( ctx . stderr ) . to . contain ( 'No import data found - please provide input through stdin or the --in flag' )
67+ } )
68+
69+ test
70+ . stdin ( '{"luis_schema_version": "4.0.0","versionId": "0.1","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": []}' )
71+ . stdout ( )
72+ . stderr ( )
73+ . command ( [ 'luis:application:import' , '--name' , 'sampleapp' , '--endpoint' , 'https://westus.api.cognitive.microsoft.com' , '--subscriptionKey' , uuidv1 ( ) ] )
74+ . it ( 'imports a luis app from stdin and returns the app\'s id' , ctx => {
75+ process . stdin . setEncoding ( 'utf8' )
76+ process . stdin . once ( 'data' , data => {
77+ expect ( ctx . stderr ) . to . contain ( 'App successfully imported with id 99999' )
78+ } )
79+ } )
80+
81+ } )
0 commit comments