Skip to content

Commit 5e314b4

Browse files
galz10Ace Nassri
authored and
Ace Nassri
committed
docs: add filter code sample (#179)
1 parent f5f9c1a commit 5e314b4

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function main(projectId, agentId, testId, location) {
18+
/**
19+
* TODO(developer): Uncomment these variables before running the sample.
20+
*/
21+
// const projectId = 'my-project';
22+
// const agentId = 'my-agent';
23+
// const testId = 'my-flow';
24+
// const location = 'global';
25+
26+
// [START dialogflow_cx_list_testcase_sample]
27+
const parent = `projects/${projectId}/locations/${location}/agents/${agentId}/testCases/${testId}`;
28+
29+
const {TestCasesClient} = require('@google-cloud/dialogflow-cx');
30+
31+
const client = new TestCasesClient({
32+
apiEndpoint: 'global-dialogflow.googleapis.com',
33+
});
34+
const req = {
35+
parent,
36+
filter: 'environment=draft',
37+
};
38+
39+
const res = await client.listTestCaseResults(req);
40+
41+
console.log(res);
42+
// [END dialogflow_cx_list_testcase_sample]
43+
}
44+
45+
process.on('unhandledRejection', err => {
46+
console.error(err.message);
47+
process.exitCode = 1;
48+
});
49+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const execSync = require('child_process').execSync;
20+
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
21+
const dialogflow = require('@google-cloud/dialogflow-cx');
22+
23+
describe('Test filtering results', async () => {
24+
const cmd = 'node list-testcase-results.js';
25+
const agentId = process.env.AGENT_ID;
26+
const testId = process.env.TEST_ID;
27+
const location = 'global';
28+
const agentClient = new dialogflow.AgentsClient();
29+
const projectId = await agentClient.getProjectId();
30+
31+
it('should return filtered test results', async () => {
32+
const output = exec(`${cmd} ${projectId} ${agentId} ${testId} ${location}`);
33+
assert.include(output, testId);
34+
});
35+
});

0 commit comments

Comments
 (0)