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