1616'use strict' ;
1717
1818const { assert} = require ( 'chai' ) ;
19- const execSync = require ( 'child_process' ) . execSync ;
19+ const { execSync} = require ( 'child_process' ) ;
2020const uuid = require ( 'uuid/v4' ) ;
21+
2122const cmd = 'node detect.v2beta1.js' ;
2223const testQuery = 'Where is my data stored?' ;
2324const testKnowledgeBaseName = `${ uuid ( ) . split ( '-' ) [ 0 ] } -TestKnowledgeBase` ;
@@ -31,15 +32,13 @@ describe('v2beta1 detection', () => {
3132 let knowbaseId ;
3233 let documentFullPath ;
3334
34- it ( 'should create a knowledge base' , async ( ) => {
35+ it ( 'should create a knowledge base' , ( ) => {
3536 // Check that the knowledge base does not yet exist
3637 let output = exec ( `${ cmd } listKnowledgeBases` ) ;
3738 assert . notInclude ( output , testKnowledgeBaseName ) ;
3839
3940 // Creates a knowledge base
40- output = exec (
41- `${ cmd } createKnowledgeBase -k ${ testKnowledgeBaseName } `
42- ) ;
41+ output = exec ( `${ cmd } createKnowledgeBase -k ${ testKnowledgeBaseName } ` ) ;
4342 assert . include ( output , `displayName: ${ testKnowledgeBaseName } ` ) ;
4443
4544 knowbaseFullName = output
@@ -52,66 +51,67 @@ describe('v2beta1 detection', () => {
5251 . trim ( ) ;
5352 } ) ;
5453
55- it ( 'should list the knowledge bases' , async ( ) => {
54+ it ( 'should list the knowledge bases' , ( ) => {
5655 const output = exec ( `${ cmd } listKnowledgeBases` ) ;
5756 assert . include ( output , testKnowledgeBaseName ) ;
5857 } ) ;
5958
60- it ( 'should get a knowledge base' , async ( ) => {
59+ it ( 'should get a knowledge base' , ( ) => {
6160 const output = exec ( `${ cmd } getKnowledgeBase -b "${ knowbaseId } "` ) ;
6261 assert . include ( output , `displayName: ${ testKnowledgeBaseName } ` ) ;
6362 assert . include ( output , `name: ${ knowbaseFullName } ` ) ;
6463 } ) ;
6564
66- it ( 'should create a document' , async ( ) => {
65+ it ( 'should create a document' , ( ) => {
6766 const output = exec (
6867 `${ cmd } createDocument -n "${ knowbaseFullName } " -z "${ testDocumentPath } " -m "${ testDocName } "`
6968 ) ;
7069 assert . include ( output , 'Document created' ) ;
7170 } ) ;
7271
73- it ( 'should list documents' , async ( ) => {
72+ it ( 'should list documents' , ( ) => {
7473 const output = exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
75- const parsedOut = output . split ( '\n' ) ;
74+ const parsedOut = output . split ( '\n' ) . filter ( x => ! ! x . trim ( ) ) ;
7675 documentFullPath = parsedOut [ parsedOut . length - 1 ] . split ( ':' ) [ 1 ] ;
76+ assert . isDefined ( documentFullPath ) ;
7777 assert . include ( output , `There are 1 documents in ${ knowbaseFullName } ` ) ;
7878 } ) ;
7979
80- it ( 'should detect intent with a knowledge base' , async ( ) => {
80+ it ( 'should detect intent with a knowledge base' , ( ) => {
8181 const output = exec (
8282 `${ cmd } detectIntentKnowledge -q "${ testQuery } " -n "${ knowbaseId } "`
8383 ) ;
8484 assert . include ( output , 'Detected Intent:' ) ;
8585 } ) ;
8686
87- it ( 'should delete a document' , async ( ) => {
87+ it ( 'should delete a document' , ( ) => {
8888 const output = exec ( `${ cmd } deleteDocument -d ${ documentFullPath } ` ) ;
8989 assert . include ( output , 'document deleted' ) ;
9090 } ) ;
9191
92- it ( 'should list the document' , async ( ) => {
92+ it ( 'should list the document' , ( ) => {
9393 const output = exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
9494 assert . notInclude ( output , documentFullPath ) ;
9595 } ) ;
9696
97- it ( 'should delete the Knowledge Base' , async ( ) => {
97+ it ( 'should delete the Knowledge Base' , ( ) => {
9898 exec ( `${ cmd } deleteKnowledgeBase -n "${ knowbaseFullName } "` ) ;
9999 } ) ;
100100
101- it ( 'should list the Knowledge Base' , async ( ) => {
101+ it ( 'should list the Knowledge Base' , ( ) => {
102102 const output = exec ( `${ cmd } listKnowledgeBases` ) ;
103103 assert . notInclude ( output , testKnowledgeBaseName ) ;
104104 } ) ;
105105
106- it ( 'should detect Intent with Model Selection' , async ( ) => {
106+ it ( 'should detect Intent with Model Selection' , ( ) => {
107107 const output = exec ( `${ cmd } detectIntentwithModelSelection` ) ;
108108 assert . include (
109109 output ,
110110 'Response: I can help with that. Where would you like to reserve a room?'
111111 ) ;
112112 } ) ;
113113
114- it ( 'should detect Intent with Text to Speech Response' , async ( ) => {
114+ it ( 'should detect Intent with Text to Speech Response' , ( ) => {
115115 const output = exec (
116116 `${ cmd } detectIntentwithTexttoSpeechResponse -q "${ testQuery } "`
117117 ) ;
@@ -121,10 +121,8 @@ describe('v2beta1 detection', () => {
121121 ) ;
122122 } ) ;
123123
124- it ( 'should detect sentiment with intent' , async ( ) => {
125- const output = exec (
126- `${ cmd } detectIntentandSentiment -q "${ testQuery } "`
127- ) ;
124+ it ( 'should detect sentiment with intent' , ( ) => {
125+ const output = exec ( `${ cmd } detectIntentandSentiment -q "${ testQuery } "` ) ;
128126 assert . include ( output , 'Detected sentiment' ) ;
129127 } ) ;
130128} ) ;
0 commit comments