1515
1616'use strict' ;
1717
18- const path = require ( 'path' ) ;
1918const { assert} = require ( 'chai' ) ;
20- const execa = require ( 'execa' ) ;
19+ const execSync = require ( 'child_process' ) . execSync ;
2120const uuid = require ( 'uuid/v4' ) ;
22-
2321const cmd = 'node detect.v2beta1.js' ;
24- const { cwd} = path . join ( __dirname , '..' ) ;
2522const testQuery = 'Where is my data stored?' ;
2623const testKnowledgeBaseName = `${ uuid ( ) . split ( '-' ) [ 0 ] } -TestKnowledgeBase` ;
2724const testDocName = 'TestDoc' ;
2825const testDocumentPath = 'https://cloud.google.com/storage/docs/faq' ;
2926
30- const exec = async cmd => {
31- const res = await execa . shell ( cmd , { cwd} ) ;
32- if ( res . stderr ) {
33- throw new Error ( res . stderr ) ;
34- }
35- return res . stdout ;
36- } ;
27+ const exec = cmd => execSync ( cmd , { encoding : 'utf8' } ) ;
3728
3829describe ( 'v2beta1 detection' , ( ) => {
3930 let knowbaseFullName ;
@@ -42,11 +33,11 @@ describe('v2beta1 detection', () => {
4233
4334 it ( 'should create a knowledge base' , async ( ) => {
4435 // Check that the knowledge base does not yet exist
45- let output = await exec ( `${ cmd } listKnowledgeBases` ) ;
36+ let output = exec ( `${ cmd } listKnowledgeBases` ) ;
4637 assert . notInclude ( output , testKnowledgeBaseName ) ;
4738
4839 // Creates a knowledge base
49- output = await exec (
40+ output = exec (
5041 `${ cmd } createKnowledgeBase -k ${ testKnowledgeBaseName } `
5142 ) ;
5243 assert . include ( output , `displayName: ${ testKnowledgeBaseName } ` ) ;
@@ -62,66 +53,66 @@ describe('v2beta1 detection', () => {
6253 } ) ;
6354
6455 it ( 'should list the knowledge bases' , async ( ) => {
65- const output = await exec ( `${ cmd } listKnowledgeBases` ) ;
56+ const output = exec ( `${ cmd } listKnowledgeBases` ) ;
6657 assert . include ( output , testKnowledgeBaseName ) ;
6758 } ) ;
6859
6960 it ( 'should get a knowledge base' , async ( ) => {
70- const output = await exec ( `${ cmd } getKnowledgeBase -b "${ knowbaseId } "` ) ;
61+ const output = exec ( `${ cmd } getKnowledgeBase -b "${ knowbaseId } "` ) ;
7162 assert . include ( output , `displayName: ${ testKnowledgeBaseName } ` ) ;
7263 assert . include ( output , `name: ${ knowbaseFullName } ` ) ;
7364 } ) ;
7465
7566 it ( 'should create a document' , async ( ) => {
76- const output = await exec (
67+ const output = exec (
7768 `${ cmd } createDocument -n "${ knowbaseFullName } " -z "${ testDocumentPath } " -m "${ testDocName } "`
7869 ) ;
7970 assert . include ( output , 'Document created' ) ;
8071 } ) ;
8172
8273 it ( 'should list documents' , async ( ) => {
83- const output = await exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
74+ const output = exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
8475 const parsedOut = output . split ( '\n' ) ;
8576 documentFullPath = parsedOut [ parsedOut . length - 1 ] . split ( ':' ) [ 1 ] ;
8677 assert . include ( output , `There are 1 documents in ${ knowbaseFullName } ` ) ;
8778 } ) ;
8879
8980 it ( 'should detect intent with a knowledge base' , async ( ) => {
90- const output = await exec (
81+ const output = exec (
9182 `${ cmd } detectIntentKnowledge -q "${ testQuery } " -n "${ knowbaseId } "`
9283 ) ;
9384 assert . include ( output , 'Detected Intent:' ) ;
9485 } ) ;
9586
9687 it ( 'should delete a document' , async ( ) => {
97- const output = await exec ( `${ cmd } deleteDocument -d ${ documentFullPath } ` ) ;
88+ const output = exec ( `${ cmd } deleteDocument -d ${ documentFullPath } ` ) ;
9889 assert . include ( output , 'document deleted' ) ;
9990 } ) ;
10091
10192 it ( 'should list the document' , async ( ) => {
102- const output = await exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
93+ const output = exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
10394 assert . notInclude ( output , documentFullPath ) ;
10495 } ) ;
10596
10697 it ( 'should delete the Knowledge Base' , async ( ) => {
107- await exec ( `${ cmd } deleteKnowledgeBase -n "${ knowbaseFullName } "` ) ;
98+ exec ( `${ cmd } deleteKnowledgeBase -n "${ knowbaseFullName } "` ) ;
10899 } ) ;
109100
110101 it ( 'should list the Knowledge Base' , async ( ) => {
111- const output = await exec ( `${ cmd } listKnowledgeBases` ) ;
102+ const output = exec ( `${ cmd } listKnowledgeBases` ) ;
112103 assert . notInclude ( output , testKnowledgeBaseName ) ;
113104 } ) ;
114105
115106 it ( 'should detect Intent with Model Selection' , async ( ) => {
116- const output = await exec ( `${ cmd } detectIntentwithModelSelection` ) ;
107+ const output = exec ( `${ cmd } detectIntentwithModelSelection` ) ;
117108 assert . include (
118109 output ,
119110 'Response: I can help with that. Where would you like to reserve a room?'
120111 ) ;
121112 } ) ;
122113
123114 it ( 'should detect Intent with Text to Speech Response' , async ( ) => {
124- const output = await exec (
115+ const output = exec (
125116 `${ cmd } detectIntentwithTexttoSpeechResponse -q "${ testQuery } "`
126117 ) ;
127118 assert . include (
@@ -131,7 +122,7 @@ describe('v2beta1 detection', () => {
131122 } ) ;
132123
133124 it ( 'should detect sentiment with intent' , async ( ) => {
134- const output = await exec (
125+ const output = exec (
135126 `${ cmd } detectIntentandSentiment -q "${ testQuery } "`
136127 ) ;
137128 assert . include ( output , 'Detected sentiment' ) ;
0 commit comments