diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..7821534 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 73eeec2..0000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -extends: - - 'eslint:recommended' - - 'plugin:node/recommended' - - prettier -plugins: - - node - - prettier -rules: - prettier/prettier: error - block-scoped-var: error - eqeqeq: error - no-warning-comments: warn - no-var: error - prefer-const: error diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 92394b1..7138a79 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [8, 10, 12, 13] + node: [10, 12, 13] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index df6eac0..0000000 --- a/.prettierrc +++ /dev/null @@ -1,8 +0,0 @@ ---- -bracketSpacing: false -printWidth: 80 -semi: true -singleQuote: true -tabWidth: 2 -trailingComma: es5 -useTabs: false diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..08cba37 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,17 @@ +// Copyright 2020 Google LLC +// +// 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. + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/package.json b/package.json index 4aee31a..33ceb23 100644 --- a/package.json +++ b/package.json @@ -25,17 +25,18 @@ "reCAPTCHA Enterprise API" ], "dependencies": { - "google-gax": "^1.9.0" + "google-gax": "^2.0.1" }, "devDependencies": { "@types/mocha": "^7.0.0", "@types/node": "^12.0.0", + "@types/sinon": "^7.5.2", "c8": "^7.0.0", "eslint": "^6.0.0", "eslint-config-prettier": "^6.0.0", "eslint-plugin-node": "^11.0.0", "eslint-plugin-prettier": "^3.0.0", - "gts": "^1.0.0", + "gts": "2.0.0-alpha.9", "jsdoc": "^3.6.2", "jsdoc-fresh": "^1.0.1", "jsdoc-region-tag": "^1.0.2", @@ -44,8 +45,9 @@ "null-loader": "^3.0.0", "pack-n-play": "^1.0.0-2", "prettier": "^1.17.1", + "sinon": "^9.0.1", "ts-loader": "^6.2.1", - "typescript": "^3.7.0", + "typescript": "^3.8.3", "webpack": "^4.41.2", "webpack-cli": "^3.3.10" }, @@ -66,6 +68,6 @@ }, "license": "Apache-2.0", "engines": { - "node": ">=8.10.0" + "node": ">=10" } } diff --git a/samples/test/samples.test.js b/samples/test/samples.test.js index d24c716..c944ccb 100644 --- a/samples/test/samples.test.js +++ b/samples/test/samples.test.js @@ -26,7 +26,7 @@ describe('Quickstart', () => { it('should run quickstart', () => { // TODO: work on setting up a proper integration test. assert.throws(() => { - execSync(`node quickstart.js 123456`, {cwd}); + execSync('node quickstart.js 123456', {cwd}); }, /Permission denied on resource project #123456/); }); }); diff --git a/src/v1/recaptcha_enterprise_service_client.ts b/src/v1/recaptcha_enterprise_service_client.ts index bf61e9d..57d5366 100644 --- a/src/v1/recaptcha_enterprise_service_client.ts +++ b/src/v1/recaptcha_enterprise_service_client.ts @@ -18,18 +18,18 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, - PaginationResponse, + GaxCall, } from 'google-gax'; import * as path from 'path'; import {Transform} from 'stream'; -import * as protosTypes from '../../protos/protos'; +import {RequestType} from 'google-gax/build/src/apitypes'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './recaptcha_enterprise_service_client_config.json'; const version = require('../../../package.json').version; @@ -40,14 +40,6 @@ const version = require('../../../package.json').version; * @memberof v1 */ export class RecaptchaEnterpriseServiceClient { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -55,6 +47,14 @@ export class RecaptchaEnterpriseServiceClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; recaptchaEnterpriseServiceStub?: Promise<{[name: string]: Function}>; /** @@ -148,13 +148,16 @@ export class RecaptchaEnterpriseServiceClient { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { assessmentPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/assessments/{assessment}' ), @@ -169,7 +172,7 @@ export class RecaptchaEnterpriseServiceClient { // Some of the methods on this service return "paged" results, // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. - this._descriptors.page = { + this.descriptors.page = { listKeys: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', @@ -188,7 +191,7 @@ export class RecaptchaEnterpriseServiceClient { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -215,7 +218,7 @@ export class RecaptchaEnterpriseServiceClient { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.recaptchaenterprise.v1.RecaptchaEnterpriseService' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.recaptchaenterprise.v1 .RecaptchaEnterpriseService, this._opts @@ -232,9 +235,8 @@ export class RecaptchaEnterpriseServiceClient { 'updateKey', 'deleteKey', ]; - for (const methodName of recaptchaEnterpriseServiceStubMethods) { - const innerCallPromise = this.recaptchaEnterpriseServiceStub.then( + const callPromise = this.recaptchaEnterpriseServiceStub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -248,20 +250,14 @@ export class RecaptchaEnterpriseServiceClient { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.recaptchaEnterpriseServiceStub; @@ -318,26 +314,37 @@ export class RecaptchaEnterpriseServiceClient { // -- Service calls -- // ------------------- createAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IAssessment, + protos.google.cloud.recaptchaenterprise.v1.IAssessment, ( - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest | undefined ), {} | undefined ] >; createAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IAssessment, - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createAssessment( + request: protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -357,26 +364,28 @@ export class RecaptchaEnterpriseServiceClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IAssessment, - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IAssessment, - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IAssessment, + protos.google.cloud.recaptchaenterprise.v1.IAssessment, ( - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest | undefined ), {} | undefined @@ -399,29 +408,40 @@ export class RecaptchaEnterpriseServiceClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createAssessment(request, options, callback); + return this.innerApiCalls.createAssessment(request, options, callback); } annotateAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, + protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest | undefined ), {} | undefined ] >; annotateAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, - | protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + annotateAssessment( + request: protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -442,26 +462,28 @@ export class RecaptchaEnterpriseServiceClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ annotateAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, - | protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, - | protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, + protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse, ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest | undefined ), {} | undefined @@ -484,29 +506,37 @@ export class RecaptchaEnterpriseServiceClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.annotateAssessment(request, options, callback); + return this.innerApiCalls.annotateAssessment(request, options, callback); } createKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest - | undefined - ), + protos.google.cloud.recaptchaenterprise.v1.IKey, + protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest | undefined, {} | undefined ] >; createKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createKey( + request: protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -526,28 +556,27 @@ export class RecaptchaEnterpriseServiceClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ createKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest - | undefined - ), + protos.google.cloud.recaptchaenterprise.v1.IKey, + protos.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest | undefined, {} | undefined ] > | void { @@ -568,29 +597,37 @@ export class RecaptchaEnterpriseServiceClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createKey(request, options, callback); + return this.innerApiCalls.createKey(request, options, callback); } getKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest - | undefined - ), + protos.google.cloud.recaptchaenterprise.v1.IKey, + protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest | undefined, {} | undefined ] >; getKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + getKey( + request: protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -608,28 +645,27 @@ export class RecaptchaEnterpriseServiceClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ getKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest - | undefined - ), + protos.google.cloud.recaptchaenterprise.v1.IKey, + protos.google.cloud.recaptchaenterprise.v1.IGetKeyRequest | undefined, {} | undefined ] > | void { @@ -650,29 +686,37 @@ export class RecaptchaEnterpriseServiceClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getKey(request, options, callback); + return this.innerApiCalls.getKey(request, options, callback); } updateKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest - | undefined - ), + protos.google.cloud.recaptchaenterprise.v1.IKey, + protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest | undefined, {} | undefined ] >; updateKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + updateKey( + request: protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -692,28 +736,27 @@ export class RecaptchaEnterpriseServiceClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest + protos.google.cloud.recaptchaenterprise.v1.IKey, + | protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest - | undefined - ), + protos.google.cloud.recaptchaenterprise.v1.IKey, + protos.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest | undefined, {} | undefined ] > | void { @@ -734,29 +777,37 @@ export class RecaptchaEnterpriseServiceClient { 'key.name': request.key!.name || '', }); this.initialize(); - return this._innerApiCalls.updateKey(request, options, callback); + return this.innerApiCalls.updateKey(request, options, callback); } deleteKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest | undefined, {} | undefined ] >; deleteKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteKey( + request: protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -774,28 +825,27 @@ export class RecaptchaEnterpriseServiceClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, - ( - | protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest - | undefined - ), + protos.google.protobuf.IEmpty, + protos.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest | undefined, {} | undefined ] > | void { @@ -816,26 +866,38 @@ export class RecaptchaEnterpriseServiceClient { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteKey(request, options, callback); + return this.innerApiCalls.deleteKey(request, options, callback); } listKeys( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysResponse + protos.google.cloud.recaptchaenterprise.v1.IKey[], + protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest | null, + protos.google.cloud.recaptchaenterprise.v1.IListKeysResponse ] >; listKeys( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysResponse + callback: PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1.IKey + > + ): void; + listKeys( + request: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + callback: PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1.IKey > ): void; /** @@ -871,24 +933,28 @@ export class RecaptchaEnterpriseServiceClient { * The promise has a method named "cancel" which cancels the ongoing API call. */ listKeys( - request: protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + request: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysResponse + | PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1.IKey >, - callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysResponse + callback?: PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1.IKey > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysResponse + protos.google.cloud.recaptchaenterprise.v1.IKey[], + protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest | null, + protos.google.cloud.recaptchaenterprise.v1.IListKeysResponse ] > | void { request = request || {}; @@ -908,7 +974,7 @@ export class RecaptchaEnterpriseServiceClient { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listKeys(request, options, callback); + return this.innerApiCalls.listKeys(request, options, callback); } /** @@ -941,7 +1007,7 @@ export class RecaptchaEnterpriseServiceClient { * An object stream which emits an object representing [Key]{@link google.cloud.recaptchaenterprise.v1.Key} on 'data' event. */ listKeysStream( - request?: protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + request?: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -955,12 +1021,56 @@ export class RecaptchaEnterpriseServiceClient { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listKeys.createStream( - this._innerApiCalls.listKeys as gax.GaxCall, + return this.descriptors.page.listKeys.createStream( + this.innerApiCalls.listKeys as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listKeys}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project that contains the keys that will be + * listed, in the format "projects/{project}". + * @param {number} [request.pageSize] + * Optional. The maximum number of keys to return. Default is 10. Max limit is + * 1000. + * @param {string} [request.pageToken] + * Optional. The next_page_token value returned from a previous. + * ListKeysRequest, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listKeysAsync( + request?: protos.google.cloud.recaptchaenterprise.v1.IListKeysRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listKeys.asyncIterate( + this.innerApiCalls['listKeys'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } // -------------------- // -- Path templates -- // -------------------- @@ -973,9 +1083,9 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} Resource name string. */ assessmentPath(project: string, assessment: string) { - return this._pathTemplates.assessmentPathTemplate.render({ - project, - assessment, + return this.pathTemplates.assessmentPathTemplate.render({ + project: project, + assessment: assessment, }); } @@ -987,7 +1097,7 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} A string representing the project. */ matchProjectFromAssessmentName(assessmentName: string) { - return this._pathTemplates.assessmentPathTemplate.match(assessmentName) + return this.pathTemplates.assessmentPathTemplate.match(assessmentName) .project; } @@ -999,7 +1109,7 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} A string representing the assessment. */ matchAssessmentFromAssessmentName(assessmentName: string) { - return this._pathTemplates.assessmentPathTemplate.match(assessmentName) + return this.pathTemplates.assessmentPathTemplate.match(assessmentName) .assessment; } @@ -1011,9 +1121,9 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} Resource name string. */ keyPath(project: string, key: string) { - return this._pathTemplates.keyPathTemplate.render({ - project, - key, + return this.pathTemplates.keyPathTemplate.render({ + project: project, + key: key, }); } @@ -1025,7 +1135,7 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} A string representing the project. */ matchProjectFromKeyName(keyName: string) { - return this._pathTemplates.keyPathTemplate.match(keyName).project; + return this.pathTemplates.keyPathTemplate.match(keyName).project; } /** @@ -1036,7 +1146,7 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} A string representing the key. */ matchKeyFromKeyName(keyName: string) { - return this._pathTemplates.keyPathTemplate.match(keyName).key; + return this.pathTemplates.keyPathTemplate.match(keyName).key; } /** @@ -1046,8 +1156,8 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} Resource name string. */ projectPath(project: string) { - return this._pathTemplates.projectPathTemplate.render({ - project, + return this.pathTemplates.projectPathTemplate.render({ + project: project, }); } @@ -1059,7 +1169,7 @@ export class RecaptchaEnterpriseServiceClient { * @returns {string} A string representing the project. */ matchProjectFromProjectName(projectName: string) { - return this._pathTemplates.projectPathTemplate.match(projectName).project; + return this.pathTemplates.projectPathTemplate.match(projectName).project; } /** diff --git a/src/v1beta1/recaptcha_enterprise_service_v1_beta1_client.ts b/src/v1beta1/recaptcha_enterprise_service_v1_beta1_client.ts index ab23a5c..fbbfc22 100644 --- a/src/v1beta1/recaptcha_enterprise_service_v1_beta1_client.ts +++ b/src/v1beta1/recaptcha_enterprise_service_v1_beta1_client.ts @@ -18,18 +18,18 @@ import * as gax from 'google-gax'; import { - APICallback, Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, - PaginationResponse, + GaxCall, } from 'google-gax'; import * as path from 'path'; import {Transform} from 'stream'; -import * as protosTypes from '../../protos/protos'; +import {RequestType} from 'google-gax/build/src/apitypes'; +import * as protos from '../../protos/protos'; import * as gapicConfig from './recaptcha_enterprise_service_v1_beta1_client_config.json'; const version = require('../../../package.json').version; @@ -40,14 +40,6 @@ const version = require('../../../package.json').version; * @memberof v1beta1 */ export class RecaptchaEnterpriseServiceV1Beta1Client { - private _descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - private _innerApiCalls: {[name: string]: Function}; - private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; private _opts: ClientOptions; private _gaxModule: typeof gax | typeof gax.fallback; @@ -55,6 +47,14 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; recaptchaEnterpriseServiceV1Beta1Stub?: Promise<{[name: string]: Function}>; /** @@ -148,13 +148,16 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { 'protos.json' ); this._protos = this._gaxGrpc.loadProto( - opts.fallback ? require('../../protos/protos.json') : nodejsProtoPath + opts.fallback + ? // eslint-disable-next-line @typescript-eslint/no-var-requires + require('../../protos/protos.json') + : nodejsProtoPath ); // This API contains "path templates"; forward-slash-separated // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. - this._pathTemplates = { + this.pathTemplates = { assessmentPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/assessments/{assessment}' ), @@ -169,7 +172,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { // Some of the methods on this service return "paged" results, // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. - this._descriptors.page = { + this.descriptors.page = { listKeys: new this._gaxModule.PageDescriptor( 'pageToken', 'nextPageToken', @@ -188,7 +191,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. - this._innerApiCalls = {}; + this.innerApiCalls = {}; } /** @@ -215,7 +218,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { ? (this._protos as protobuf.Root).lookupService( 'google.cloud.recaptchaenterprise.v1beta1.RecaptchaEnterpriseServiceV1Beta1' ) - : // tslint:disable-next-line no-any + : // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.recaptchaenterprise.v1beta1 .RecaptchaEnterpriseServiceV1Beta1, this._opts @@ -232,9 +235,8 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { 'updateKey', 'deleteKey', ]; - for (const methodName of recaptchaEnterpriseServiceV1Beta1StubMethods) { - const innerCallPromise = this.recaptchaEnterpriseServiceV1Beta1Stub.then( + const callPromise = this.recaptchaEnterpriseServiceV1Beta1Stub.then( stub => (...args: Array<{}>) => { if (this._terminated) { return Promise.reject('The client has already been closed.'); @@ -248,20 +250,14 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { ); const apiCall = this._gaxModule.createApiCall( - innerCallPromise, + callPromise, this._defaults[methodName], - this._descriptors.page[methodName] || - this._descriptors.stream[methodName] || - this._descriptors.longrunning[methodName] + this.descriptors.page[methodName] || + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); - this._innerApiCalls[methodName] = ( - argument: {}, - callOptions?: CallOptions, - callback?: APICallback - ) => { - return apiCall(argument, callOptions, callback); - }; + this.innerApiCalls[methodName] = apiCall; } return this.recaptchaEnterpriseServiceV1Beta1Stub; @@ -318,26 +314,37 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { // -- Service calls -- // ------------------- createAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAssessment, + protos.google.cloud.recaptchaenterprise.v1beta1.IAssessment, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest | undefined ), {} | undefined ] >; createAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAssessment, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createAssessment( + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1beta1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -357,26 +364,28 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * The promise has a method named "cancel" which cancels the ongoing API call. */ createAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAssessment, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAssessment, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IAssessment, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAssessment, + protos.google.cloud.recaptchaenterprise.v1beta1.IAssessment, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest | undefined ), {} | undefined @@ -399,29 +408,40 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createAssessment(request, options, callback); + return this.innerApiCalls.createAssessment(request, options, callback); } annotateAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, + protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest | undefined ), {} | undefined ] >; annotateAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + annotateAssessment( + request: protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -442,26 +462,28 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * The promise has a method named "cancel" which cancels the ongoing API call. */ annotateAssessment( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, + | protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, + protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest | undefined ), {} | undefined @@ -484,29 +506,40 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.annotateAssessment(request, options, callback); + return this.innerApiCalls.annotateAssessment(request, options, callback); } createKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest | undefined ), {} | undefined ] >; createKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + createKey( + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -526,26 +559,28 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * The promise has a method named "cancel" which cancels the ongoing API call. */ createKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest | undefined ), {} | undefined @@ -568,29 +603,40 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.createKey(request, options, callback); + return this.innerApiCalls.createKey(request, options, callback); } getKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest | undefined ), {} | undefined ] >; getKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + getKey( + request: protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -608,26 +654,28 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * The promise has a method named "cancel" which cancels the ongoing API call. */ getKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest | undefined ), {} | undefined @@ -650,29 +698,40 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.getKey(request, options, callback); + return this.innerApiCalls.getKey(request, options, callback); } updateKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest | undefined ), {} | undefined ] >; updateKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + updateKey( + request: protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest, + callback: Callback< + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -692,26 +751,28 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * The promise has a method named "cancel" which cancels the ongoing API call. */ updateKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, + | protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest | undefined ), {} | undefined @@ -734,29 +795,40 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { 'key.name': request.key!.name || '', }); this.initialize(); - return this._innerApiCalls.updateKey(request, options, callback); + return this.innerApiCalls.updateKey(request, options, callback); } deleteKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest | undefined ), {} | undefined ] >; deleteKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest, options: gax.CallOptions, callback: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined + > + ): void; + deleteKey( + request: protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + | null + | undefined, + {} | null | undefined > ): void; /** @@ -774,26 +846,28 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * The promise has a method named "cancel" which cancels the ongoing API call. */ deleteKey( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest, optionsOrCallback?: | gax.CallOptions | Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined >, callback?: Callback< - protosTypes.google.protobuf.IEmpty, - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + protos.google.protobuf.IEmpty, + | protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + | null | undefined, - {} | undefined + {} | null | undefined > ): Promise< [ - protosTypes.google.protobuf.IEmpty, + protos.google.protobuf.IEmpty, ( - | protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest + | protos.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest | undefined ), {} | undefined @@ -816,26 +890,38 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { name: request.name || '', }); this.initialize(); - return this._innerApiCalls.deleteKey(request, options, callback); + return this.innerApiCalls.deleteKey(request, options, callback); } listKeys( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, options?: gax.CallOptions ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + protos.google.cloud.recaptchaenterprise.v1beta1.IKey[], + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest | null, + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse ] >; listKeys( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, options: gax.CallOptions, - callback: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + callback: PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey + > + ): void; + listKeys( + request: protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + callback: PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey > ): void; /** @@ -871,24 +957,28 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * The promise has a method named "cancel" which cancels the ongoing API call. */ listKeys( - request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + request: protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, optionsOrCallback?: | gax.CallOptions - | Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + | PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey >, - callback?: Callback< - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + callback?: PaginationCallback< + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + | protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + | null + | undefined, + protos.google.cloud.recaptchaenterprise.v1beta1.IKey > ): Promise< [ - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IKey[], - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest | null, - protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse + protos.google.cloud.recaptchaenterprise.v1beta1.IKey[], + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest | null, + protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysResponse ] > | void { request = request || {}; @@ -908,7 +998,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { parent: request.parent || '', }); this.initialize(); - return this._innerApiCalls.listKeys(request, options, callback); + return this.innerApiCalls.listKeys(request, options, callback); } /** @@ -941,7 +1031,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * An object stream which emits an object representing [Key]{@link google.cloud.recaptchaenterprise.v1beta1.Key} on 'data' event. */ listKeysStream( - request?: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + request?: protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, options?: gax.CallOptions ): Transform { request = request || {}; @@ -955,12 +1045,56 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { }); const callSettings = new gax.CallSettings(options); this.initialize(); - return this._descriptors.page.listKeys.createStream( - this._innerApiCalls.listKeys as gax.GaxCall, + return this.descriptors.page.listKeys.createStream( + this.innerApiCalls.listKeys as gax.GaxCall, request, callSettings ); } + + /** + * Equivalent to {@link listKeys}, but returns an iterable object. + * + * for-await-of syntax is used with the iterable to recursively get response element on-demand. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project that contains the keys that will be + * listed, in the format "projects/{project_number}". + * @param {number} [request.pageSize] + * Optional. The maximum number of keys to return. Default is 10. Max limit is + * 1000. + * @param {string} [request.pageToken] + * Optional. The next_page_token value returned from a previous. + * ListKeysRequest, if any. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. + */ + listKeysAsync( + request?: protos.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest, + options?: gax.CallOptions + ): AsyncIterable { + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + parent: request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listKeys.asyncIterate( + this.innerApiCalls['listKeys'] as GaxCall, + (request as unknown) as RequestType, + callSettings + ) as AsyncIterable; + } // -------------------- // -- Path templates -- // -------------------- @@ -973,9 +1107,9 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} Resource name string. */ assessmentPath(project: string, assessment: string) { - return this._pathTemplates.assessmentPathTemplate.render({ - project, - assessment, + return this.pathTemplates.assessmentPathTemplate.render({ + project: project, + assessment: assessment, }); } @@ -987,7 +1121,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} A string representing the project. */ matchProjectFromAssessmentName(assessmentName: string) { - return this._pathTemplates.assessmentPathTemplate.match(assessmentName) + return this.pathTemplates.assessmentPathTemplate.match(assessmentName) .project; } @@ -999,7 +1133,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} A string representing the assessment. */ matchAssessmentFromAssessmentName(assessmentName: string) { - return this._pathTemplates.assessmentPathTemplate.match(assessmentName) + return this.pathTemplates.assessmentPathTemplate.match(assessmentName) .assessment; } @@ -1011,9 +1145,9 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} Resource name string. */ keyPath(project: string, key: string) { - return this._pathTemplates.keyPathTemplate.render({ - project, - key, + return this.pathTemplates.keyPathTemplate.render({ + project: project, + key: key, }); } @@ -1025,7 +1159,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} A string representing the project. */ matchProjectFromKeyName(keyName: string) { - return this._pathTemplates.keyPathTemplate.match(keyName).project; + return this.pathTemplates.keyPathTemplate.match(keyName).project; } /** @@ -1036,7 +1170,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} A string representing the key. */ matchKeyFromKeyName(keyName: string) { - return this._pathTemplates.keyPathTemplate.match(keyName).key; + return this.pathTemplates.keyPathTemplate.match(keyName).key; } /** @@ -1046,8 +1180,8 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} Resource name string. */ projectPath(project: string) { - return this._pathTemplates.projectPathTemplate.render({ - project, + return this.pathTemplates.projectPathTemplate.render({ + project: project, }); } @@ -1059,7 +1193,7 @@ export class RecaptchaEnterpriseServiceV1Beta1Client { * @returns {string} A string representing the project. */ matchProjectFromProjectName(projectName: string) { - return this._pathTemplates.projectPathTemplate.match(projectName).project; + return this.pathTemplates.projectPathTemplate.match(projectName).project; } /** diff --git a/synth.metadata b/synth.metadata index 71b59f3..e2f2c50 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,16 +1,5 @@ { - "updateTime": "2020-03-24T23:50:54.138889Z", - "sources": [ - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "1df117114c73299b614dfd3ba3632bf246669336", - "internalRef": "302753982", - "log": "1df117114c73299b614dfd3ba3632bf246669336\nSynchronize new proto/yaml changes.\n\nPiperOrigin-RevId: 302753982\n\n" - } - } - ], + "updateTime": "2020-03-31T19:56:03.113784Z", "destinations": [ { "client": { diff --git a/system-test/fixtures/sample/src/index.js b/system-test/fixtures/sample/src/index.js index d0565cd..cb2d9ca 100644 --- a/system-test/fixtures/sample/src/index.js +++ b/system-test/fixtures/sample/src/index.js @@ -16,7 +16,6 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** - /* eslint-disable node/no-missing-require, no-unused-vars */ const recaptchaenterprise = require('@google-cloud/recaptcha-enterprise'); diff --git a/system-test/fixtures/sample/src/index.ts b/system-test/fixtures/sample/src/index.ts index d010410..c457bf5 100644 --- a/system-test/fixtures/sample/src/index.ts +++ b/system-test/fixtures/sample/src/index.ts @@ -19,7 +19,7 @@ import {RecaptchaEnterpriseServiceV1Beta1Client} from '@google-cloud/recaptcha-enterprise'; function main() { - const recaptchaEnterpriseServiceV1Beta1Client = new RecaptchaEnterpriseServiceV1Beta1Client(); + new RecaptchaEnterpriseServiceV1Beta1Client(); } main(); diff --git a/test/gapic-recaptcha_enterprise_service-v1.ts b/test/gapic-recaptcha_enterprise_service-v1.ts deleted file mode 100644 index f247b6b..0000000 --- a/test/gapic-recaptcha_enterprise_service-v1.ts +++ /dev/null @@ -1,512 +0,0 @@ -// Copyright 2020 Google LLC -// -// 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 -// -// https://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. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const recaptchaenterpriseserviceModule = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -describe('v1.RecaptchaEnterpriseServiceClient', () => { - it('has servicePath', () => { - const servicePath = - recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient - .servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient - .apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = - recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - fallback: true, - } - ); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.recaptchaEnterpriseServiceStub, undefined); - await client.initialize(); - assert(client.recaptchaEnterpriseServiceStub); - }); - it('has close method', () => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.close(); - }); - describe('createAssessment', () => { - it('invokes createAssessment without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createAssessment = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createAssessment(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createAssessment with error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateAssessmentRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createAssessment = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createAssessment(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('annotateAssessment', () => { - it('invokes annotateAssessment without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.annotateAssessment = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.annotateAssessment(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes annotateAssessment with error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.annotateAssessment = mockSimpleGrpcMethod( - request, - null, - error - ); - client.annotateAssessment(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createKey', () => { - it('invokes createKey without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createKey with error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.ICreateKeyRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createKey = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getKey', () => { - it('invokes getKey without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getKey with error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IGetKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getKey = mockSimpleGrpcMethod(request, null, error); - client.getKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateKey', () => { - it('invokes updateKey without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest = {}; - request.key = {}; - request.key.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateKey with error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IUpdateKeyRequest = {}; - request.key = {}; - request.key.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateKey = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteKey', () => { - it('invokes deleteKey without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteKey with error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IDeleteKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteKey = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('listKeys', () => { - it('invokes listKeys without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listKeys = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listKeys(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listKeysStream', () => { - it('invokes listKeysStream without error', done => { - const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1.IListKeysRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listKeys = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listKeysStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); -}); diff --git a/test/gapic-recaptcha_enterprise_service_v1_beta1-v1beta1.ts b/test/gapic-recaptcha_enterprise_service_v1_beta1-v1beta1.ts deleted file mode 100644 index d119609..0000000 --- a/test/gapic-recaptcha_enterprise_service_v1_beta1-v1beta1.ts +++ /dev/null @@ -1,513 +0,0 @@ -// Copyright 2020 Google LLC -// -// 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 -// -// https://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. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protosTypes from '../protos/protos'; -import * as assert from 'assert'; -import {describe, it} from 'mocha'; -const recaptchaenterpriseservicev1beta1Module = require('../src'); - -const FAKE_STATUS_CODE = 1; -class FakeError { - name: string; - message: string; - code: number; - constructor(n: number) { - this.name = 'fakeName'; - this.message = 'fake message'; - this.code = n; - } -} -const error = new FakeError(FAKE_STATUS_CODE); -export interface Callback { - (err: FakeError | null, response?: {} | null): void; -} - -export class Operation { - constructor() {} - promise() {} -} -function mockSimpleGrpcMethod( - expectedRequest: {}, - response: {} | null, - error: FakeError | null -) { - return (actualRequest: {}, options: {}, callback: Callback) => { - assert.deepStrictEqual(actualRequest, expectedRequest); - if (error) { - callback(error); - } else if (response) { - callback(null, response); - } else { - callback(null); - } - }; -} -describe('v1beta1.RecaptchaEnterpriseServiceV1Beta1Client', () => { - it('has servicePath', () => { - const servicePath = - recaptchaenterpriseservicev1beta1Module.v1beta1 - .RecaptchaEnterpriseServiceV1Beta1Client.servicePath; - assert(servicePath); - }); - it('has apiEndpoint', () => { - const apiEndpoint = - recaptchaenterpriseservicev1beta1Module.v1beta1 - .RecaptchaEnterpriseServiceV1Beta1Client.apiEndpoint; - assert(apiEndpoint); - }); - it('has port', () => { - const port = - recaptchaenterpriseservicev1beta1Module.v1beta1 - .RecaptchaEnterpriseServiceV1Beta1Client.port; - assert(port); - assert(typeof port === 'number'); - }); - it('should create a client with no option', () => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client(); - assert(client); - }); - it('should create a client with gRPC fallback', () => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - fallback: true, - } - ); - assert(client); - }); - it('has initialize method and supports deferred initialization', async () => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - assert.strictEqual(client.recaptchaEnterpriseServiceV1Beta1Stub, undefined); - await client.initialize(); - assert(client.recaptchaEnterpriseServiceV1Beta1Stub); - }); - it('has close method', () => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - client.close(); - }); - describe('createAssessment', () => { - it('invokes createAssessment without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createAssessment = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createAssessment(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createAssessment with error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateAssessmentRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createAssessment = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createAssessment(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('annotateAssessment', () => { - it('invokes annotateAssessment without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.annotateAssessment = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.annotateAssessment(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes annotateAssessment with error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.annotateAssessment = mockSimpleGrpcMethod( - request, - null, - error - ); - client.annotateAssessment(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('createKey', () => { - it('invokes createKey without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.createKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes createKey with error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.ICreateKeyRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.createKey = mockSimpleGrpcMethod( - request, - null, - error - ); - client.createKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('getKey', () => { - it('invokes getKey without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.getKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes getKey with error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IGetKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.getKey = mockSimpleGrpcMethod(request, null, error); - client.getKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('updateKey', () => { - it('invokes updateKey without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest = {}; - request.key = {}; - request.key.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.updateKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes updateKey with error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IUpdateKeyRequest = {}; - request.key = {}; - request.key.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.updateKey = mockSimpleGrpcMethod( - request, - null, - error - ); - client.updateKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('deleteKey', () => { - it('invokes deleteKey without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteKey = mockSimpleGrpcMethod( - request, - expectedResponse, - null - ); - client.deleteKey(request, (err: {}, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - - it('invokes deleteKey with error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IDeleteKeyRequest = {}; - request.name = ''; - // Mock response - const expectedResponse = {}; - // Mock gRPC layer - client._innerApiCalls.deleteKey = mockSimpleGrpcMethod( - request, - null, - error - ); - client.deleteKey(request, (err: FakeError, response: {}) => { - assert(err instanceof FakeError); - assert.strictEqual(err.code, FAKE_STATUS_CODE); - assert(typeof response === 'undefined'); - done(); - }); - }); - }); - describe('listKeys', () => { - it('invokes listKeys without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {}; - // Mock Grpc layer - client._innerApiCalls.listKeys = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - client.listKeys(request, (err: FakeError, response: {}) => { - assert.ifError(err); - assert.deepStrictEqual(response, expectedResponse); - done(); - }); - }); - }); - describe('listKeysStream', () => { - it('invokes listKeysStream without error', done => { - const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( - { - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - } - ); - // Initialize client before mocking - client.initialize(); - // Mock request - const request: protosTypes.google.cloud.recaptchaenterprise.v1beta1.IListKeysRequest = {}; - request.parent = ''; - // Mock response - const expectedResponse = {response: 'data'}; - // Mock Grpc layer - client._innerApiCalls.listKeys = ( - actualRequest: {}, - options: {}, - callback: Callback - ) => { - assert.deepStrictEqual(actualRequest, request); - callback(null, expectedResponse); - }; - const stream = client - .listKeysStream(request, {}) - .on('data', (response: {}) => { - assert.deepStrictEqual(response, expectedResponse); - done(); - }) - .on('error', (err: FakeError) => { - done(err); - }); - stream.write(expectedResponse); - }); - }); -}); diff --git a/test/gapic_recaptcha_enterprise_service_v1.ts b/test/gapic_recaptcha_enterprise_service_v1.ts new file mode 100644 index 0000000..b9a1a04 --- /dev/null +++ b/test/gapic_recaptcha_enterprise_service_v1.ts @@ -0,0 +1,1389 @@ +// Copyright 2020 Google LLC +// +// 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as recaptchaenterpriseserviceModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall( + responses?: ResponseType[], + error?: Error +) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error + ? sinon.stub().callsArgWith(2, error) + : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { + mockStream.write({}); + }); + } + setImmediate(() => { + mockStream.end(); + }); + } else { + setImmediate(() => { + mockStream.write({}); + }); + setImmediate(() => { + mockStream.end(); + }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall( + responses?: ResponseType[], + error?: Error +) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + }, + }; + }, + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1.RecaptchaEnterpriseServiceClient', () => { + it('has servicePath', () => { + const servicePath = + recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient + .servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient + .apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = + recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + fallback: true, + } + ); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.recaptchaEnterpriseServiceStub, undefined); + await client.initialize(); + assert(client.recaptchaEnterpriseServiceStub); + }); + + it('has close method', () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('createAssessment', () => { + it('invokes createAssessment without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.CreateAssessmentRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Assessment() + ); + client.innerApiCalls.createAssessment = stubSimpleCall(expectedResponse); + const [response] = await client.createAssessment(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createAssessment without error using callback', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.CreateAssessmentRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Assessment() + ); + client.innerApiCalls.createAssessment = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createAssessment( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1.IAssessment | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createAssessment with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.CreateAssessmentRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createAssessment = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createAssessment(request); + }, expectedError); + assert( + (client.innerApiCalls.createAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('annotateAssessment', () => { + it('invokes annotateAssessment without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.AnnotateAssessmentRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.AnnotateAssessmentResponse() + ); + client.innerApiCalls.annotateAssessment = stubSimpleCall( + expectedResponse + ); + const [response] = await client.annotateAssessment(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.annotateAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes annotateAssessment without error using callback', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.AnnotateAssessmentRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.AnnotateAssessmentResponse() + ); + client.innerApiCalls.annotateAssessment = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.annotateAssessment( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1.IAnnotateAssessmentResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.annotateAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes annotateAssessment with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.AnnotateAssessmentRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.annotateAssessment = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.annotateAssessment(request); + }, expectedError); + assert( + (client.innerApiCalls.annotateAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createKey', () => { + it('invokes createKey without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.CreateKeyRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ); + client.innerApiCalls.createKey = stubSimpleCall(expectedResponse); + const [response] = await client.createKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createKey without error using callback', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.CreateKeyRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ); + client.innerApiCalls.createKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createKey( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1.IKey | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createKey with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.CreateKeyRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.createKey(request); + }, expectedError); + assert( + (client.innerApiCalls.createKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getKey', () => { + it('invokes getKey without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.GetKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ); + client.innerApiCalls.getKey = stubSimpleCall(expectedResponse); + const [response] = await client.getKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getKey without error using callback', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.GetKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ); + client.innerApiCalls.getKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getKey( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1.IKey | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getKey with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.GetKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.getKey(request); + }, expectedError); + assert( + (client.innerApiCalls.getKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateKey', () => { + it('invokes updateKey without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.UpdateKeyRequest() + ); + request.key = {}; + request.key.name = ''; + const expectedHeaderRequestParams = 'key.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ); + client.innerApiCalls.updateKey = stubSimpleCall(expectedResponse); + const [response] = await client.updateKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateKey without error using callback', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.UpdateKeyRequest() + ); + request.key = {}; + request.key.name = ''; + const expectedHeaderRequestParams = 'key.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ); + client.innerApiCalls.updateKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateKey( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1.IKey | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateKey with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.UpdateKeyRequest() + ); + request.key = {}; + request.key.name = ''; + const expectedHeaderRequestParams = 'key.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.updateKey(request); + }, expectedError); + assert( + (client.innerApiCalls.updateKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteKey', () => { + it('invokes deleteKey without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.DeleteKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteKey = stubSimpleCall(expectedResponse); + const [response] = await client.deleteKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteKey without error using callback', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.DeleteKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteKey( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteKey with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.DeleteKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.deleteKey(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('listKeys', () => { + it('invokes listKeys without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + ]; + client.innerApiCalls.listKeys = stubSimpleCall(expectedResponse); + const [response] = await client.listKeys(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listKeys as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listKeys without error using callback', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + ]; + client.innerApiCalls.listKeys = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listKeys( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1.IKey[] | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listKeys as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listKeys with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listKeys = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.listKeys(request); + }, expectedError); + assert( + (client.innerApiCalls.listKeys as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listKeysStream without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + ]; + client.descriptors.page.listKeys.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listKeysStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.recaptchaenterprise.v1.Key[] = []; + stream.on( + 'data', + (response: protos.google.cloud.recaptchaenterprise.v1.Key) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listKeys.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listKeys, request) + ); + assert.strictEqual( + (client.descriptors.page.listKeys.createStream as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('invokes listKeysStream with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listKeys.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listKeysStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.recaptchaenterprise.v1.Key[] = []; + stream.on( + 'data', + (response: protos.google.cloud.recaptchaenterprise.v1.Key) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listKeys.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listKeys, request) + ); + assert.strictEqual( + (client.descriptors.page.listKeys.createStream as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listKeys without error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.Key() + ), + ]; + client.descriptors.page.listKeys.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.recaptchaenterprise.v1.IKey[] = []; + const iterable = client.listKeysAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listKeys with error', async () => { + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listKeys.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listKeysAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.recaptchaenterprise.v1.IKey[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + }); + + describe('Path templates', () => { + describe('assessment', () => { + const fakePath = '/rendered/path/assessment'; + const expectedParameters = { + project: 'projectValue', + assessment: 'assessmentValue', + }; + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + client.pathTemplates.assessmentPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.assessmentPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('assessmentPath', () => { + const result = client.assessmentPath('projectValue', 'assessmentValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.assessmentPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromAssessmentName', () => { + const result = client.matchProjectFromAssessmentName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.assessmentPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchAssessmentFromAssessmentName', () => { + const result = client.matchAssessmentFromAssessmentName(fakePath); + assert.strictEqual(result, 'assessmentValue'); + assert( + (client.pathTemplates.assessmentPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('key', () => { + const fakePath = '/rendered/path/key'; + const expectedParameters = { + project: 'projectValue', + key: 'keyValue', + }; + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + client.pathTemplates.keyPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.keyPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('keyPath', () => { + const result = client.keyPath('projectValue', 'keyValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.keyPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromKeyName', () => { + const result = client.matchProjectFromKeyName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.keyPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchKeyFromKeyName', () => { + const result = client.matchKeyFromKeyName(fakePath); + assert.strictEqual(result, 'keyValue'); + assert( + (client.pathTemplates.keyPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('project', () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = new recaptchaenterpriseserviceModule.v1.RecaptchaEnterpriseServiceClient( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/test/gapic_recaptcha_enterprise_service_v1_beta1_v1beta1.ts b/test/gapic_recaptcha_enterprise_service_v1_beta1_v1beta1.ts new file mode 100644 index 0000000..239c5d3 --- /dev/null +++ b/test/gapic_recaptcha_enterprise_service_v1_beta1_v1beta1.ts @@ -0,0 +1,1392 @@ +// Copyright 2020 Google LLC +// +// 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 +// +// https://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. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import {describe, it} from 'mocha'; +import * as recaptchaenterpriseservicev1beta1Module from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message).toObject( + instance as protobuf.Message, + {defaults: true} + ); + return (instance.constructor as typeof protobuf.Message).fromObject( + filledObject + ) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error + ? sinon.stub().rejects(error) + : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback( + response?: ResponseType, + error?: Error +) { + return error + ? sinon.stub().callsArgWith(2, error) + : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall( + responses?: ResponseType[], + error?: Error +) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error + ? sinon.stub().callsArgWith(2, error) + : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { + mockStream.write({}); + }); + } + setImmediate(() => { + mockStream.end(); + }); + } else { + setImmediate(() => { + mockStream.write({}); + }); + setImmediate(() => { + mockStream.end(); + }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall( + responses?: ResponseType[], + error?: Error +) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + }, + }; + }, + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v1beta1.RecaptchaEnterpriseServiceV1Beta1Client', () => { + it('has servicePath', () => { + const servicePath = + recaptchaenterpriseservicev1beta1Module.v1beta1 + .RecaptchaEnterpriseServiceV1Beta1Client.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + recaptchaenterpriseservicev1beta1Module.v1beta1 + .RecaptchaEnterpriseServiceV1Beta1Client.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = + recaptchaenterpriseservicev1beta1Module.v1beta1 + .RecaptchaEnterpriseServiceV1Beta1Client.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + fallback: true, + } + ); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + assert.strictEqual(client.recaptchaEnterpriseServiceV1Beta1Stub, undefined); + await client.initialize(); + assert(client.recaptchaEnterpriseServiceV1Beta1Stub); + }); + + it('has close method', () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.auth.getProjectId = sinon + .stub() + .callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error | null, projectId?: string | null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('createAssessment', () => { + it('invokes createAssessment without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.CreateAssessmentRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Assessment() + ); + client.innerApiCalls.createAssessment = stubSimpleCall(expectedResponse); + const [response] = await client.createAssessment(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createAssessment without error using callback', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.CreateAssessmentRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Assessment() + ); + client.innerApiCalls.createAssessment = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createAssessment( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1beta1.IAssessment | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createAssessment with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.CreateAssessmentRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createAssessment = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.createAssessment(request); + }, expectedError); + assert( + (client.innerApiCalls.createAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('annotateAssessment', () => { + it('invokes annotateAssessment without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse() + ); + client.innerApiCalls.annotateAssessment = stubSimpleCall( + expectedResponse + ); + const [response] = await client.annotateAssessment(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.annotateAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes annotateAssessment without error using callback', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.AnnotateAssessmentResponse() + ); + client.innerApiCalls.annotateAssessment = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.annotateAssessment( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1beta1.IAnnotateAssessmentResponse | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.annotateAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes annotateAssessment with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.AnnotateAssessmentRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.annotateAssessment = stubSimpleCall( + undefined, + expectedError + ); + assert.rejects(async () => { + await client.annotateAssessment(request); + }, expectedError); + assert( + (client.innerApiCalls.annotateAssessment as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('createKey', () => { + it('invokes createKey without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.CreateKeyRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ); + client.innerApiCalls.createKey = stubSimpleCall(expectedResponse); + const [response] = await client.createKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes createKey without error using callback', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.CreateKeyRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ); + client.innerApiCalls.createKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.createKey( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1beta1.IKey | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.createKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes createKey with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.CreateKeyRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.createKey(request); + }, expectedError); + assert( + (client.innerApiCalls.createKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('getKey', () => { + it('invokes getKey without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.GetKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ); + client.innerApiCalls.getKey = stubSimpleCall(expectedResponse); + const [response] = await client.getKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes getKey without error using callback', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.GetKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ); + client.innerApiCalls.getKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.getKey( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1beta1.IKey | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.getKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes getKey with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.GetKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.getKey(request); + }, expectedError); + assert( + (client.innerApiCalls.getKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('updateKey', () => { + it('invokes updateKey without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.UpdateKeyRequest() + ); + request.key = {}; + request.key.name = ''; + const expectedHeaderRequestParams = 'key.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ); + client.innerApiCalls.updateKey = stubSimpleCall(expectedResponse); + const [response] = await client.updateKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes updateKey without error using callback', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.UpdateKeyRequest() + ); + request.key = {}; + request.key.name = ''; + const expectedHeaderRequestParams = 'key.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ); + client.innerApiCalls.updateKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.updateKey( + request, + ( + err?: Error | null, + result?: protos.google.cloud.recaptchaenterprise.v1beta1.IKey | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.updateKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes updateKey with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.UpdateKeyRequest() + ); + request.key = {}; + request.key.name = ''; + const expectedHeaderRequestParams = 'key.name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updateKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.updateKey(request); + }, expectedError); + assert( + (client.innerApiCalls.updateKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('deleteKey', () => { + it('invokes deleteKey without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.DeleteKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteKey = stubSimpleCall(expectedResponse); + const [response] = await client.deleteKey(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes deleteKey without error using callback', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.DeleteKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage( + new protos.google.protobuf.Empty() + ); + client.innerApiCalls.deleteKey = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.deleteKey( + request, + ( + err?: Error | null, + result?: protos.google.protobuf.IEmpty | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.deleteKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes deleteKey with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.DeleteKeyRequest() + ); + request.name = ''; + const expectedHeaderRequestParams = 'name='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deleteKey = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.deleteKey(request); + }, expectedError); + assert( + (client.innerApiCalls.deleteKey as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + }); + + describe('listKeys', () => { + it('invokes listKeys without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + ]; + client.innerApiCalls.listKeys = stubSimpleCall(expectedResponse); + const [response] = await client.listKeys(request); + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listKeys as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listKeys without error using callback', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + ]; + client.innerApiCalls.listKeys = stubSimpleCallWithCallback( + expectedResponse + ); + const promise = new Promise((resolve, reject) => { + client.listKeys( + request, + ( + err?: Error | null, + result?: + | protos.google.cloud.recaptchaenterprise.v1beta1.IKey[] + | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert( + (client.innerApiCalls.listKeys as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions /*, callback defined above */) + ); + }); + + it('invokes listKeys with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listKeys = stubSimpleCall(undefined, expectedError); + assert.rejects(async () => { + await client.listKeys(request); + }, expectedError); + assert( + (client.innerApiCalls.listKeys as SinonStub) + .getCall(0) + .calledWith(request, expectedOptions, undefined) + ); + }); + + it('invokes listKeysStream without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + ]; + client.descriptors.page.listKeys.createStream = stubPageStreamingCall( + expectedResponse + ); + const stream = client.listKeysStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.recaptchaenterprise.v1beta1.Key[] = []; + stream.on( + 'data', + (response: protos.google.cloud.recaptchaenterprise.v1beta1.Key) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert( + (client.descriptors.page.listKeys.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listKeys, request) + ); + assert.strictEqual( + (client.descriptors.page.listKeys.createStream as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('invokes listKeysStream with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listKeys.createStream = stubPageStreamingCall( + undefined, + expectedError + ); + const stream = client.listKeysStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.recaptchaenterprise.v1beta1.Key[] = []; + stream.on( + 'data', + (response: protos.google.cloud.recaptchaenterprise.v1beta1.Key) => { + responses.push(response); + } + ); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + assert.rejects(async () => { + await promise; + }, expectedError); + assert( + (client.descriptors.page.listKeys.createStream as SinonStub) + .getCall(0) + .calledWith(client.innerApiCalls.listKeys, request) + ); + assert.strictEqual( + (client.descriptors.page.listKeys.createStream as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listKeys without error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedResponse = [ + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.Key() + ), + ]; + client.descriptors.page.listKeys.asyncIterate = stubAsyncIterationCall( + expectedResponse + ); + const responses: protos.google.cloud.recaptchaenterprise.v1beta1.IKey[] = []; + const iterable = client.listKeysAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listKeys with error', async () => { + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.recaptchaenterprise.v1beta1.ListKeysRequest() + ); + request.parent = ''; + const expectedHeaderRequestParams = 'parent='; + const expectedError = new Error('expected'); + client.descriptors.page.listKeys.asyncIterate = stubAsyncIterationCall( + undefined, + expectedError + ); + const iterable = client.listKeysAsync(request); + assert.rejects(async () => { + const responses: protos.google.cloud.recaptchaenterprise.v1beta1.IKey[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[1], + request + ); + assert.strictEqual( + (client.descriptors.page.listKeys.asyncIterate as SinonStub).getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + }); + + describe('Path templates', () => { + describe('assessment', () => { + const fakePath = '/rendered/path/assessment'; + const expectedParameters = { + project: 'projectValue', + assessment: 'assessmentValue', + }; + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + client.pathTemplates.assessmentPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.assessmentPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('assessmentPath', () => { + const result = client.assessmentPath('projectValue', 'assessmentValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.assessmentPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromAssessmentName', () => { + const result = client.matchProjectFromAssessmentName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.assessmentPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchAssessmentFromAssessmentName', () => { + const result = client.matchAssessmentFromAssessmentName(fakePath); + assert.strictEqual(result, 'assessmentValue'); + assert( + (client.pathTemplates.assessmentPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('key', () => { + const fakePath = '/rendered/path/key'; + const expectedParameters = { + project: 'projectValue', + key: 'keyValue', + }; + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + client.pathTemplates.keyPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.keyPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('keyPath', () => { + const result = client.keyPath('projectValue', 'keyValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.keyPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromKeyName', () => { + const result = client.matchProjectFromKeyName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.keyPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + + it('matchKeyFromKeyName', () => { + const result = client.matchKeyFromKeyName(fakePath); + assert.strictEqual(result, 'keyValue'); + assert( + (client.pathTemplates.keyPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + + describe('project', () => { + const fakePath = '/rendered/path/project'; + const expectedParameters = { + project: 'projectValue', + }; + const client = new recaptchaenterpriseservicev1beta1Module.v1beta1.RecaptchaEnterpriseServiceV1Beta1Client( + { + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + } + ); + client.initialize(); + client.pathTemplates.projectPathTemplate.render = sinon + .stub() + .returns(fakePath); + client.pathTemplates.projectPathTemplate.match = sinon + .stub() + .returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath('projectValue'); + assert.strictEqual(result, fakePath); + assert( + (client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1) + .calledWith(expectedParameters) + ); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, 'projectValue'); + assert( + (client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1) + .calledWith(fakePath) + ); + }); + }); + }); +}); diff --git a/webpack.config.js b/webpack.config.js index 2435e0e..04831b7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -36,27 +36,27 @@ module.exports = { { test: /\.tsx?$/, use: 'ts-loader', - exclude: /node_modules/ + exclude: /node_modules/, }, { test: /node_modules[\\/]@grpc[\\/]grpc-js/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]grpc/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]retry-request/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]https?-proxy-agent/, - use: 'null-loader' + use: 'null-loader', }, { test: /node_modules[\\/]gtoken/, - use: 'null-loader' + use: 'null-loader', }, ], },