15
15
16
16
'use strict' ;
17
17
18
- const path = require ( 'path' ) ;
19
18
const { assert} = require ( 'chai' ) ;
20
- const execa = require ( 'execa' ) ;
19
+ const execSync = require ( 'child_process' ) . execSync ;
21
20
const uuid = require ( 'uuid/v4' ) ;
22
-
23
21
const cmd = 'node detect.v2beta1.js' ;
24
- const { cwd} = path . join ( __dirname , '..' ) ;
25
22
const testQuery = 'Where is my data stored?' ;
26
23
const testKnowledgeBaseName = `${ uuid ( ) . split ( '-' ) [ 0 ] } -TestKnowledgeBase` ;
27
24
const testDocName = 'TestDoc' ;
28
25
const testDocumentPath = 'https://cloud.google.com/storage/docs/faq' ;
29
26
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' } ) ;
37
28
38
29
describe ( 'v2beta1 detection' , ( ) => {
39
30
let knowbaseFullName ;
@@ -42,11 +33,11 @@ describe('v2beta1 detection', () => {
42
33
43
34
it ( 'should create a knowledge base' , async ( ) => {
44
35
// Check that the knowledge base does not yet exist
45
- let output = await exec ( `${ cmd } listKnowledgeBases` ) ;
36
+ let output = exec ( `${ cmd } listKnowledgeBases` ) ;
46
37
assert . notInclude ( output , testKnowledgeBaseName ) ;
47
38
48
39
// Creates a knowledge base
49
- output = await exec (
40
+ output = exec (
50
41
`${ cmd } createKnowledgeBase -k ${ testKnowledgeBaseName } `
51
42
) ;
52
43
assert . include ( output , `displayName: ${ testKnowledgeBaseName } ` ) ;
@@ -62,66 +53,66 @@ describe('v2beta1 detection', () => {
62
53
} ) ;
63
54
64
55
it ( 'should list the knowledge bases' , async ( ) => {
65
- const output = await exec ( `${ cmd } listKnowledgeBases` ) ;
56
+ const output = exec ( `${ cmd } listKnowledgeBases` ) ;
66
57
assert . include ( output , testKnowledgeBaseName ) ;
67
58
} ) ;
68
59
69
60
it ( 'should get a knowledge base' , async ( ) => {
70
- const output = await exec ( `${ cmd } getKnowledgeBase -b "${ knowbaseId } "` ) ;
61
+ const output = exec ( `${ cmd } getKnowledgeBase -b "${ knowbaseId } "` ) ;
71
62
assert . include ( output , `displayName: ${ testKnowledgeBaseName } ` ) ;
72
63
assert . include ( output , `name: ${ knowbaseFullName } ` ) ;
73
64
} ) ;
74
65
75
66
it ( 'should create a document' , async ( ) => {
76
- const output = await exec (
67
+ const output = exec (
77
68
`${ cmd } createDocument -n "${ knowbaseFullName } " -z "${ testDocumentPath } " -m "${ testDocName } "`
78
69
) ;
79
70
assert . include ( output , 'Document created' ) ;
80
71
} ) ;
81
72
82
73
it ( 'should list documents' , async ( ) => {
83
- const output = await exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
74
+ const output = exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
84
75
const parsedOut = output . split ( '\n' ) ;
85
76
documentFullPath = parsedOut [ parsedOut . length - 1 ] . split ( ':' ) [ 1 ] ;
86
77
assert . include ( output , `There are 1 documents in ${ knowbaseFullName } ` ) ;
87
78
} ) ;
88
79
89
80
it ( 'should detect intent with a knowledge base' , async ( ) => {
90
- const output = await exec (
81
+ const output = exec (
91
82
`${ cmd } detectIntentKnowledge -q "${ testQuery } " -n "${ knowbaseId } "`
92
83
) ;
93
84
assert . include ( output , 'Detected Intent:' ) ;
94
85
} ) ;
95
86
96
87
it ( 'should delete a document' , async ( ) => {
97
- const output = await exec ( `${ cmd } deleteDocument -d ${ documentFullPath } ` ) ;
88
+ const output = exec ( `${ cmd } deleteDocument -d ${ documentFullPath } ` ) ;
98
89
assert . include ( output , 'document deleted' ) ;
99
90
} ) ;
100
91
101
92
it ( 'should list the document' , async ( ) => {
102
- const output = await exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
93
+ const output = exec ( `${ cmd } listDocuments -n "${ knowbaseFullName } "` ) ;
103
94
assert . notInclude ( output , documentFullPath ) ;
104
95
} ) ;
105
96
106
97
it ( 'should delete the Knowledge Base' , async ( ) => {
107
- await exec ( `${ cmd } deleteKnowledgeBase -n "${ knowbaseFullName } "` ) ;
98
+ exec ( `${ cmd } deleteKnowledgeBase -n "${ knowbaseFullName } "` ) ;
108
99
} ) ;
109
100
110
101
it ( 'should list the Knowledge Base' , async ( ) => {
111
- const output = await exec ( `${ cmd } listKnowledgeBases` ) ;
102
+ const output = exec ( `${ cmd } listKnowledgeBases` ) ;
112
103
assert . notInclude ( output , testKnowledgeBaseName ) ;
113
104
} ) ;
114
105
115
106
it ( 'should detect Intent with Model Selection' , async ( ) => {
116
- const output = await exec ( `${ cmd } detectIntentwithModelSelection` ) ;
107
+ const output = exec ( `${ cmd } detectIntentwithModelSelection` ) ;
117
108
assert . include (
118
109
output ,
119
110
'Response: I can help with that. Where would you like to reserve a room?'
120
111
) ;
121
112
} ) ;
122
113
123
114
it ( 'should detect Intent with Text to Speech Response' , async ( ) => {
124
- const output = await exec (
115
+ const output = exec (
125
116
`${ cmd } detectIntentwithTexttoSpeechResponse -q "${ testQuery } "`
126
117
) ;
127
118
assert . include (
@@ -131,7 +122,7 @@ describe('v2beta1 detection', () => {
131
122
} ) ;
132
123
133
124
it ( 'should detect sentiment with intent' , async ( ) => {
134
- const output = await exec (
125
+ const output = exec (
135
126
`${ cmd } detectIntentandSentiment -q "${ testQuery } "`
136
127
) ;
137
128
assert . include ( output , 'Detected sentiment' ) ;
0 commit comments