Skip to content

Commit 9117c2d

Browse files
chore: update format and sample tests (#383)
1 parent a5decaf commit 9117c2d

File tree

4 files changed

+33
-36
lines changed

4 files changed

+33
-36
lines changed

dialogflow/detect.v2beta1.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,15 @@ async function detectIntentKnowledge(
417417
console.log(`Detected Intent: ${result.intent.displayName}`);
418418
console.log(`Confidence: ${result.intentDetectionConfidence}`);
419419
console.log(`Query Result: ${result.fulfillmentText}`);
420-
const answers = result.knowledgeAnswers.answers;
421-
console.log(`There are ${answers.length} answer(s);`);
422-
answers.forEach(a => {
423-
console.log(` answer: ${a.answer}`);
424-
console.log(` confidence: ${a.matchConfidence}`);
425-
console.log(` match confidence level: ${a.matchConfidenceLevel}`);
426-
});
420+
if (result.knowledgeAnswers && result.knowledgeAnswers.answers) {
421+
const answers = result.knowledgeAnswers.answers;
422+
console.log(`There are ${answers.length} answer(s);`);
423+
answers.forEach(a => {
424+
console.log(` answer: ${a.answer}`);
425+
console.log(` confidence: ${a.matchConfidence}`);
426+
console.log(` match confidence level: ${a.matchConfidenceLevel}`);
427+
});
428+
}
427429
// [END dialogflow_detect_intent_knowledge]
428430
}
429431

dialogflow/system-test/detect.test.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,19 @@ describe('basic detection', () => {
4343
});
4444

4545
it('should detect audio query', async () => {
46-
const stdout = exec(
47-
`${cmd} audio ${audioFilepathBookARoom} -r 16000`);
46+
const stdout = exec(`${cmd} audio ${audioFilepathBookARoom} -r 16000`);
4847
assert.include(stdout, 'Detected intent');
4948
});
5049

5150
it('should detect audio query in streaming fashion', async () => {
52-
const stdout = exec(
53-
`${cmd} stream ${audioFilepathBookARoom} -r 16000`);
51+
const stdout = exec(`${cmd} stream ${audioFilepathBookARoom} -r 16000`);
5452
assert.include(stdout, 'Detected intent');
5553
});
5654

5755
it('should detect Intent with Text to Speech Response', async () => {
5856
const stdout = exec(
59-
`${cmd_tts} ${projectId} 'SESSION_ID' '${testQuery}' 'en-US' './resources/output.wav'`);
57+
`${cmd_tts} ${projectId} 'SESSION_ID' '${testQuery}' 'en-US' './resources/output.wav'`
58+
);
6059
assert.include(
6160
stdout,
6261
'Audio content written to file: ./resources/output.wav'

dialogflow/system-test/detect.v2beta1.test.js

+19-21
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
'use strict';
1717

1818
const {assert} = require('chai');
19-
const execSync = require('child_process').execSync;
19+
const {execSync} = require('child_process');
2020
const uuid = require('uuid/v4');
21+
2122
const cmd = 'node detect.v2beta1.js';
2223
const testQuery = 'Where is my data stored?';
2324
const 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
});

dialogflow/system-test/resource.test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ describe('resources', () => {
159159
});
160160

161161
it('should List the Session Entity Type', async () => {
162-
const output = exec(
163-
`${cmd} list-session-entity-types -s ${sessionId}`
164-
);
162+
const output = exec(`${cmd} list-session-entity-types -s ${sessionId}`);
165163
assert.include(output, sessionId);
166164
assert.include(output, displayName);
167165
assert.include(output, '2');

0 commit comments

Comments
 (0)