diff --git a/dialogflow/package.json b/dialogflow/package.json index 78ad05a785..f298c98ebf 100644 --- a/dialogflow/package.json +++ b/dialogflow/package.json @@ -5,12 +5,15 @@ "license": "Apache-2.0", "author": "Google LLC", "repository": "googleapis/nodejs-dialogflow", - "files": [ "*.js", "resources" ], + "files": [ + "*.js", + "resources" + ], "engines": { "node": ">=8.0.0" }, "scripts": { - "test": "ava system-test" + "test": "mocha system-test/*.test.js --timeout=600000" }, "dependencies": { "dialogflow": "^0.7.0", @@ -22,6 +25,6 @@ }, "devDependencies": { "@google-cloud/nodejs-repo-tools": "^3.0.0", - "ava": "^0.25.0" + "mocha": "^5.2.0" } } diff --git a/dialogflow/system-test/.eslintrc.yml b/dialogflow/system-test/.eslintrc.yml new file mode 100644 index 0000000000..6db2a46c53 --- /dev/null +++ b/dialogflow/system-test/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +env: + mocha: true diff --git a/dialogflow/system-test/detect_test.js b/dialogflow/system-test/detect.test.js similarity index 51% rename from dialogflow/system-test/detect_test.js rename to dialogflow/system-test/detect.test.js index 7fe92885ad..e3806d5e31 100644 --- a/dialogflow/system-test/detect_test.js +++ b/dialogflow/system-test/detect.test.js @@ -16,34 +16,37 @@ 'use strict'; const path = require('path'); -const test = require('ava'); +const assert = require('assert'); const {runAsync} = require('@google-cloud/nodejs-repo-tools'); const cmd = 'node detect.js'; +const cwd = path.join(__dirname, '..'); const audioFilepathBookARoom = path - .join(__dirname, `../resources/book_a_room.wav`) + .join(__dirname, '../resources/book_a_room.wav') .replace(/(\s+)/g, '\\$1'); -test('Should detect text queries', async t => { - const output = await runAsync(`${cmd} text -q "hello"`); - t.true(output.includes('Detected intent')); +it('Should detect text queries', async () => { + const output = await runAsync(`${cmd} text -q "hello"`, cwd); + assert.strictEqual(output.includes('Detected intent'), true); }); -test('Should detect event query', async t => { - const output = await runAsync(`${cmd} event WELCOME`); - t.true(output.includes('Query: WELCOME')); +it('Should detect event query', async () => { + const output = await runAsync(`${cmd} event WELCOME`, cwd); + assert.strictEqual(output.includes('Query: WELCOME'), true); }); -test('Should detect audio query', async t => { +it('Should detect audio query', async () => { const output = await runAsync( - `${cmd} audio ${audioFilepathBookARoom} -r 16000` + `${cmd} audio ${audioFilepathBookARoom} -r 16000`, + cwd ); - t.true(output.includes('Detected intent')); + assert.strictEqual(output.includes('Detected intent'), true); }); -test('Should detect audio query in streaming fashion', async t => { +it('Should detect audio query in streaming fashion', async () => { const output = await runAsync( - `${cmd} stream ${audioFilepathBookARoom} -r 16000` + `${cmd} stream ${audioFilepathBookARoom} -r 16000`, + cwd ); - t.true(output.includes('Detected intent')); + assert.strictEqual(output.includes('Detected intent'), true); }); diff --git a/dialogflow/system-test/detect.v2beta1.test.js b/dialogflow/system-test/detect.v2beta1.test.js index 4a7eac5d0b..fec725c2e2 100644 --- a/dialogflow/system-test/detect.v2beta1.test.js +++ b/dialogflow/system-test/detect.v2beta1.test.js @@ -15,101 +15,120 @@ 'use strict'; -const test = require(`ava`); +const path = require('path'); +const assert = require('assert'); const {runAsync} = require('@google-cloud/nodejs-repo-tools'); const uuid = require('uuid/v4'); const cmd = 'node detect.v2beta1.js'; -const testQuery = `Where is my data stored?`; +const cwd = path.join(__dirname, '..'); +const testQuery = 'Where is my data stored?'; const testKnowledgeBaseName = `${uuid().split('-')[0]}-TestKnowledgeBase`; -const testDocName = `TestDoc`; -const testDocumentPath = `https://cloud.google.com/storage/docs/faq`; +const testDocName = 'TestDoc'; +const testDocumentPath = 'https://cloud.google.com/storage/docs/faq'; -test.serial(`It should create a knowledge base`, async t => { +it('It should create a knowledge base', async () => { // Check that the knowledge base does not yet exist - let output = await runAsync(`${cmd} listKnowledgeBases`); - t.false(output.includes(testKnowledgeBaseName)); + let output = await runAsync(`${cmd} listKnowledgeBases`, cwd); + assert.strictEqual(output.includes(testKnowledgeBaseName), false); // Creates a knowledge base output = await runAsync( - `${cmd} createKnowledgeBase -k ${testKnowledgeBaseName}` + `${cmd} createKnowledgeBase -k ${testKnowledgeBaseName}`, + cwd + ); + assert.strictEqual( + output.includes(`displayName: ${testKnowledgeBaseName}`), + true ); - t.true(output.includes(`displayName: ${testKnowledgeBaseName}`)); const knowbaseFullName = output - .split(`\n`)[0] - .split(`:`)[1] + .split('\n')[0] + .split(':')[1] .trim(); const knowbaseId = output - .split(`\n`)[0] - .split(`knowledgeBases/`)[1] + .split('\n')[0] + .split('knowledgeBases/')[1] .trim(); // List the knowledge base - output = await runAsync(`${cmd} listKnowledgeBases`); - t.true(output.includes(testKnowledgeBaseName)); + output = await runAsync(`${cmd} listKnowledgeBases`, cwd); + assert.strictEqual(output.includes(testKnowledgeBaseName), true); // Get the knowledge base - output = await runAsync(`${cmd} getKnowledgeBase -b "${knowbaseId}"`); - t.true(output.includes(`displayName: ${testKnowledgeBaseName}`)); - t.true(output.includes(`name: ${knowbaseFullName}`)); + output = await runAsync(`${cmd} getKnowledgeBase -b "${knowbaseId}"`, cwd); + assert.strictEqual( + output.includes(`displayName: ${testKnowledgeBaseName}`), + true + ); + assert.strictEqual(output.includes(`name: ${knowbaseFullName}`), true); // Create a document output = await runAsync( - `${cmd} createDocument -n "${knowbaseFullName}" -z "${testDocumentPath}" -m "${testDocName}"` + `${cmd} createDocument -n "${knowbaseFullName}" -z "${testDocumentPath}" -m "${testDocName}"`, + cwd ); - t.true(output.includes(`Document created`)); + assert.strictEqual(output.includes('Document created'), true); // List the Document output = await runAsync(`${cmd} listDocuments -n "${knowbaseFullName}"`); - const parsedOut = output.split(`\n`); - const documentFullPath = parsedOut[parsedOut.length - 1].split(`:`)[1]; - t.true(output.includes(`There are 1 documents in ${knowbaseFullName}`)); + const parsedOut = output.split('\n'); + const documentFullPath = parsedOut[parsedOut.length - 1].split(':')[1]; + assert.strictEqual( + output.includes(`There are 1 documents in ${knowbaseFullName}`), + true + ); // Detect intent with Knowledge Base output = await runAsync( - `${cmd} detectIntentKnowledge -q "${testQuery}" -n "${knowbaseId}"` + `${cmd} detectIntentKnowledge -q "${testQuery}" -n "${knowbaseId}"`, + cwd ); - t.true(output.includes(`Detected Intent:`)); + assert.strictEqual(output.includes('Detected Intent:'), true); // Delete the Document - output = await runAsync(`${cmd} deleteDocument -d ${documentFullPath}`); - t.true(output.includes(`document deleted`)); + output = await runAsync(`${cmd} deleteDocument -d ${documentFullPath}`, cwd); + assert.strictEqual(output.includes('document deleted'), true); // List the Document - output = await runAsync(`${cmd} listDocuments -n "${knowbaseFullName}"`); - t.false(output.includes(documentFullPath)); + output = await runAsync(`${cmd} listDocuments -n "${knowbaseFullName}"`, cwd); + assert.strictEqual(output.includes(documentFullPath), false); // Delete the Knowledge Base output = await runAsync( - `${cmd} deleteKnowledgeBase -n "${knowbaseFullName}"` + `${cmd} deleteKnowledgeBase -n "${knowbaseFullName}"`, + cwd ); // List the Knowledge Base - output = await runAsync(`${cmd} listKnowledgeBases`); - t.false(output.includes(testKnowledgeBaseName)); + output = await runAsync(`${cmd} listKnowledgeBases`, cwd); + assert.strictEqual(output.includes(testKnowledgeBaseName), false); }); -test(`It should detect Intent with Model Selection`, async t => { - const output = await runAsync(`${cmd} detectIntentwithModelSelection`); - t.true( +it('It should detect Intent with Model Selection', async () => { + const output = await runAsync(`${cmd} detectIntentwithModelSelection`, cwd); + assert.strictEqual( output.includes( - `Response: I can help with that. Where would you like to reserve a room?` - ) + 'Response: I can help with that. Where would you like to reserve a room?' + ), + true ); }); -test(`It should detect Intent with Text to Speech Response`, async t => { +it('It should detect Intent with Text to Speech Response', async () => { const output = await runAsync( - `${cmd} detectIntentwithTexttoSpeechResponse -q "${testQuery}"` + `${cmd} detectIntentwithTexttoSpeechResponse -q "${testQuery}"`, + cwd ); - t.true( - output.includes(`Audio content written to file: ./resources/output.wav`) + assert.strictEqual( + output.includes('Audio content written to file: ./resources/output.wav'), + true ); }); -test(`It should detect sentiment with intent`, async t => { +it('It should detect sentiment with intent', async () => { const output = await runAsync( - `${cmd} detectIntentandSentiment -q "${testQuery}"` + `${cmd} detectIntentandSentiment -q "${testQuery}"`, + cwd ); - t.true(output.includes(`Detected sentiment`)); + assert.strictEqual(output.includes('Detected sentiment'), true); }); diff --git a/dialogflow/system-test/resource.test.js b/dialogflow/system-test/resource.test.js new file mode 100644 index 0000000000..5102639a7a --- /dev/null +++ b/dialogflow/system-test/resource.test.js @@ -0,0 +1,194 @@ +/** + * Copyright 2018, Google, Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +const path = require('path'); +const assert = require('assert'); +const tools = require('@google-cloud/nodejs-repo-tools'); + +const cmd = 'node resource.js'; +const cwd = path.join(__dirname, '..'); +const sessionId = require('uuid/v1')(); +const contextName = 'fake_context_name'; +const displayName = 'fake_display_name'; +const entityName = 'fake_entity'; +const synonym1 = 'synonym_1'; +const synonym2 = 'synonym_2'; +const phrase1 = 'training_phrase_1'; +const phrase2 = 'training_phrase_2'; +const message1 = 'message_1'; +const message2 = 'message_2'; + +it('Test creating / listing / deleting a context.', async () => { + let output = await tools.runAsync( + `${cmd} create-context -s ${sessionId} -c ${contextName} -l 3`, + cwd + ); + assert.strictEqual(output.includes(sessionId), true); + assert.strictEqual(output.includes(contextName), true); + + output = await tools.runAsync(`${cmd} list-contexts -s ${sessionId}`, cwd); + assert.strictEqual(output.includes(sessionId), true); + assert.strictEqual(output.includes(contextName), true); + assert.strictEqual(output.includes('3'), true); + + output = await tools.runAsync( + `${cmd} delete-context -s ${sessionId} -c ${contextName}`, + cwd + ); + assert.strictEqual(output.includes(sessionId), true); + assert.strictEqual(output.includes(contextName), true); + + output = await tools.runAsync(`${cmd} list-contexts -s ${sessionId}`, cwd); + assert.strictEqual(output.includes(sessionId), false); + assert.strictEqual(output.includes(contextName), false); +}); + +it('Test creating / listing / deleting a entity type and entity.', async () => { + // Create the Entity Type + let output = await tools.runAsync( + `${cmd} create-entity-type -d ${displayName} -k KIND_MAP`, + cwd + ); + assert.strictEqual(output.includes('entityTypes'), true); + + const entityTypeId = output.split(' ')[1].split('/')[4]; + + // List the Entity Type + output = await tools.runAsync(`${cmd} list-entity-types`, cwd); + assert.strictEqual(output.includes(displayName), true); + assert.strictEqual(output.includes(entityTypeId), true); + + // Create an Entity for the Entity Type + output = await tools.runAsync( + `${cmd} create-entity -e ${entityTypeId} -v ${entityName} -s ${synonym1} -s ${synonym2}`, + cwd + ); + + // List the Entity + output = await tools.runAsync(`${cmd} list-entities -e ${entityTypeId}`, cwd); + assert.strictEqual(output.includes(entityName), true); + assert.strictEqual(output.includes(synonym1), true); + assert.strictEqual(output.includes(synonym2), true); + + // Delete the Entity + output = await tools.runAsync( + `${cmd} delete-entity -e ${entityTypeId} -v ${entityName}`, + cwd + ); + assert.strictEqual(output.includes(entityName), true); + + // Verify the Entity is Deleted + output = await tools.runAsync(`${cmd} list-entities -e ${entityTypeId}`, cwd); + assert.strictEqual(output.includes(entityName), false); + assert.strictEqual(output.includes(synonym1), false); + assert.strictEqual(output.includes(synonym2), false); + + // Delete the Entity Type + output = await tools.runAsync( + `${cmd} delete-entity-type -e ${entityTypeId}`, + cwd + ); + assert.strictEqual(output.includes(entityTypeId), true); + + // Verify the Entity Type is Deleted + output = await tools.runAsync(`${cmd} list-entity-types`, cwd); + assert.strictEqual(output.includes(displayName), false); + assert.strictEqual(output.includes(entityTypeId), false); +}); + +it('Test creating / listing / deleting a intent.', async () => { + let output = await tools.runAsync( + `${cmd} create-intent -d ${displayName} -t ${phrase1} -t ${phrase2} -m ${message1} -m ${message2}`, + cwd + ); + assert.strictEqual(output.includes('intents'), true); + const intentId = output.split(' ')[1].split('/')[4]; + + output = await tools.runAsync(`${cmd} list-intents`, cwd); + assert.strictEqual(output.includes(intentId), true); + assert.strictEqual(output.includes(displayName), true); + + output = await tools.runAsync(`${cmd} delete-intent -i ${intentId}`, cwd); + assert.strictEqual(output.includes(intentId), true); + + output = await tools.runAsync(`${cmd} list-intents`, cwd); + assert.strictEqual(output.includes(intentId), false); + assert.strictEqual(output.includes(displayName), false); +}); + +it('Test creating / listing / deleting a session entity type', async () => { + // Create the Entity Type + let output = await tools.runAsync( + `${cmd} create-entity-type -d ${displayName} -k KIND_MAP`, + cwd + ); + assert.strictEqual(output.includes('entityTypes'), true); + + const entityTypeId = output.split(' ')[1].split('/')[4]; + + // List the Entity Type + output = await tools.runAsync(`${cmd} list-entity-types`, cwd); + assert.strictEqual(output.includes(displayName), true); + assert.strictEqual(output.includes(entityTypeId), true); + + // Create a Session Entity Type + output = await tools.runAsync( + `${cmd} create-session-entity-type -s ${sessionId} -e ${synonym1} -e ${synonym2} -d ${displayName} -o ENTITY_OVERRIDE_MODE_OVERRIDE`, + cwd + ); + assert.strictEqual(output.includes(sessionId), true); + assert.strictEqual(output.includes(displayName), true); + assert.strictEqual(output.includes(synonym1), true); + assert.strictEqual(output.includes(synonym2), true); + + // List the Session Entity Type + output = await tools.runAsync( + `${cmd} list-session-entity-types -s ${sessionId}`, + cwd + ); + assert.strictEqual(output.includes(sessionId), true); + assert.strictEqual(output.includes(displayName), true); + assert.strictEqual(output.includes('2'), true); + + // Delete the Session Entity Type + output = await tools.runAsync( + `${cmd} delete-session-entity-type -s ${sessionId} -d ${displayName}`, + cwd + ); + assert.strictEqual(output.includes(displayName), true); + + // Verify the Session Entity Type is Deleted + output = await tools.runAsync( + `${cmd} list-session-entity-types -s ${sessionId}`, + cwd + ); + assert.strictEqual(output.includes(sessionId), false); + assert.strictEqual(output.includes(displayName), false); + assert.strictEqual(output.includes('2'), false); + + // Delete the Entity Type + output = await tools.runAsync( + `${cmd} delete-entity-type -e ${entityTypeId}`, + cwd + ); + assert.strictEqual(output.includes(entityTypeId), true); + + // Verify the Entity Type is Deleted + output = await tools.runAsync(`${cmd} list-entity-types`, cwd); + assert.strictEqual(output.includes(displayName), false); + assert.strictEqual(output.includes(entityTypeId), false); +}); diff --git a/dialogflow/system-test/resource_test.js b/dialogflow/system-test/resource_test.js deleted file mode 100644 index d1a8a8cd8a..0000000000 --- a/dialogflow/system-test/resource_test.js +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -const cmd = 'node resource.js'; -const sessionId = require('uuid/v1')(); -const contextName = 'fake_context_name'; -const displayName = 'fake_display_name'; -const entityName = 'fake_entity'; -const synonym1 = 'synonym_1'; -const synonym2 = 'synonym_2'; -const phrase1 = 'training_phrase_1'; -const phrase2 = 'training_phrase_2'; -const message1 = 'message_1'; -const message2 = 'message_2'; - -test.serial('Test creating / listing / deleting a context.', async t => { - let output = await tools.runAsync( - `${cmd} create-context -s ${sessionId} -c ${contextName} -l 3` - ); - t.true(output.includes(sessionId)); - t.true(output.includes(contextName)); - - output = await tools.runAsync(`${cmd} list-contexts -s ${sessionId}`); - t.true(output.includes(sessionId)); - t.true(output.includes(contextName)); - t.true(output.includes('3')); - - output = await tools.runAsync( - `${cmd} delete-context -s ${sessionId} -c ${contextName}` - ); - t.true(output.includes(sessionId)); - t.true(output.includes(contextName)); - - output = await tools.runAsync(`${cmd} list-contexts -s ${sessionId}`); - t.false(output.includes(sessionId)); - t.false(output.includes(contextName)); -}); - -test.serial( - 'Test creating / listing / deleting a entity type and entity.', - async t => { - // Create the Entity Type - let output = await tools.runAsync( - `${cmd} create-entity-type -d ${displayName} -k KIND_MAP` - ); - t.true(output.includes('entityTypes')); - - const entityTypeId = output.split(' ')[1].split('/')[4]; - - // List the Entity Type - output = await tools.runAsync(`${cmd} list-entity-types`); - t.true(output.includes(displayName)); - t.true(output.includes(entityTypeId)); - - // Create an Entity for the Entity Type - output = await tools.runAsync( - `${cmd} create-entity -e ${entityTypeId} -v ${entityName} -s ${synonym1} -s ${synonym2}` - ); - - // List the Entity - output = await tools.runAsync(`${cmd} list-entities -e ${entityTypeId}`); - t.true(output.includes(entityName)); - t.true(output.includes(synonym1)); - t.true(output.includes(synonym2)); - - // Delete the Entity - output = await tools.runAsync( - `${cmd} delete-entity -e ${entityTypeId} -v ${entityName}` - ); - t.true(output.includes(entityName)); - - // Verify the Entity is Deleted - output = await tools.runAsync(`${cmd} list-entities -e ${entityTypeId}`); - t.false(output.includes(entityName)); - t.false(output.includes(synonym1)); - t.false(output.includes(synonym2)); - - // Delete the Entity Type - output = await tools.runAsync( - `${cmd} delete-entity-type -e ${entityTypeId}` - ); - t.true(output.includes(entityTypeId)); - - // Verify the Entity Type is Deleted - output = await tools.runAsync(`${cmd} list-entity-types`); - t.false(output.includes(displayName)); - t.false(output.includes(entityTypeId)); - } -); - -test.serial('Test creating / listing / deleting a intent.', async t => { - let output = await tools.runAsync( - `${cmd} create-intent -d ${displayName} -t ${phrase1} -t ${phrase2} -m ${message1} -m ${message2}` - ); - t.true(output.includes('intents')); - const intentId = output.split(' ')[1].split('/')[4]; - - output = await tools.runAsync(`${cmd} list-intents`); - t.true(output.includes(intentId)); - t.true(output.includes(displayName)); - - output = await tools.runAsync(`${cmd} delete-intent -i ${intentId}`); - t.true(output.includes(intentId)); - - output = await tools.runAsync(`${cmd} list-intents`); - t.false(output.includes(intentId)); - t.false(output.includes(displayName)); -}); - -test.serial( - 'Test creating / listing / deleting a session entity type', - async t => { - // Create the Entity Type - let output = await tools.runAsync( - `${cmd} create-entity-type -d ${displayName} -k KIND_MAP` - ); - t.true(output.includes('entityTypes')); - - const entityTypeId = output.split(' ')[1].split('/')[4]; - - // List the Entity Type - output = await tools.runAsync(`${cmd} list-entity-types`); - t.true(output.includes(displayName)); - t.true(output.includes(entityTypeId)); - - // Create a Session Entity Type - output = await tools.runAsync( - `${cmd} create-session-entity-type -s ${sessionId} -e ${synonym1} -e ${synonym2} -d ${displayName} -o ENTITY_OVERRIDE_MODE_OVERRIDE` - ); - t.true(output.includes(sessionId)); - t.true(output.includes(displayName)); - t.true(output.includes(synonym1)); - t.true(output.includes(synonym2)); - - // List the Session Entity Type - output = await tools.runAsync( - `${cmd} list-session-entity-types -s ${sessionId}` - ); - t.true(output.includes(sessionId)); - t.true(output.includes(displayName)); - t.true(output.includes('2')); - - // Delete the Session Entity Type - output = await tools.runAsync( - `${cmd} delete-session-entity-type -s ${sessionId} -d ${displayName}` - ); - t.true(output.includes(displayName)); - - // Verify the Session Entity Type is Deleted - output = await tools.runAsync( - `${cmd} list-session-entity-types -s ${sessionId}` - ); - t.false(output.includes(sessionId)); - t.false(output.includes(displayName)); - t.false(output.includes('2')); - - // Delete the Entity Type - output = await tools.runAsync( - `${cmd} delete-entity-type -e ${entityTypeId}` - ); - t.true(output.includes(entityTypeId)); - - // Verify the Entity Type is Deleted - output = await tools.runAsync(`${cmd} list-entity-types`); - t.false(output.includes(displayName)); - t.false(output.includes(entityTypeId)); - } -);