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