From 97d8e6a2106237eff4610baafc25230f90fdf087 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Mon, 20 Apr 2020 16:02:08 -0700 Subject: [PATCH] chore: remove unused dev packages (#67) (#72) --- .../google-cloud-recommender/src/index.ts | 2 +- .../src/v1/recommender_client.ts | 1070 +++++----- .../google-cloud-recommender/synth.metadata | 19 +- .../system-test/fixtures/sample/src/index.js | 1 + .../system-test/install.ts | 28 +- .../test/gapic_recommender_v1.ts | 1770 +++++++---------- .../webpack.config.js | 12 +- 7 files changed, 1220 insertions(+), 1682 deletions(-) diff --git a/packages/google-cloud-recommender/src/index.ts b/packages/google-cloud-recommender/src/index.ts index bab729506af..83fe9c83967 100644 --- a/packages/google-cloud-recommender/src/index.ts +++ b/packages/google-cloud-recommender/src/index.ts @@ -21,4 +21,4 @@ const RecommenderClient = v1.RecommenderClient; export {v1, RecommenderClient}; export default {v1, RecommenderClient}; import * as protos from '../protos/protos'; -export {protos}; +export {protos} diff --git a/packages/google-cloud-recommender/src/v1/recommender_client.ts b/packages/google-cloud-recommender/src/v1/recommender_client.ts index 513c2b28824..11d653f5f1c 100644 --- a/packages/google-cloud-recommender/src/v1/recommender_client.ts +++ b/packages/google-cloud-recommender/src/v1/recommender_client.ts @@ -17,18 +17,11 @@ // ** All changes to this file may be overwritten. ** import * as gax from 'google-gax'; -import { - Callback, - CallOptions, - Descriptors, - ClientOptions, - PaginationCallback, - GaxCall, -} from 'google-gax'; +import {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall} from 'google-gax'; import * as path from 'path'; -import {Transform} from 'stream'; -import {RequestType} from 'google-gax/build/src/apitypes'; +import { Transform } from 'stream'; +import { RequestType } from 'google-gax/build/src/apitypes'; import * as protos from '../../protos/protos'; import * as gapicConfig from './recommender_client_config.json'; @@ -50,12 +43,7 @@ export class RecommenderClient { private _protos: {}; private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; + descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}, batching: {}}; innerApiCalls: {[name: string]: Function}; pathTemplates: {[name: string]: gax.PathTemplate}; recommenderStub?: Promise<{[name: string]: Function}>; @@ -89,12 +77,10 @@ export class RecommenderClient { constructor(opts?: ClientOptions) { // Ensure that options include the service address and port. const staticMembers = this.constructor as typeof RecommenderClient; - const servicePath = - opts && opts.servicePath - ? opts.servicePath - : opts && opts.apiEndpoint - ? opts.apiEndpoint - : staticMembers.servicePath; + const servicePath = opts && opts.servicePath ? + opts.servicePath : + ((opts && opts.apiEndpoint) ? opts.apiEndpoint : + staticMembers.servicePath); const port = opts && opts.port ? opts.port : staticMembers.port; if (!opts) { @@ -104,8 +90,8 @@ export class RecommenderClient { opts.port = opts.port || port; opts.clientConfig = opts.clientConfig || {}; - const isBrowser = typeof window !== 'undefined'; - if (isBrowser) { + const isBrowser = (typeof window !== 'undefined'); + if (isBrowser){ opts.fallback = true; } // If we are in browser, we are already using fallback because of the @@ -122,10 +108,13 @@ export class RecommenderClient { this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = this._gaxGrpc.auth as gax.GoogleAuth; + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. - const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { @@ -141,18 +130,12 @@ export class RecommenderClient { // For Node.js, pass the path to JSON proto file. // For browsers, pass the JSON content. - const nodejsProtoPath = path.join( - __dirname, - '..', - '..', - 'protos', - 'protos.json' - ); + const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); this._protos = this._gaxGrpc.loadProto( - opts.fallback - ? // eslint-disable-next-line @typescript-eslint/no-var-requires - 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 @@ -171,20 +154,14 @@ export class RecommenderClient { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this.descriptors.page = { - listRecommendations: new this._gaxModule.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'recommendations' - ), + listRecommendations: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'recommendations') }; // Put together the default options sent with requests. this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.recommender.v1.Recommender', - gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, - {'x-goog-api-client': clientHeader.join(' ')} - ); + 'google.cloud.recommender.v1.Recommender', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); // Set up a dictionary of "inner API calls"; the core implementation // of calling the API is handled in `google-gax`, with this code @@ -212,24 +189,16 @@ export class RecommenderClient { // Put together the "service stub" for // google.cloud.recommender.v1.Recommender. this.recommenderStub = this._gaxGrpc.createStub( - this._opts.fallback - ? (this._protos as protobuf.Root).lookupService( - 'google.cloud.recommender.v1.Recommender' - ) - : // eslint-disable-next-line @typescript-eslint/no-explicit-any + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.recommender.v1.Recommender') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any (this._protos as any).google.cloud.recommender.v1.Recommender, - this._opts - ) as Promise<{[method: string]: Function}>; + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. - const recommenderStubMethods = [ - 'listRecommendations', - 'getRecommendation', - 'markRecommendationClaimed', - 'markRecommendationSucceeded', - 'markRecommendationFailed', - ]; + const recommenderStubMethods = + ['listRecommendations', 'getRecommendation', 'markRecommendationClaimed', 'markRecommendationSucceeded', 'markRecommendationFailed']; for (const methodName of recommenderStubMethods) { const callPromise = this.recommenderStub.then( stub => (...args: Array<{}>) => { @@ -239,17 +208,16 @@ export class RecommenderClient { const func = stub[methodName]; return func.apply(stub, args); }, - (err: Error | null | undefined) => () => { + (err: Error|null|undefined) => () => { throw err; - } - ); + }); const apiCall = this._gaxModule.createApiCall( callPromise, this._defaults[methodName], this.descriptors.page[methodName] || - this.descriptors.stream[methodName] || - this.descriptors.longrunning[methodName] + this.descriptors.stream[methodName] || + this.descriptors.longrunning[methodName] ); this.innerApiCalls[methodName] = apiCall; @@ -285,7 +253,9 @@ export class RecommenderClient { * in this service. */ static get scopes() { - return ['https://www.googleapis.com/auth/cloud-platform']; + return [ + 'https://www.googleapis.com/auth/cloud-platform' + ]; } getProjectId(): Promise; @@ -295,9 +265,8 @@ export class RecommenderClient { * @param {function(Error, string)} callback - the callback to * be called with the current project Id. */ - getProjectId( - callback?: Callback - ): Promise | void { + getProjectId(callback?: Callback): + Promise|void { if (callback) { this.auth.getProjectId(callback); return; @@ -309,81 +278,60 @@ export class RecommenderClient { // -- Service calls -- // ------------------- getRecommendation( - request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, - options?: gax.CallOptions - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - protos.google.cloud.recommender.v1.IGetRecommendationRequest | undefined, - {} | undefined - ] - >; + request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, + options?: gax.CallOptions): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IGetRecommendationRequest|undefined, {}|undefined + ]>; getRecommendation( - request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, - options: gax.CallOptions, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IGetRecommendationRequest - | null - | undefined, - {} | null | undefined - > - ): void; + request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, + options: gax.CallOptions, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IGetRecommendationRequest|null|undefined, + {}|null|undefined>): void; getRecommendation( - request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IGetRecommendationRequest - | null - | undefined, - {} | null | undefined - > - ): void; - /** - * Gets the requested recommendation. Requires the recommender.*.get - * IAM permission for the specified recommender. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the recommendation. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ + request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IGetRecommendationRequest|null|undefined, + {}|null|undefined>): void; +/** + * Gets the requested recommendation. Requires the recommender.*.get + * IAM permission for the specified recommender. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Name of the recommendation. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ getRecommendation( - request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, - optionsOrCallback?: - | gax.CallOptions - | Callback< + request: protos.google.cloud.recommender.v1.IGetRecommendationRequest, + optionsOrCallback?: gax.CallOptions|Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IGetRecommendationRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IGetRecommendationRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IGetRecommendationRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - protos.google.cloud.recommender.v1.IGetRecommendationRequest | undefined, - {} | undefined - ] - > | void { + protos.google.cloud.recommender.v1.IGetRecommendationRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IGetRecommendationRequest|undefined, {}|undefined + ]>|void { request = request || {}; let options: gax.CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } else { + } + else { options = optionsOrCallback as gax.CallOptions; } options = options || {}; @@ -392,108 +340,81 @@ export class RecommenderClient { options.otherArgs.headers[ 'x-goog-request-params' ] = gax.routingHeader.fromParams({ - name: request.name || '', + 'name': request.name || '', }); this.initialize(); return this.innerApiCalls.getRecommendation(request, options, callback); } markRecommendationClaimed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, - options?: gax.CallOptions - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - ( - | protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest - | undefined - ), - {} | undefined - ] - >; + request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, + options?: gax.CallOptions): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest|undefined, {}|undefined + ]>; markRecommendationClaimed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, - options: gax.CallOptions, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest - | null - | undefined, - {} | null | undefined - > - ): void; + request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, + options: gax.CallOptions, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest|null|undefined, + {}|null|undefined>): void; markRecommendationClaimed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest - | null - | undefined, - {} | null | undefined - > - ): void; - /** - * Mark the Recommendation State as Claimed. Users can use this method to - * indicate to the Recommender API that they are starting to apply the - * recommendation themselves. This stops the recommendation content from being - * updated. - * - * MarkRecommendationClaimed can be applied to recommendations in CLAIMED, - * SUCCEEDED, FAILED, or ACTIVE state. - * - * Requires the recommender.*.update IAM permission for the specified - * recommender. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the recommendation. - * @param {number[]} request.stateMetadata - * State properties to include with this state. Overwrites any existing - * `state_metadata`. - * Keys must match the regex /^{@link a-z0-9_.-|a-z0-9}{0,62}$/. - * Values must match the regex /^[a-zA-Z0-9_./-]{0,255}$/. - * @param {string} request.etag - * Required. Fingerprint of the Recommendation. Provides optimistic locking. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ + request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest|null|undefined, + {}|null|undefined>): void; +/** + * Mark the Recommendation State as Claimed. Users can use this method to + * indicate to the Recommender API that they are starting to apply the + * recommendation themselves. This stops the recommendation content from being + * updated. + * + * MarkRecommendationClaimed can be applied to recommendations in CLAIMED, + * SUCCEEDED, FAILED, or ACTIVE state. + * + * Requires the recommender.*.update IAM permission for the specified + * recommender. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Name of the recommendation. + * @param {number[]} request.stateMetadata + * State properties to include with this state. Overwrites any existing + * `state_metadata`. + * Keys must match the regex /^{@link a-z0-9_.-|a-z0-9}{0,62}$/. + * Values must match the regex /^[a-zA-Z0-9_./-]{0,255}$/. + * @param {string} request.etag + * Required. Fingerprint of the Recommendation. Provides optimistic locking. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ markRecommendationClaimed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, - optionsOrCallback?: - | gax.CallOptions - | Callback< + request: protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest, + optionsOrCallback?: gax.CallOptions|Callback< protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - ( - | protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest - | undefined - ), - {} | undefined - ] - > | void { + protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationClaimedRequest|undefined, {}|undefined + ]>|void { request = request || {}; let options: gax.CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } else { + } + else { options = optionsOrCallback as gax.CallOptions; } options = options || {}; @@ -502,112 +423,81 @@ export class RecommenderClient { options.otherArgs.headers[ 'x-goog-request-params' ] = gax.routingHeader.fromParams({ - name: request.name || '', + 'name': request.name || '', }); this.initialize(); - return this.innerApiCalls.markRecommendationClaimed( - request, - options, - callback - ); + return this.innerApiCalls.markRecommendationClaimed(request, options, callback); } markRecommendationSucceeded( - request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, - options?: gax.CallOptions - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - ( - | protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest - | undefined - ), - {} | undefined - ] - >; + request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, + options?: gax.CallOptions): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest|undefined, {}|undefined + ]>; markRecommendationSucceeded( - request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, - options: gax.CallOptions, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest - | null - | undefined, - {} | null | undefined - > - ): void; + request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, + options: gax.CallOptions, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest|null|undefined, + {}|null|undefined>): void; markRecommendationSucceeded( - request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest - | null - | undefined, - {} | null | undefined - > - ): void; - /** - * Mark the Recommendation State as Succeeded. Users can use this method to - * indicate to the Recommender API that they have applied the recommendation - * themselves, and the operation was successful. This stops the recommendation - * content from being updated. - * - * MarkRecommendationSucceeded can be applied to recommendations in ACTIVE, - * CLAIMED, SUCCEEDED, or FAILED state. - * - * Requires the recommender.*.update IAM permission for the specified - * recommender. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the recommendation. - * @param {number[]} request.stateMetadata - * State properties to include with this state. Overwrites any existing - * `state_metadata`. - * Keys must match the regex /^{@link a-z0-9_.-|a-z0-9}{0,62}$/. - * Values must match the regex /^[a-zA-Z0-9_./-]{0,255}$/. - * @param {string} request.etag - * Required. Fingerprint of the Recommendation. Provides optimistic locking. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ + request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest|null|undefined, + {}|null|undefined>): void; +/** + * Mark the Recommendation State as Succeeded. Users can use this method to + * indicate to the Recommender API that they have applied the recommendation + * themselves, and the operation was successful. This stops the recommendation + * content from being updated. + * + * MarkRecommendationSucceeded can be applied to recommendations in ACTIVE, + * CLAIMED, SUCCEEDED, or FAILED state. + * + * Requires the recommender.*.update IAM permission for the specified + * recommender. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Name of the recommendation. + * @param {number[]} request.stateMetadata + * State properties to include with this state. Overwrites any existing + * `state_metadata`. + * Keys must match the regex /^{@link a-z0-9_.-|a-z0-9}{0,62}$/. + * Values must match the regex /^[a-zA-Z0-9_./-]{0,255}$/. + * @param {string} request.etag + * Required. Fingerprint of the Recommendation. Provides optimistic locking. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ markRecommendationSucceeded( - request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, - optionsOrCallback?: - | gax.CallOptions - | Callback< + request: protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest, + optionsOrCallback?: gax.CallOptions|Callback< protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - ( - | protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest - | undefined - ), - {} | undefined - ] - > | void { + protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationSucceededRequest|undefined, {}|undefined + ]>|void { request = request || {}; let options: gax.CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } else { + } + else { options = optionsOrCallback as gax.CallOptions; } options = options || {}; @@ -616,112 +506,81 @@ export class RecommenderClient { options.otherArgs.headers[ 'x-goog-request-params' ] = gax.routingHeader.fromParams({ - name: request.name || '', + 'name': request.name || '', }); this.initialize(); - return this.innerApiCalls.markRecommendationSucceeded( - request, - options, - callback - ); + return this.innerApiCalls.markRecommendationSucceeded(request, options, callback); } markRecommendationFailed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, - options?: gax.CallOptions - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - ( - | protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest - | undefined - ), - {} | undefined - ] - >; + request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, + options?: gax.CallOptions): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest|undefined, {}|undefined + ]>; markRecommendationFailed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, - options: gax.CallOptions, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest - | null - | undefined, - {} | null | undefined - > - ): void; + request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, + options: gax.CallOptions, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest|null|undefined, + {}|null|undefined>): void; markRecommendationFailed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, - callback: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest - | null - | undefined, - {} | null | undefined - > - ): void; - /** - * Mark the Recommendation State as Failed. Users can use this method to - * indicate to the Recommender API that they have applied the recommendation - * themselves, and the operation failed. This stops the recommendation content - * from being updated. - * - * MarkRecommendationFailed can be applied to recommendations in ACTIVE, - * CLAIMED, SUCCEEDED, or FAILED state. - * - * Requires the recommender.*.update IAM permission for the specified - * recommender. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the recommendation. - * @param {number[]} request.stateMetadata - * State properties to include with this state. Overwrites any existing - * `state_metadata`. - * Keys must match the regex /^{@link a-z0-9_.-|a-z0-9}{0,62}$/. - * Values must match the regex /^[a-zA-Z0-9_./-]{0,255}$/. - * @param {string} request.etag - * Required. Fingerprint of the Recommendation. Provides optimistic locking. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. - * The promise has a method named "cancel" which cancels the ongoing API call. - */ + request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, + callback: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest|null|undefined, + {}|null|undefined>): void; +/** + * Mark the Recommendation State as Failed. Users can use this method to + * indicate to the Recommender API that they have applied the recommendation + * themselves, and the operation failed. This stops the recommendation content + * from being updated. + * + * MarkRecommendationFailed can be applied to recommendations in ACTIVE, + * CLAIMED, SUCCEEDED, or FAILED state. + * + * Requires the recommender.*.update IAM permission for the specified + * recommender. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Name of the recommendation. + * @param {number[]} request.stateMetadata + * State properties to include with this state. Overwrites any existing + * `state_metadata`. + * Keys must match the regex /^{@link a-z0-9_.-|a-z0-9}{0,62}$/. + * Values must match the regex /^[a-zA-Z0-9_./-]{0,255}$/. + * @param {string} request.etag + * Required. Fingerprint of the Recommendation. Provides optimistic locking. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. + * The promise has a method named "cancel" which cancels the ongoing API call. + */ markRecommendationFailed( - request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, - optionsOrCallback?: - | gax.CallOptions - | Callback< + request: protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest, + optionsOrCallback?: gax.CallOptions|Callback< protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest - | null - | undefined, - {} | null | undefined - >, - callback?: Callback< - protos.google.cloud.recommender.v1.IRecommendation, - | protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest - | null - | undefined, - {} | null | undefined - > - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation, - ( - | protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest - | undefined - ), - {} | undefined - ] - > | void { + protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation, + protos.google.cloud.recommender.v1.IMarkRecommendationFailedRequest|undefined, {}|undefined + ]>|void { request = request || {}; let options: gax.CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } else { + } + else { options = optionsOrCallback as gax.CallOptions; } options = options || {}; @@ -730,124 +589,101 @@ export class RecommenderClient { options.otherArgs.headers[ 'x-goog-request-params' ] = gax.routingHeader.fromParams({ - name: request.name || '', + 'name': request.name || '', }); this.initialize(); - return this.innerApiCalls.markRecommendationFailed( - request, - options, - callback - ); + return this.innerApiCalls.markRecommendationFailed(request, options, callback); } listRecommendations( - request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, - options?: gax.CallOptions - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation[], - protos.google.cloud.recommender.v1.IListRecommendationsRequest | null, - protos.google.cloud.recommender.v1.IListRecommendationsResponse - ] - >; + request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, + options?: gax.CallOptions): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation[], + protos.google.cloud.recommender.v1.IListRecommendationsRequest|null, + protos.google.cloud.recommender.v1.IListRecommendationsResponse + ]>; listRecommendations( - request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, - options: gax.CallOptions, - callback: PaginationCallback< - protos.google.cloud.recommender.v1.IListRecommendationsRequest, - | protos.google.cloud.recommender.v1.IListRecommendationsResponse - | null - | undefined, - protos.google.cloud.recommender.v1.IRecommendation - > - ): void; + request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, + options: gax.CallOptions, + callback: PaginationCallback< + protos.google.cloud.recommender.v1.IListRecommendationsRequest, + protos.google.cloud.recommender.v1.IListRecommendationsResponse|null|undefined, + protos.google.cloud.recommender.v1.IRecommendation>): void; listRecommendations( - request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, - callback: PaginationCallback< - protos.google.cloud.recommender.v1.IListRecommendationsRequest, - | protos.google.cloud.recommender.v1.IListRecommendationsResponse - | null - | undefined, - protos.google.cloud.recommender.v1.IRecommendation - > - ): void; - /** - * Lists recommendations for a Cloud project. Requires the recommender.*.list - * IAM permission for the specified recommender. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The container resource on which to execute the request. - * Acceptable formats: - * - * 1. - * "projects/[PROJECT_NUMBER]/locations/[LOCATION]/recommenders/[RECOMMENDER_ID]", - * - * LOCATION here refers to GCP Locations: - * https://cloud.google.com/about/locations/ - * @param {number} [request.pageSize] - * Optional. The maximum number of results to return from this request. Non-positive - * values are ignored. If not specified, the server will determine the number - * of results to return. - * @param {string} [request.pageToken] - * Optional. If present, retrieves the next batch of results from the preceding call to - * this method. `page_token` must be the value of `next_page_token` from the - * previous response. The values of other method parameters must be identical - * to those in the previous call. - * @param {string} request.filter - * Filter expression to restrict the recommendations returned. Supported - * filter fields: state_info.state - * Eg: `state_info.state:"DISMISSED" or state_info.state:"FAILED" - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is Array of [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. - * The client library support auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * - * When autoPaginate: false is specified through options, the array has three elements. - * The first element is Array of [Recommendation]{@link google.cloud.recommender.v1.Recommendation} that corresponds to - * the one page received from the API server. - * If the second element is not null it contains the request object of type [ListRecommendationsRequest]{@link google.cloud.recommender.v1.ListRecommendationsRequest} - * that can be used to obtain the next page of the results. - * If it is null, the next page does not exist. - * The third element contains the raw response received from the API server. Its type is - * [ListRecommendationsResponse]{@link google.cloud.recommender.v1.ListRecommendationsResponse}. - * - * The promise has a method named "cancel" which cancels the ongoing API call. - */ + request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, + callback: PaginationCallback< + protos.google.cloud.recommender.v1.IListRecommendationsRequest, + protos.google.cloud.recommender.v1.IListRecommendationsResponse|null|undefined, + protos.google.cloud.recommender.v1.IRecommendation>): void; +/** + * Lists recommendations for a Cloud project. Requires the recommender.*.list + * IAM permission for the specified recommender. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The container resource on which to execute the request. + * Acceptable formats: + * + * 1. + * "projects/[PROJECT_NUMBER]/locations/[LOCATION]/recommenders/[RECOMMENDER_ID]", + * + * LOCATION here refers to GCP Locations: + * https://cloud.google.com/about/locations/ + * @param {number} [request.pageSize] + * Optional. The maximum number of results to return from this request. Non-positive + * values are ignored. If not specified, the server will determine the number + * of results to return. + * @param {string} [request.pageToken] + * Optional. If present, retrieves the next batch of results from the preceding call to + * this method. `page_token` must be the value of `next_page_token` from the + * previous response. The values of other method parameters must be identical + * to those in the previous call. + * @param {string} request.filter + * Filter expression to restrict the recommendations returned. Supported + * filter fields: state_info.state + * Eg: `state_info.state:"DISMISSED" or state_info.state:"FAILED" + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is Array of [Recommendation]{@link google.cloud.recommender.v1.Recommendation}. + * The client library support auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * + * When autoPaginate: false is specified through options, the array has three elements. + * The first element is Array of [Recommendation]{@link google.cloud.recommender.v1.Recommendation} that corresponds to + * the one page received from the API server. + * If the second element is not null it contains the request object of type [ListRecommendationsRequest]{@link google.cloud.recommender.v1.ListRecommendationsRequest} + * that can be used to obtain the next page of the results. + * If it is null, the next page does not exist. + * The third element contains the raw response received from the API server. Its type is + * [ListRecommendationsResponse]{@link google.cloud.recommender.v1.ListRecommendationsResponse}. + * + * The promise has a method named "cancel" which cancels the ongoing API call. + */ listRecommendations( - request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, - optionsOrCallback?: - | gax.CallOptions - | PaginationCallback< + request: protos.google.cloud.recommender.v1.IListRecommendationsRequest, + optionsOrCallback?: gax.CallOptions|PaginationCallback< + protos.google.cloud.recommender.v1.IListRecommendationsRequest, + protos.google.cloud.recommender.v1.IListRecommendationsResponse|null|undefined, + protos.google.cloud.recommender.v1.IRecommendation>, + callback?: PaginationCallback< protos.google.cloud.recommender.v1.IListRecommendationsRequest, - | protos.google.cloud.recommender.v1.IListRecommendationsResponse - | null - | undefined, - protos.google.cloud.recommender.v1.IRecommendation - >, - callback?: PaginationCallback< - protos.google.cloud.recommender.v1.IListRecommendationsRequest, - | protos.google.cloud.recommender.v1.IListRecommendationsResponse - | null - | undefined, - protos.google.cloud.recommender.v1.IRecommendation - > - ): Promise< - [ - protos.google.cloud.recommender.v1.IRecommendation[], - protos.google.cloud.recommender.v1.IListRecommendationsRequest | null, - protos.google.cloud.recommender.v1.IListRecommendationsResponse - ] - > | void { + protos.google.cloud.recommender.v1.IListRecommendationsResponse|null|undefined, + protos.google.cloud.recommender.v1.IRecommendation>): + Promise<[ + protos.google.cloud.recommender.v1.IRecommendation[], + protos.google.cloud.recommender.v1.IListRecommendationsRequest|null, + protos.google.cloud.recommender.v1.IListRecommendationsResponse + ]>|void { request = request || {}; let options: gax.CallOptions; if (typeof optionsOrCallback === 'function' && callback === undefined) { callback = optionsOrCallback; options = {}; - } else { + } + else { options = optionsOrCallback as gax.CallOptions; } options = options || {}; @@ -856,58 +692,58 @@ export class RecommenderClient { options.otherArgs.headers[ 'x-goog-request-params' ] = gax.routingHeader.fromParams({ - parent: request.parent || '', + 'parent': request.parent || '', }); this.initialize(); return this.innerApiCalls.listRecommendations(request, options, callback); } - /** - * Equivalent to {@link listRecommendations}, but returns a NodeJS Stream object. - * - * This fetches the paged responses for {@link listRecommendations} continuously - * and invokes the callback registered for 'data' event for each element in the - * responses. - * - * The returned object has 'end' method when no more elements are required. - * - * autoPaginate option will be ignored. - * - * @see {@link https://nodejs.org/api/stream.html} - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The container resource on which to execute the request. - * Acceptable formats: - * - * 1. - * "projects/[PROJECT_NUMBER]/locations/[LOCATION]/recommenders/[RECOMMENDER_ID]", - * - * LOCATION here refers to GCP Locations: - * https://cloud.google.com/about/locations/ - * @param {number} [request.pageSize] - * Optional. The maximum number of results to return from this request. Non-positive - * values are ignored. If not specified, the server will determine the number - * of results to return. - * @param {string} [request.pageToken] - * Optional. If present, retrieves the next batch of results from the preceding call to - * this method. `page_token` must be the value of `next_page_token` from the - * previous response. The values of other method parameters must be identical - * to those in the previous call. - * @param {string} request.filter - * Filter expression to restrict the recommendations returned. Supported - * filter fields: state_info.state - * Eg: `state_info.state:"DISMISSED" or state_info.state:"FAILED" - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation} on 'data' event. - */ +/** + * Equivalent to {@link listRecommendations}, but returns a NodeJS Stream object. + * + * This fetches the paged responses for {@link listRecommendations} continuously + * and invokes the callback registered for 'data' event for each element in the + * responses. + * + * The returned object has 'end' method when no more elements are required. + * + * autoPaginate option will be ignored. + * + * @see {@link https://nodejs.org/api/stream.html} + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The container resource on which to execute the request. + * Acceptable formats: + * + * 1. + * "projects/[PROJECT_NUMBER]/locations/[LOCATION]/recommenders/[RECOMMENDER_ID]", + * + * LOCATION here refers to GCP Locations: + * https://cloud.google.com/about/locations/ + * @param {number} [request.pageSize] + * Optional. The maximum number of results to return from this request. Non-positive + * values are ignored. If not specified, the server will determine the number + * of results to return. + * @param {string} [request.pageToken] + * Optional. If present, retrieves the next batch of results from the preceding call to + * this method. `page_token` must be the value of `next_page_token` from the + * previous response. The values of other method parameters must be identical + * to those in the previous call. + * @param {string} request.filter + * Filter expression to restrict the recommendations returned. Supported + * filter fields: state_info.state + * Eg: `state_info.state:"DISMISSED" or state_info.state:"FAILED" + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing [Recommendation]{@link google.cloud.recommender.v1.Recommendation} on 'data' event. + */ listRecommendationsStream( - request?: protos.google.cloud.recommender.v1.IListRecommendationsRequest, - options?: gax.CallOptions - ): Transform { + request?: protos.google.cloud.recommender.v1.IListRecommendationsRequest, + options?: gax.CallOptions): + Transform{ request = request || {}; options = options || {}; options.otherArgs = options.otherArgs || {}; @@ -915,7 +751,7 @@ export class RecommenderClient { options.otherArgs.headers[ 'x-goog-request-params' ] = gax.routingHeader.fromParams({ - parent: request.parent || '', + 'parent': request.parent || '', }); const callSettings = new gax.CallSettings(options); this.initialize(); @@ -926,44 +762,44 @@ export class RecommenderClient { ); } - /** - * Equivalent to {@link listRecommendations}, 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 container resource on which to execute the request. - * Acceptable formats: - * - * 1. - * "projects/[PROJECT_NUMBER]/locations/[LOCATION]/recommenders/[RECOMMENDER_ID]", - * - * LOCATION here refers to GCP Locations: - * https://cloud.google.com/about/locations/ - * @param {number} [request.pageSize] - * Optional. The maximum number of results to return from this request. Non-positive - * values are ignored. If not specified, the server will determine the number - * of results to return. - * @param {string} [request.pageToken] - * Optional. If present, retrieves the next batch of results from the preceding call to - * this method. `page_token` must be the value of `next_page_token` from the - * previous response. The values of other method parameters must be identical - * to those in the previous call. - * @param {string} request.filter - * Filter expression to restrict the recommendations returned. Supported - * filter fields: state_info.state - * Eg: `state_info.state:"DISMISSED" or state_info.state:"FAILED" - * @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. - */ +/** + * Equivalent to {@link listRecommendations}, 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 container resource on which to execute the request. + * Acceptable formats: + * + * 1. + * "projects/[PROJECT_NUMBER]/locations/[LOCATION]/recommenders/[RECOMMENDER_ID]", + * + * LOCATION here refers to GCP Locations: + * https://cloud.google.com/about/locations/ + * @param {number} [request.pageSize] + * Optional. The maximum number of results to return from this request. Non-positive + * values are ignored. If not specified, the server will determine the number + * of results to return. + * @param {string} [request.pageToken] + * Optional. If present, retrieves the next batch of results from the preceding call to + * this method. `page_token` must be the value of `next_page_token` from the + * previous response. The values of other method parameters must be identical + * to those in the previous call. + * @param {string} request.filter + * Filter expression to restrict the recommendations returned. Supported + * filter fields: state_info.state + * Eg: `state_info.state:"DISMISSED" or state_info.state:"FAILED" + * @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. + */ listRecommendationsAsync( - request?: protos.google.cloud.recommender.v1.IListRecommendationsRequest, - options?: gax.CallOptions - ): AsyncIterable { + request?: protos.google.cloud.recommender.v1.IListRecommendationsRequest, + options?: gax.CallOptions): + AsyncIterable{ request = request || {}; options = options || {}; options.otherArgs = options.otherArgs || {}; @@ -971,14 +807,14 @@ export class RecommenderClient { options.otherArgs.headers[ 'x-goog-request-params' ] = gax.routingHeader.fromParams({ - parent: request.parent || '', + 'parent': request.parent || '', }); options = options || {}; const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listRecommendations.asyncIterate( this.innerApiCalls['listRecommendations'] as GaxCall, - (request as unknown) as RequestType, + request as unknown as RequestType, callSettings ) as AsyncIterable; } @@ -995,12 +831,7 @@ export class RecommenderClient { * @param {string} recommendation * @returns {string} Resource name string. */ - recommendationPath( - project: string, - location: string, - recommender: string, - recommendation: string - ) { + recommendationPath(project:string,location:string,recommender:string,recommendation:string) { return this.pathTemplates.recommendationPathTemplate.render({ project: project, location: location, @@ -1017,9 +848,7 @@ export class RecommenderClient { * @returns {string} A string representing the project. */ matchProjectFromRecommendationName(recommendationName: string) { - return this.pathTemplates.recommendationPathTemplate.match( - recommendationName - ).project; + return this.pathTemplates.recommendationPathTemplate.match(recommendationName).project; } /** @@ -1030,9 +859,7 @@ export class RecommenderClient { * @returns {string} A string representing the location. */ matchLocationFromRecommendationName(recommendationName: string) { - return this.pathTemplates.recommendationPathTemplate.match( - recommendationName - ).location; + return this.pathTemplates.recommendationPathTemplate.match(recommendationName).location; } /** @@ -1043,9 +870,7 @@ export class RecommenderClient { * @returns {string} A string representing the recommender. */ matchRecommenderFromRecommendationName(recommendationName: string) { - return this.pathTemplates.recommendationPathTemplate.match( - recommendationName - ).recommender; + return this.pathTemplates.recommendationPathTemplate.match(recommendationName).recommender; } /** @@ -1056,9 +881,7 @@ export class RecommenderClient { * @returns {string} A string representing the recommendation. */ matchRecommendationFromRecommendationName(recommendationName: string) { - return this.pathTemplates.recommendationPathTemplate.match( - recommendationName - ).recommendation; + return this.pathTemplates.recommendationPathTemplate.match(recommendationName).recommendation; } /** @@ -1069,7 +892,7 @@ export class RecommenderClient { * @param {string} recommender * @returns {string} Resource name string. */ - recommenderPath(project: string, location: string, recommender: string) { + recommenderPath(project:string,location:string,recommender:string) { return this.pathTemplates.recommenderPathTemplate.render({ project: project, location: location, @@ -1085,8 +908,7 @@ export class RecommenderClient { * @returns {string} A string representing the project. */ matchProjectFromRecommenderName(recommenderName: string) { - return this.pathTemplates.recommenderPathTemplate.match(recommenderName) - .project; + return this.pathTemplates.recommenderPathTemplate.match(recommenderName).project; } /** @@ -1097,8 +919,7 @@ export class RecommenderClient { * @returns {string} A string representing the location. */ matchLocationFromRecommenderName(recommenderName: string) { - return this.pathTemplates.recommenderPathTemplate.match(recommenderName) - .location; + return this.pathTemplates.recommenderPathTemplate.match(recommenderName).location; } /** @@ -1109,8 +930,7 @@ export class RecommenderClient { * @returns {string} A string representing the recommender. */ matchRecommenderFromRecommenderName(recommenderName: string) { - return this.pathTemplates.recommenderPathTemplate.match(recommenderName) - .recommender; + return this.pathTemplates.recommenderPathTemplate.match(recommenderName).recommender; } /** diff --git a/packages/google-cloud-recommender/synth.metadata b/packages/google-cloud-recommender/synth.metadata index dfa09d0e93a..27c5ea1c239 100644 --- a/packages/google-cloud-recommender/synth.metadata +++ b/packages/google-cloud-recommender/synth.metadata @@ -1,12 +1,25 @@ { - "updateTime": "2020-04-11T00:44:38.031540Z", "sources": [ + { + "git": { + "name": ".", + "remote": "https://github.com/googleapis/nodejs-recommender.git", + "sha": "7639dc40c2529290583d00ec67a99f8b3391bf76" + } + }, + { + "git": { + "name": "googleapis", + "remote": "https://github.com/googleapis/googleapis.git", + "sha": "cdf13efacdea0649e940452f9c5d320b93735974", + "internalRef": "306783437" + } + }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "6f32150677c9784f3c3a7e1949472bd29c9d72c5", - "log": "6f32150677c9784f3c3a7e1949472bd29c9d72c5\nfix: installs test_utils from its common repo (#480)\n\n\n74ce986d3b5431eb66985e9a00c4eb45295a4020\nfix: stop recording update_time in synth.metadata (#478)\n\n\n7f8e62aa3edd225f76347a16f92e400661fdfb52\nchore(java): release-please only updates non maven versions in README (#476)\n\nPrevent release-please and synthtool from fighting over the released library version. Synthtool updates the install snippets from the samples pom.xml files so the bots fight if they are temporarily out of sync after a release.\nc7e0e517d7f46f77bebd27da2e5afcaa6eee7e25\nbuild(java): fix nightly integration test config to run integrations (#465)\n\nThis was only running the units.\nbd69a2aa7b70875f3c988e269706b22fefbef40e\nbuild(java): fix retry_with_backoff when -e option set (#475)\n\n\nd9b173c427bfa0c6cca818233562e7e8841a357c\nfix: record version of working repo in synth.metadata (#473)\n\nPartial revert of b37cf74d12e9a42b9de9e61a4f26133d7cd9c168.\nf73a541770d95a609e5be6bf6b3b220d17cefcbe\nfeat(discogapic): allow local discovery-artifact-manager (#474)\n\n\n8cf0f5d93a70c3dcb0b4999d3152c46d4d9264bf\ndoc: describe the Autosynth & Synthtool protocol (#472)\n\n* doc: describe the Autosynth & Synthtool protocol\n\n* Accommodate review comments.\n980baaa738a1ad8fa02b4fdbd56be075ee77ece5\nfix: pin sphinx to <3.0.0 as new version causes new error (#471)\n\nThe error `toctree contains reference to document changlelog that doesn't have a title: no link will be generated` occurs as of 3.0.0. Pinning to 2.x until we address the docs build issue.\n\nTowards #470\n\nI did this manually for python-datastore https://github.com/googleapis/python-datastore/pull/22\n928b2998ac5023e7c7e254ab935f9ef022455aad\nchore(deps): update dependency com.google.cloud.samples:shared-configuration to v1.0.15 (#466)\n\nCo-authored-by: Jeffrey Rennie \n188f1b1d53181f739b98f8aa5d40cfe99eb90c47\nfix: allow local and external deps to be specified (#469)\n\nModify noxfile.py to allow local and external dependencies for\nsystem tests to be specified.\n1df68ed6735ddce6797d0f83641a731c3c3f75b4\nfix: apache license URL (#468)\n\n\nf4a59efa54808c4b958263de87bc666ce41e415f\nfeat: Add discogapic support for GAPICBazel generation (#459)\n\n* feat: Add discogapic support for GAPICBazel generation\n\n* reformat with black\n\n* Rename source repository variable\n\nCo-authored-by: Jeffrey Rennie \n" + "sha": "52638600f387deb98efb5f9c85fec39e82aa9052" } } ], diff --git a/packages/google-cloud-recommender/system-test/fixtures/sample/src/index.js b/packages/google-cloud-recommender/system-test/fixtures/sample/src/index.js index e8f4e4a22a6..59a3c7d7ef0 100644 --- a/packages/google-cloud-recommender/system-test/fixtures/sample/src/index.js +++ b/packages/google-cloud-recommender/system-test/fixtures/sample/src/index.js @@ -16,6 +16,7 @@ // ** 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 recommender = require('@google-cloud/recommender'); diff --git a/packages/google-cloud-recommender/system-test/install.ts b/packages/google-cloud-recommender/system-test/install.ts index c4d80e9c0c8..5e4ed636481 100644 --- a/packages/google-cloud-recommender/system-test/install.ts +++ b/packages/google-cloud-recommender/system-test/install.ts @@ -16,36 +16,34 @@ // ** https://github.com/googleapis/gapic-generator-typescript ** // ** All changes to this file may be overwritten. ** -import {packNTest} from 'pack-n-play'; -import {readFileSync} from 'fs'; -import {describe, it} from 'mocha'; +import { packNTest } from 'pack-n-play'; +import { readFileSync } from 'fs'; +import { describe, it } from 'mocha'; describe('typescript consumer tests', () => { + it('should have correct type signature for typescript users', async function() { this.timeout(300000); const options = { - packageDir: process.cwd(), // path to your module. + packageDir: process.cwd(), // path to your module. sample: { description: 'typescript based user can use the type definitions', - ts: readFileSync( - './system-test/fixtures/sample/src/index.ts' - ).toString(), - }, + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } }; - await packNTest(options); // will throw upon error. + await packNTest(options); // will throw upon error. }); it('should have correct type signature for javascript users', async function() { this.timeout(300000); const options = { - packageDir: process.cwd(), // path to your module. + packageDir: process.cwd(), // path to your module. sample: { description: 'typescript based user can use the type definitions', - ts: readFileSync( - './system-test/fixtures/sample/src/index.js' - ).toString(), - }, + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } }; - await packNTest(options); // will throw upon error. + await packNTest(options); // will throw upon error. }); + }); diff --git a/packages/google-cloud-recommender/test/gapic_recommender_v1.ts b/packages/google-cloud-recommender/test/gapic_recommender_v1.ts index ef26fb78af5..a1b01d52ecb 100644 --- a/packages/google-cloud-recommender/test/gapic_recommender_v1.ts +++ b/packages/google-cloud-recommender/test/gapic_recommender_v1.ts @@ -20,7 +20,7 @@ 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 { describe, it } from 'mocha'; import * as recommenderModule from '../src'; import {PassThrough} from 'stream'; @@ -28,1095 +28,801 @@ 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; + 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]); + 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 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({}); - }); +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]); + } } - setImmediate(() => { - mockStream.end(); - }); - } else { - setImmediate(() => { - mockStream.write({}); - }); - setImmediate(() => { - mockStream.end(); + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, }); - } - return sinon.stub().returns(mockStream); + // 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); +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.RecommenderClient', () => { - it('has servicePath', () => { - const servicePath = recommenderModule.v1.RecommenderClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = recommenderModule.v1.RecommenderClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = recommenderModule.v1.RecommenderClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new recommenderModule.v1.RecommenderClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new recommenderModule.v1.RecommenderClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.recommenderStub, undefined); - await client.initialize(); - assert(client.recommenderStub); - }); - - it('has close method', () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new recommenderModule.v1.RecommenderClient({ - 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 recommenderModule.v1.RecommenderClient({ - 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); - } - }); + it('has servicePath', () => { + const servicePath = recommenderModule.v1.RecommenderClient.servicePath; + assert(servicePath); }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - describe('getRecommendation', () => { - it('invokes getRecommendation without error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.GetRecommendationRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.getRecommendation = stubSimpleCall(expectedResponse); - const [response] = await client.getRecommendation(request); - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getRecommendation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + it('has apiEndpoint', () => { + const apiEndpoint = recommenderModule.v1.RecommenderClient.apiEndpoint; + assert(apiEndpoint); }); - it('invokes getRecommendation without error using callback', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.GetRecommendationRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.getRecommendation = stubSimpleCallWithCallback( - expectedResponse - ); - const promise = new Promise((resolve, reject) => { - client.getRecommendation( - request, - ( - err?: Error | null, - result?: protos.google.cloud.recommender.v1.IRecommendation | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getRecommendation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + it('has port', () => { + const port = recommenderModule.v1.RecommenderClient.port; + assert(port); + assert(typeof port === 'number'); }); - it('invokes getRecommendation with error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.GetRecommendationRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.getRecommendation = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(async () => { - await client.getRecommendation(request); - }, expectedError); - assert( - (client.innerApiCalls.getRecommendation as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + it('should create a client with no option', () => { + const client = new recommenderModule.v1.RecommenderClient(); + assert(client); }); - }); - describe('markRecommendationClaimed', () => { - it('invokes markRecommendationClaimed without error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationClaimedRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.markRecommendationClaimed = stubSimpleCall( - expectedResponse - ); - const [response] = await client.markRecommendationClaimed(request); - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.markRecommendationClaimed as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + it('should create a client with gRPC fallback', () => { + const client = new recommenderModule.v1.RecommenderClient({ + fallback: true, + }); + assert(client); }); - it('invokes markRecommendationClaimed without error using callback', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationClaimedRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.markRecommendationClaimed = stubSimpleCallWithCallback( - expectedResponse - ); - const promise = new Promise((resolve, reject) => { - client.markRecommendationClaimed( - request, - ( - err?: Error | null, - result?: protos.google.cloud.recommender.v1.IRecommendation | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.markRecommendationClaimed as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + it('has initialize method and supports deferred initialization', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.recommenderStub, undefined); + await client.initialize(); + assert(client.recommenderStub); }); - it('invokes markRecommendationClaimed with error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationClaimedRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.markRecommendationClaimed = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(async () => { - await client.markRecommendationClaimed(request); - }, expectedError); - assert( - (client.innerApiCalls.markRecommendationClaimed as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + it('has close method', () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); }); - }); - describe('markRecommendationSucceeded', () => { - it('invokes markRecommendationSucceeded without error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationSucceededRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.markRecommendationSucceeded = stubSimpleCall( - expectedResponse - ); - const [response] = await client.markRecommendationSucceeded(request); - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.markRecommendationSucceeded as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new recommenderModule.v1.RecommenderClient({ + 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('invokes markRecommendationSucceeded without error using callback', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationSucceededRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.markRecommendationSucceeded = stubSimpleCallWithCallback( - expectedResponse - ); - const promise = new Promise((resolve, reject) => { - client.markRecommendationSucceeded( - request, - ( - err?: Error | null, - result?: protos.google.cloud.recommender.v1.IRecommendation | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.markRecommendationSucceeded as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new recommenderModule.v1.RecommenderClient({ + 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); }); - it('invokes markRecommendationSucceeded with error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationSucceededRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.markRecommendationSucceeded = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(async () => { - await client.markRecommendationSucceeded(request); - }, expectedError); - assert( - (client.innerApiCalls.markRecommendationSucceeded as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); - }); - }); + describe('getRecommendation', () => { + it('invokes getRecommendation without error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.GetRecommendationRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.getRecommendation = stubSimpleCall(expectedResponse); + const [response] = await client.getRecommendation(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.getRecommendation as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); - describe('markRecommendationFailed', () => { - it('invokes markRecommendationFailed without error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationFailedRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.markRecommendationFailed = stubSimpleCall( - expectedResponse - ); - const [response] = await client.markRecommendationFailed(request); - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.markRecommendationFailed as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); - }); + it('invokes getRecommendation without error using callback', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.GetRecommendationRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.getRecommendation = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getRecommendation( + request, + (err?: Error|null, result?: protos.google.cloud.recommender.v1.IRecommendation|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.getRecommendation as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); - it('invokes markRecommendationFailed without error using callback', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationFailedRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ); - client.innerApiCalls.markRecommendationFailed = stubSimpleCallWithCallback( - expectedResponse - ); - const promise = new Promise((resolve, reject) => { - client.markRecommendationFailed( - request, - ( - err?: Error | null, - result?: protos.google.cloud.recommender.v1.IRecommendation | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.markRecommendationFailed as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + it('invokes getRecommendation with error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.GetRecommendationRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getRecommendation = stubSimpleCall(undefined, expectedError); + await assert.rejects(async () => { await client.getRecommendation(request); }, expectedError); + assert((client.innerApiCalls.getRecommendation as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); }); - it('invokes markRecommendationFailed with error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.MarkRecommendationFailedRequest() - ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.markRecommendationFailed = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(async () => { - await client.markRecommendationFailed(request); - }, expectedError); - assert( - (client.innerApiCalls.markRecommendationFailed as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); - }); - }); + describe('markRecommendationClaimed', () => { + it('invokes markRecommendationClaimed without error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationClaimedRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.markRecommendationClaimed = stubSimpleCall(expectedResponse); + const [response] = await client.markRecommendationClaimed(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.markRecommendationClaimed as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); - describe('listRecommendations', () => { - it('invokes listRecommendations without error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.ListRecommendationsRequest() - ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - ]; - client.innerApiCalls.listRecommendations = stubSimpleCall( - expectedResponse - ); - const [response] = await client.listRecommendations(request); - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listRecommendations as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); - }); + it('invokes markRecommendationClaimed without error using callback', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationClaimedRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.markRecommendationClaimed = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.markRecommendationClaimed( + request, + (err?: Error|null, result?: protos.google.cloud.recommender.v1.IRecommendation|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.markRecommendationClaimed as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); - it('invokes listRecommendations without error using callback', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.ListRecommendationsRequest() - ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - ]; - client.innerApiCalls.listRecommendations = stubSimpleCallWithCallback( - expectedResponse - ); - const promise = new Promise((resolve, reject) => { - client.listRecommendations( - request, - ( - err?: Error | null, - result?: protos.google.cloud.recommender.v1.IRecommendation[] | null - ) => { - if (err) { - reject(err); - } else { - resolve(result); - } - } - ); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listRecommendations as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + it('invokes markRecommendationClaimed with error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationClaimedRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.markRecommendationClaimed = stubSimpleCall(undefined, expectedError); + await assert.rejects(async () => { await client.markRecommendationClaimed(request); }, expectedError); + assert((client.innerApiCalls.markRecommendationClaimed as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); }); - it('invokes listRecommendations with error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.ListRecommendationsRequest() - ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.listRecommendations = stubSimpleCall( - undefined, - expectedError - ); - await assert.rejects(async () => { - await client.listRecommendations(request); - }, expectedError); - assert( - (client.innerApiCalls.listRecommendations as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); - }); + describe('markRecommendationSucceeded', () => { + it('invokes markRecommendationSucceeded without error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationSucceededRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.markRecommendationSucceeded = stubSimpleCall(expectedResponse); + const [response] = await client.markRecommendationSucceeded(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.markRecommendationSucceeded as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); - it('invokes listRecommendationsStream without error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.ListRecommendationsRequest() - ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - ]; - client.descriptors.page.listRecommendations.createStream = stubPageStreamingCall( - expectedResponse - ); - const stream = client.listRecommendationsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.recommender.v1.Recommendation[] = []; - stream.on( - 'data', - (response: protos.google.cloud.recommender.v1.Recommendation) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); + it('invokes markRecommendationSucceeded without error using callback', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationSucceededRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.markRecommendationSucceeded = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.markRecommendationSucceeded( + request, + (err?: Error|null, result?: protos.google.cloud.recommender.v1.IRecommendation|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.markRecommendationSucceeded as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); }); - stream.on('error', (err: Error) => { - reject(err); + + it('invokes markRecommendationSucceeded with error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationSucceededRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.markRecommendationSucceeded = stubSimpleCall(undefined, expectedError); + await assert.rejects(async () => { await client.markRecommendationSucceeded(request); }, expectedError); + assert((client.innerApiCalls.markRecommendationSucceeded as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert( - (client.descriptors.page.listRecommendations.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listRecommendations, request) - ); - assert.strictEqual( - (client.descriptors.page.listRecommendations - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], - expectedHeaderRequestParams - ); }); - it('invokes listRecommendationsStream with error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.ListRecommendationsRequest() - ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedError = new Error('expected'); - client.descriptors.page.listRecommendations.createStream = stubPageStreamingCall( - undefined, - expectedError - ); - const stream = client.listRecommendationsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.recommender.v1.Recommendation[] = []; - stream.on( - 'data', - (response: protos.google.cloud.recommender.v1.Recommendation) => { - responses.push(response); - } - ); - stream.on('end', () => { - resolve(responses); + describe('markRecommendationFailed', () => { + it('invokes markRecommendationFailed without error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationFailedRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.markRecommendationFailed = stubSimpleCall(expectedResponse); + const [response] = await client.markRecommendationFailed(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.markRecommendationFailed as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); }); - stream.on('error', (err: Error) => { - reject(err); + + it('invokes markRecommendationFailed without error using callback', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationFailedRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()); + client.innerApiCalls.markRecommendationFailed = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.markRecommendationFailed( + request, + (err?: Error|null, result?: protos.google.cloud.recommender.v1.IRecommendation|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.markRecommendationFailed as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); }); - }); - await assert.rejects(async () => { - await promise; - }, expectedError); - assert( - (client.descriptors.page.listRecommendations.createStream as SinonStub) - .getCall(0) - .calledWith(client.innerApiCalls.listRecommendations, request) - ); - assert.strictEqual( - (client.descriptors.page.listRecommendations - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], - expectedHeaderRequestParams - ); - }); - it('uses async iteration with listRecommendations without error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.ListRecommendationsRequest() - ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedResponse = [ - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - generateSampleMessage( - new protos.google.cloud.recommender.v1.Recommendation() - ), - ]; - client.descriptors.page.listRecommendations.asyncIterate = stubAsyncIterationCall( - expectedResponse - ); - const responses: protos.google.cloud.recommender.v1.IRecommendation[] = []; - const iterable = client.listRecommendationsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listRecommendations - .asyncIterate as SinonStub).getCall(0).args[1], - request - ); - assert.strictEqual( - (client.descriptors.page.listRecommendations - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], - expectedHeaderRequestParams - ); + it('invokes markRecommendationFailed with error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.MarkRecommendationFailedRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.markRecommendationFailed = stubSimpleCall(undefined, expectedError); + await assert.rejects(async () => { await client.markRecommendationFailed(request); }, expectedError); + assert((client.innerApiCalls.markRecommendationFailed as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); }); - it('uses async iteration with listRecommendations with error', async () => { - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage( - new protos.google.cloud.recommender.v1.ListRecommendationsRequest() - ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedError = new Error('expected'); - client.descriptors.page.listRecommendations.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError - ); - const iterable = client.listRecommendationsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.recommender.v1.IRecommendation[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listRecommendations - .asyncIterate as SinonStub).getCall(0).args[1], - request - ); - assert.strictEqual( - (client.descriptors.page.listRecommendations - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], - expectedHeaderRequestParams - ); - }); - }); + describe('listRecommendations', () => { + it('invokes listRecommendations without error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.ListRecommendationsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + ]; + client.innerApiCalls.listRecommendations = stubSimpleCall(expectedResponse); + const [response] = await client.listRecommendations(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.listRecommendations as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); - describe('Path templates', () => { - describe('recommendation', () => { - const fakePath = '/rendered/path/recommendation'; - const expectedParameters = { - project: 'projectValue', - location: 'locationValue', - recommender: 'recommenderValue', - recommendation: 'recommendationValue', - }; - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.recommendationPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.recommendationPathTemplate.match = sinon - .stub() - .returns(expectedParameters); + it('invokes listRecommendations without error using callback', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.ListRecommendationsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + ]; + client.innerApiCalls.listRecommendations = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listRecommendations( + request, + (err?: Error|null, result?: protos.google.cloud.recommender.v1.IRecommendation[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.listRecommendations as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); - it('recommendationPath', () => { - const result = client.recommendationPath( - 'projectValue', - 'locationValue', - 'recommenderValue', - 'recommendationValue' - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.recommendationPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters) - ); - }); + it('invokes listRecommendations with error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.ListRecommendationsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listRecommendations = stubSimpleCall(undefined, expectedError); + await assert.rejects(async () => { await client.listRecommendations(request); }, expectedError); + assert((client.innerApiCalls.listRecommendations as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); - it('matchProjectFromRecommendationName', () => { - const result = client.matchProjectFromRecommendationName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.recommendationPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); + it('invokes listRecommendationsStream without error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.ListRecommendationsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + ]; + client.descriptors.page.listRecommendations.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listRecommendationsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.recommender.v1.Recommendation[] = []; + stream.on('data', (response: protos.google.cloud.recommender.v1.Recommendation) => { + 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.listRecommendations.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listRecommendations, request)); + assert.strictEqual( + (client.descriptors.page.listRecommendations.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); - it('matchLocationFromRecommendationName', () => { - const result = client.matchLocationFromRecommendationName(fakePath); - assert.strictEqual(result, 'locationValue'); - assert( - (client.pathTemplates.recommendationPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); + it('invokes listRecommendationsStream with error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.ListRecommendationsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedError = new Error('expected'); + client.descriptors.page.listRecommendations.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listRecommendationsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.recommender.v1.Recommendation[] = []; + stream.on('data', (response: protos.google.cloud.recommender.v1.Recommendation) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(async () => { await promise; }, expectedError); + assert((client.descriptors.page.listRecommendations.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listRecommendations, request)); + assert.strictEqual( + (client.descriptors.page.listRecommendations.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); - it('matchRecommenderFromRecommendationName', () => { - const result = client.matchRecommenderFromRecommendationName(fakePath); - assert.strictEqual(result, 'recommenderValue'); - assert( - (client.pathTemplates.recommendationPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); + it('uses async iteration with listRecommendations without error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.ListRecommendationsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent=";const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + generateSampleMessage(new protos.google.cloud.recommender.v1.Recommendation()), + ]; + client.descriptors.page.listRecommendations.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.recommender.v1.IRecommendation[] = []; + const iterable = client.listRecommendationsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listRecommendations.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert.strictEqual( + (client.descriptors.page.listRecommendations.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); - it('matchRecommendationFromRecommendationName', () => { - const result = client.matchRecommendationFromRecommendationName( - fakePath - ); - assert.strictEqual(result, 'recommendationValue'); - assert( - (client.pathTemplates.recommendationPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); + it('uses async iteration with listRecommendations with error', async () => { + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.recommender.v1.ListRecommendationsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent=";const expectedError = new Error('expected'); + client.descriptors.page.listRecommendations.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listRecommendationsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.recommender.v1.IRecommendation[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listRecommendations.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert.strictEqual( + (client.descriptors.page.listRecommendations.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); }); - describe('recommender', () => { - const fakePath = '/rendered/path/recommender'; - const expectedParameters = { - project: 'projectValue', - location: 'locationValue', - recommender: 'recommenderValue', - }; - const client = new recommenderModule.v1.RecommenderClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.recommenderPathTemplate.render = sinon - .stub() - .returns(fakePath); - client.pathTemplates.recommenderPathTemplate.match = sinon - .stub() - .returns(expectedParameters); - - it('recommenderPath', () => { - const result = client.recommenderPath( - 'projectValue', - 'locationValue', - 'recommenderValue' - ); - assert.strictEqual(result, fakePath); - assert( - (client.pathTemplates.recommenderPathTemplate.render as SinonStub) - .getCall(-1) - .calledWith(expectedParameters) - ); - }); - - it('matchProjectFromRecommenderName', () => { - const result = client.matchProjectFromRecommenderName(fakePath); - assert.strictEqual(result, 'projectValue'); - assert( - (client.pathTemplates.recommenderPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); - - it('matchLocationFromRecommenderName', () => { - const result = client.matchLocationFromRecommenderName(fakePath); - assert.strictEqual(result, 'locationValue'); - assert( - (client.pathTemplates.recommenderPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); + describe('Path templates', () => { + + describe('recommendation', () => { + const fakePath = "/rendered/path/recommendation"; + const expectedParameters = { + project: "projectValue", + location: "locationValue", + recommender: "recommenderValue", + recommendation: "recommendationValue", + }; + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.recommendationPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.recommendationPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('recommendationPath', () => { + const result = client.recommendationPath("projectValue", "locationValue", "recommenderValue", "recommendationValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.recommendationPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromRecommendationName', () => { + const result = client.matchProjectFromRecommendationName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.recommendationPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchLocationFromRecommendationName', () => { + const result = client.matchLocationFromRecommendationName(fakePath); + assert.strictEqual(result, "locationValue"); + assert((client.pathTemplates.recommendationPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchRecommenderFromRecommendationName', () => { + const result = client.matchRecommenderFromRecommendationName(fakePath); + assert.strictEqual(result, "recommenderValue"); + assert((client.pathTemplates.recommendationPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchRecommendationFromRecommendationName', () => { + const result = client.matchRecommendationFromRecommendationName(fakePath); + assert.strictEqual(result, "recommendationValue"); + assert((client.pathTemplates.recommendationPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); - it('matchRecommenderFromRecommenderName', () => { - const result = client.matchRecommenderFromRecommenderName(fakePath); - assert.strictEqual(result, 'recommenderValue'); - assert( - (client.pathTemplates.recommenderPathTemplate.match as SinonStub) - .getCall(-1) - .calledWith(fakePath) - ); - }); + describe('recommender', () => { + const fakePath = "/rendered/path/recommender"; + const expectedParameters = { + project: "projectValue", + location: "locationValue", + recommender: "recommenderValue", + }; + const client = new recommenderModule.v1.RecommenderClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.recommenderPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.recommenderPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('recommenderPath', () => { + const result = client.recommenderPath("projectValue", "locationValue", "recommenderValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.recommenderPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromRecommenderName', () => { + const result = client.matchProjectFromRecommenderName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.recommenderPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchLocationFromRecommenderName', () => { + const result = client.matchLocationFromRecommenderName(fakePath); + assert.strictEqual(result, "locationValue"); + assert((client.pathTemplates.recommenderPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchRecommenderFromRecommenderName', () => { + const result = client.matchRecommenderFromRecommenderName(fakePath); + assert.strictEqual(result, "recommenderValue"); + assert((client.pathTemplates.recommenderPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); }); - }); }); diff --git a/packages/google-cloud-recommender/webpack.config.js b/packages/google-cloud-recommender/webpack.config.js index 40a80f89007..ae0c62f95e1 100644 --- a/packages/google-cloud-recommender/webpack.config.js +++ b/packages/google-cloud-recommender/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' }, ], },