Skip to content

Commit 13466b6

Browse files
authored
samples: get operation (#52)
1 parent 6951ead commit 13466b6

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
16+
'use strict';
17+
18+
function main(operationName) {
19+
// [START contactcenterinsights_get_operation]
20+
/**
21+
* TODO(developer): Uncomment this variable before running the sample.
22+
*/
23+
// const operationName = 'projects/my_project_id/locations/us-central1/operations/my_operation_id';
24+
25+
// Imports the Contact Center Insights client.
26+
const {
27+
ContactCenterInsightsClient,
28+
} = require('@google-cloud/contact-center-insights');
29+
30+
// Instantiates a client.
31+
const client = new ContactCenterInsightsClient();
32+
33+
async function getOperation() {
34+
const [operation] = await client.operationsClient.getOperation({
35+
name: operationName,
36+
});
37+
console.info(`Got operation ${operation.name}.`);
38+
}
39+
getOperation();
40+
// [END contactcenterinsights_get_operation]
41+
}
42+
43+
process.on('unhandledRejection', err => {
44+
console.error(err.message);
45+
process.exitCode = 1;
46+
});
47+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
16+
'use strict';
17+
18+
const {assert} = require('chai');
19+
const {before, describe, it} = require('mocha');
20+
const cp = require('child_process');
21+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
22+
23+
const {
24+
ContactCenterInsightsClient,
25+
} = require('@google-cloud/contact-center-insights');
26+
const client = new ContactCenterInsightsClient();
27+
28+
describe('GetOperation', () => {
29+
let projectId;
30+
31+
before(async () => {
32+
projectId = await client.getProjectId();
33+
});
34+
35+
it('should get an operation', async () => {
36+
/**
37+
* TODO(developer): Replace this variable with your operation name.
38+
*/
39+
const operationName = `projects/${projectId}/locations/us-central1/operations/12345`;
40+
41+
try {
42+
const stdout = execSync(`node ./getOperation.js ${operationName}`);
43+
assert.match(stdout, new RegExp(`Got operation ${operationName}`));
44+
} catch (e) {
45+
if (!e.message.includes('not found')) {
46+
throw e;
47+
}
48+
}
49+
});
50+
});

0 commit comments

Comments
 (0)