Skip to content

Commit

Permalink
chore: update format and sample tests (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jul 15, 2019
1 parent a5decaf commit 9117c2d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 36 deletions.
16 changes: 9 additions & 7 deletions dialogflow/detect.v2beta1.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,15 @@ async function detectIntentKnowledge(
console.log(`Detected Intent: ${result.intent.displayName}`);
console.log(`Confidence: ${result.intentDetectionConfidence}`);
console.log(`Query Result: ${result.fulfillmentText}`);
const answers = result.knowledgeAnswers.answers;
console.log(`There are ${answers.length} answer(s);`);
answers.forEach(a => {
console.log(` answer: ${a.answer}`);
console.log(` confidence: ${a.matchConfidence}`);
console.log(` match confidence level: ${a.matchConfidenceLevel}`);
});
if (result.knowledgeAnswers && result.knowledgeAnswers.answers) {
const answers = result.knowledgeAnswers.answers;
console.log(`There are ${answers.length} answer(s);`);
answers.forEach(a => {
console.log(` answer: ${a.answer}`);
console.log(` confidence: ${a.matchConfidence}`);
console.log(` match confidence level: ${a.matchConfidenceLevel}`);
});
}
// [END dialogflow_detect_intent_knowledge]
}

Expand Down
9 changes: 4 additions & 5 deletions dialogflow/system-test/detect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,19 @@ describe('basic detection', () => {
});

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

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

it('should detect Intent with Text to Speech Response', async () => {
const stdout = exec(
`${cmd_tts} ${projectId} 'SESSION_ID' '${testQuery}' 'en-US' './resources/output.wav'`);
`${cmd_tts} ${projectId} 'SESSION_ID' '${testQuery}' 'en-US' './resources/output.wav'`
);
assert.include(
stdout,
'Audio content written to file: ./resources/output.wav'
Expand Down
40 changes: 19 additions & 21 deletions dialogflow/system-test/detect.v2beta1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
'use strict';

const {assert} = require('chai');
const execSync = require('child_process').execSync;
const {execSync} = require('child_process');
const uuid = require('uuid/v4');

const cmd = 'node detect.v2beta1.js';
const testQuery = 'Where is my data stored?';
const testKnowledgeBaseName = `${uuid().split('-')[0]}-TestKnowledgeBase`;
Expand All @@ -31,15 +32,13 @@ describe('v2beta1 detection', () => {
let knowbaseId;
let documentFullPath;

it('should create a knowledge base', async () => {
it('should create a knowledge base', () => {
// Check that the knowledge base does not yet exist
let output = exec(`${cmd} listKnowledgeBases`);
assert.notInclude(output, testKnowledgeBaseName);

// Creates a knowledge base
output = exec(
`${cmd} createKnowledgeBase -k ${testKnowledgeBaseName}`
);
output = exec(`${cmd} createKnowledgeBase -k ${testKnowledgeBaseName}`);
assert.include(output, `displayName: ${testKnowledgeBaseName}`);

knowbaseFullName = output
Expand All @@ -52,66 +51,67 @@ describe('v2beta1 detection', () => {
.trim();
});

it('should list the knowledge bases', async () => {
it('should list the knowledge bases', () => {
const output = exec(`${cmd} listKnowledgeBases`);
assert.include(output, testKnowledgeBaseName);
});

it('should get a knowledge base', async () => {
it('should get a knowledge base', () => {
const output = exec(`${cmd} getKnowledgeBase -b "${knowbaseId}"`);
assert.include(output, `displayName: ${testKnowledgeBaseName}`);
assert.include(output, `name: ${knowbaseFullName}`);
});

it('should create a document', async () => {
it('should create a document', () => {
const output = exec(
`${cmd} createDocument -n "${knowbaseFullName}" -z "${testDocumentPath}" -m "${testDocName}"`
);
assert.include(output, 'Document created');
});

it('should list documents', async () => {
it('should list documents', () => {
const output = exec(`${cmd} listDocuments -n "${knowbaseFullName}"`);
const parsedOut = output.split('\n');
const parsedOut = output.split('\n').filter(x => !!x.trim());
documentFullPath = parsedOut[parsedOut.length - 1].split(':')[1];
assert.isDefined(documentFullPath);
assert.include(output, `There are 1 documents in ${knowbaseFullName}`);
});

it('should detect intent with a knowledge base', async () => {
it('should detect intent with a knowledge base', () => {
const output = exec(
`${cmd} detectIntentKnowledge -q "${testQuery}" -n "${knowbaseId}"`
);
assert.include(output, 'Detected Intent:');
});

it('should delete a document', async () => {
it('should delete a document', () => {
const output = exec(`${cmd} deleteDocument -d ${documentFullPath}`);
assert.include(output, 'document deleted');
});

it('should list the document', async () => {
it('should list the document', () => {
const output = exec(`${cmd} listDocuments -n "${knowbaseFullName}"`);
assert.notInclude(output, documentFullPath);
});

it('should delete the Knowledge Base', async () => {
it('should delete the Knowledge Base', () => {
exec(`${cmd} deleteKnowledgeBase -n "${knowbaseFullName}"`);
});

it('should list the Knowledge Base', async () => {
it('should list the Knowledge Base', () => {
const output = exec(`${cmd} listKnowledgeBases`);
assert.notInclude(output, testKnowledgeBaseName);
});

it('should detect Intent with Model Selection', async () => {
it('should detect Intent with Model Selection', () => {
const output = exec(`${cmd} detectIntentwithModelSelection`);
assert.include(
output,
'Response: I can help with that. Where would you like to reserve a room?'
);
});

it('should detect Intent with Text to Speech Response', async () => {
it('should detect Intent with Text to Speech Response', () => {
const output = exec(
`${cmd} detectIntentwithTexttoSpeechResponse -q "${testQuery}"`
);
Expand All @@ -121,10 +121,8 @@ describe('v2beta1 detection', () => {
);
});

it('should detect sentiment with intent', async () => {
const output = exec(
`${cmd} detectIntentandSentiment -q "${testQuery}"`
);
it('should detect sentiment with intent', () => {
const output = exec(`${cmd} detectIntentandSentiment -q "${testQuery}"`);
assert.include(output, 'Detected sentiment');
});
});
4 changes: 1 addition & 3 deletions dialogflow/system-test/resource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ describe('resources', () => {
});

it('should List the Session Entity Type', async () => {
const output = exec(
`${cmd} list-session-entity-types -s ${sessionId}`
);
const output = exec(`${cmd} list-session-entity-types -s ${sessionId}`);
assert.include(output, sessionId);
assert.include(output, displayName);
assert.include(output, '2');
Expand Down

0 comments on commit 9117c2d

Please sign in to comment.