|
| 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 {after, before, describe, it} = require('mocha'); |
| 20 | +const uuid = require('uuid'); |
| 21 | +const cp = require('child_process'); |
| 22 | +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); |
| 23 | + |
| 24 | +const generateUuid = () => `${uuid.v4()}`.replace(/-/gi, '_'); |
| 25 | + |
| 26 | +const { |
| 27 | + ContactCenterInsightsClient, |
| 28 | +} = require('@google-cloud/contact-center-insights'); |
| 29 | +const client = new ContactCenterInsightsClient(); |
| 30 | + |
| 31 | +const {PubSub} = require('@google-cloud/pubsub'); |
| 32 | +const pubSub = new PubSub(); |
| 33 | + |
| 34 | +const conversationTopicId = `create-conversation-${generateUuid()}`; |
| 35 | +const analysisTopicId = `create-analysis-${generateUuid()}`; |
| 36 | + |
| 37 | +describe('EnablePubSubNotifications', () => { |
| 38 | + let projectId; |
| 39 | + let conversationTopic; |
| 40 | + let analysisTopic; |
| 41 | + |
| 42 | + before(async () => { |
| 43 | + projectId = await client.getProjectId(); |
| 44 | + conversationTopic = `projects/${projectId}/topics/${conversationTopicId}`; |
| 45 | + analysisTopic = `projects/${projectId}/topics/${analysisTopicId}`; |
| 46 | + |
| 47 | + // Creates Pub/Sub topics. |
| 48 | + await pubSub.createTopic(conversationTopic); |
| 49 | + await pubSub.createTopic(analysisTopic); |
| 50 | + }); |
| 51 | + |
| 52 | + after(async () => { |
| 53 | + // Disables Pub/Sub notifications. |
| 54 | + await client.updateSettings({ |
| 55 | + settings: { |
| 56 | + name: client.settingsPath(projectId, 'us-central1'), |
| 57 | + pubsubNotificationSettings: {}, |
| 58 | + }, |
| 59 | + updateMask: { |
| 60 | + paths: ['pubsub_notification_settings'], |
| 61 | + }, |
| 62 | + }); |
| 63 | + |
| 64 | + // Deletes Pub/Sub topics. |
| 65 | + await pubSub.topic(conversationTopic).delete(); |
| 66 | + await pubSub.topic(analysisTopic).delete(); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should enable Pub/Sub notifications', async () => { |
| 70 | + const stdout = execSync(`node ./enablePubSubNotifications.js \ |
| 71 | + ${projectId} ${conversationTopic} ${analysisTopic}`); |
| 72 | + assert.match(stdout, new RegExp('Enabled Pub/Sub notifications')); |
| 73 | + }); |
| 74 | +}); |
0 commit comments