From 913ac11a735b25ae7182bc0f57f9ce0e2a1c5738 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 21 Sep 2022 12:02:27 -0700 Subject: [PATCH] fix: preserve default values in x-goog-request-params header (#820) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: use gapic-generator-typescript v2.17.0 PiperOrigin-RevId: 474338479 Source-Link: https://github.com/googleapis/googleapis/commit/d5d35e0353b59719e8917103b1bc7df2782bf6ba Source-Link: https://github.com/googleapis/googleapis-gen/commit/efcd3f93962a103f68f003e2a1eecde6fa216a27 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWZjZDNmOTM5NjJhMTAzZjY4ZjAwM2UyYTFlZWNkZTZmYTIxNmEyNyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * test: use fully qualified request type name in tests PiperOrigin-RevId: 475685359 Source-Link: https://github.com/googleapis/googleapis/commit/7a129736313ceb1f277c3b7f7e16d2e04cc901dd Source-Link: https://github.com/googleapis/googleapis-gen/commit/370c729e2ba062a167449c27882ba5f379c5c34d Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzcwYzcyOWUyYmEwNjJhMTY3NDQ5YzI3ODgyYmE1ZjM3OWM1YzM0ZCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * test: fix translation Co-authored-by: Owl Bot Co-authored-by: Alexander Fenster --- .../test/v3/translate_translate_text.test.js | 2 +- .../translate_translate_text_beta.test.js | 2 +- src/v3/translation_service_client.ts | 24 +- src/v3beta1/translation_service_client.ts | 24 +- test/gapic_translation_service_v3.ts | 1073 +++++++++-------- test/gapic_translation_service_v3beta1.ts | 1073 +++++++++-------- 6 files changed, 1154 insertions(+), 1044 deletions(-) diff --git a/samples/test/v3/translate_translate_text.test.js b/samples/test/v3/translate_translate_text.test.js index 4acba8d8..1212c49f 100644 --- a/samples/test/v3/translate_translate_text.test.js +++ b/samples/test/v3/translate_translate_text.test.js @@ -32,6 +32,6 @@ describe(REGION_TAG, () => { const output = execSync( `node v3/${REGION_TAG}.js ${projectId} ${location} ${text}` ); - assert.match(output, /Translation: Zdravo svijete/); + assert.match(output, /Translation: Здраво Свете/); }); }); diff --git a/samples/test/v3beta1/translate_translate_text_beta.test.js b/samples/test/v3beta1/translate_translate_text_beta.test.js index 7ea78f16..39bdc4d8 100644 --- a/samples/test/v3beta1/translate_translate_text_beta.test.js +++ b/samples/test/v3beta1/translate_translate_text_beta.test.js @@ -32,6 +32,6 @@ describe(REGION_TAG, () => { const output = execSync( `node v3beta1/${REGION_TAG}.js ${projectId} ${location} ${text}` ); - assert.match(output, /Translation: Zdravo svijete/); + assert.match(output, /Translation: Здраво Свете/); }); }); diff --git a/src/v3/translation_service_client.ts b/src/v3/translation_service_client.ts index 50e653f7..a7bf7499 100644 --- a/src/v3/translation_service_client.ts +++ b/src/v3/translation_service_client.ts @@ -591,7 +591,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.translateText(request, options, callback); @@ -717,7 +717,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.detectLanguage(request, options, callback); @@ -844,7 +844,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.getSupportedLanguages(request, options, callback); @@ -992,7 +992,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.translateDocument(request, options, callback); @@ -1078,7 +1078,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getGlossary(request, options, callback); @@ -1238,7 +1238,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.batchTranslateText(request, options, callback); @@ -1435,7 +1435,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.batchTranslateDocument( @@ -1580,7 +1580,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.createGlossary(request, options, callback); @@ -1720,7 +1720,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.deleteGlossary(request, options, callback); @@ -1875,7 +1875,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listGlossaries(request, options, callback); @@ -1934,7 +1934,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listGlossaries']; const callSettings = defaultCallSettings.merge(options); @@ -2002,7 +2002,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listGlossaries']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/translation_service_client.ts b/src/v3beta1/translation_service_client.ts index 32795c3f..9fe11f56 100644 --- a/src/v3beta1/translation_service_client.ts +++ b/src/v3beta1/translation_service_client.ts @@ -591,7 +591,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.translateText(request, options, callback); @@ -722,7 +722,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.detectLanguage(request, options, callback); @@ -849,7 +849,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.getSupportedLanguages(request, options, callback); @@ -1002,7 +1002,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.translateDocument(request, options, callback); @@ -1094,7 +1094,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.getGlossary(request, options, callback); @@ -1253,7 +1253,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.batchTranslateText(request, options, callback); @@ -1450,7 +1450,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.batchTranslateDocument( @@ -1595,7 +1595,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.createGlossary(request, options, callback); @@ -1735,7 +1735,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); this.initialize(); return this.innerApiCalls.deleteGlossary(request, options, callback); @@ -1890,7 +1890,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); this.initialize(); return this.innerApiCalls.listGlossaries(request, options, callback); @@ -1949,7 +1949,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listGlossaries']; const callSettings = defaultCallSettings.merge(options); @@ -2017,7 +2017,7 @@ export class TranslationServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - parent: request.parent || '', + parent: request.parent ?? '', }); const defaultCallSettings = this._defaults['listGlossaries']; const callSettings = defaultCallSettings.merge(options); diff --git a/test/gapic_translation_service_v3.ts b/test/gapic_translation_service_v3.ts index bbb893d3..640f8160 100644 --- a/test/gapic_translation_service_v3.ts +++ b/test/gapic_translation_service_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -254,26 +269,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateTextResponse() ); client.innerApiCalls.translateText = stubSimpleCall(expectedResponse); const [response] = await client.translateText(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateText without error using callback', async () => { @@ -285,15 +300,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateTextResponse() ); @@ -316,11 +328,14 @@ describe('v3.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateText with error', async () => { @@ -332,26 +347,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.translateText = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.translateText(request), expectedError); - assert( - (client.innerApiCalls.translateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateText with closed client', async () => { @@ -363,7 +378,11 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateTextRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.translateText(request), expectedError); @@ -380,26 +399,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DetectLanguageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.DetectLanguageResponse() ); client.innerApiCalls.detectLanguage = stubSimpleCall(expectedResponse); const [response] = await client.detectLanguage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectLanguage without error using callback', async () => { @@ -411,15 +430,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DetectLanguageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.DetectLanguageResponse() ); @@ -442,11 +458,14 @@ describe('v3.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectLanguage with error', async () => { @@ -458,26 +477,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DetectLanguageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.detectLanguage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.detectLanguage(request), expectedError); - assert( - (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectLanguage with closed client', async () => { @@ -489,7 +508,11 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DetectLanguageRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.detectLanguage(request), expectedError); @@ -506,15 +529,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetSupportedLanguagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.SupportedLanguages() ); @@ -522,11 +542,14 @@ describe('v3.TranslationServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getSupportedLanguages(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSupportedLanguages without error using callback', async () => { @@ -538,15 +561,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetSupportedLanguagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.SupportedLanguages() ); @@ -569,11 +589,14 @@ describe('v3.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSupportedLanguages with error', async () => { @@ -585,15 +608,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetSupportedLanguagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getSupportedLanguages = stubSimpleCall( undefined, @@ -603,11 +623,14 @@ describe('v3.TranslationServiceClient', () => { client.getSupportedLanguages(request), expectedError ); - assert( - (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSupportedLanguages with closed client', async () => { @@ -619,7 +642,11 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetSupportedLanguagesRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -639,26 +666,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateDocumentResponse() ); client.innerApiCalls.translateDocument = stubSimpleCall(expectedResponse); const [response] = await client.translateDocument(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateDocument without error using callback', async () => { @@ -670,15 +697,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateDocumentResponse() ); @@ -701,11 +725,14 @@ describe('v3.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateDocument with error', async () => { @@ -717,26 +744,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.translateDocument = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.translateDocument(request), expectedError); - assert( - (client.innerApiCalls.translateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateDocument with closed client', async () => { @@ -748,7 +775,11 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.TranslateDocumentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.translateDocument(request), expectedError); @@ -765,26 +796,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.Glossary() ); client.innerApiCalls.getGlossary = stubSimpleCall(expectedResponse); const [response] = await client.getGlossary(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getGlossary without error using callback', async () => { @@ -796,15 +827,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3.Glossary() ); @@ -827,11 +855,14 @@ describe('v3.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getGlossary with error', async () => { @@ -843,26 +874,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getGlossary = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getGlossary(request), expectedError); - assert( - (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getGlossary with closed client', async () => { @@ -874,7 +905,11 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.GetGlossaryRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getGlossary(request), expectedError); @@ -891,15 +926,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -908,11 +940,14 @@ describe('v3.TranslationServiceClient', () => { const [operation] = await client.batchTranslateText(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateText without error using callback', async () => { @@ -924,15 +959,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -962,11 +994,14 @@ describe('v3.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateText with call error', async () => { @@ -978,26 +1013,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateText = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.batchTranslateText(request), expectedError); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateText with LRO error', async () => { @@ -1009,15 +1044,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateText = stubLongRunningCall( undefined, @@ -1026,11 +1058,14 @@ describe('v3.TranslationServiceClient', () => { ); const [operation] = await client.batchTranslateText(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkBatchTranslateTextProgress without error', async () => { @@ -1085,15 +1120,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1102,11 +1134,14 @@ describe('v3.TranslationServiceClient', () => { const [operation] = await client.batchTranslateDocument(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateDocument without error using callback', async () => { @@ -1118,15 +1153,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1156,11 +1188,14 @@ describe('v3.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateDocument with call error', async () => { @@ -1172,15 +1207,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateDocument = stubLongRunningCall( undefined, @@ -1190,11 +1222,14 @@ describe('v3.TranslationServiceClient', () => { client.batchTranslateDocument(request), expectedError ); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateDocument with LRO error', async () => { @@ -1206,15 +1241,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateDocument = stubLongRunningCall( undefined, @@ -1223,11 +1255,14 @@ describe('v3.TranslationServiceClient', () => { ); const [operation] = await client.batchTranslateDocument(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkBatchTranslateDocumentProgress without error', async () => { @@ -1282,15 +1317,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1299,11 +1331,14 @@ describe('v3.TranslationServiceClient', () => { const [operation] = await client.createGlossary(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createGlossary without error using callback', async () => { @@ -1315,15 +1350,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1353,11 +1385,14 @@ describe('v3.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createGlossary with call error', async () => { @@ -1369,26 +1404,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createGlossary = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createGlossary(request), expectedError); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createGlossary with LRO error', async () => { @@ -1400,15 +1435,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createGlossary = stubLongRunningCall( undefined, @@ -1417,11 +1449,14 @@ describe('v3.TranslationServiceClient', () => { ); const [operation] = await client.createGlossary(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateGlossaryProgress without error', async () => { @@ -1476,15 +1511,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1493,11 +1525,14 @@ describe('v3.TranslationServiceClient', () => { const [operation] = await client.deleteGlossary(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteGlossary without error using callback', async () => { @@ -1509,15 +1544,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1547,11 +1579,14 @@ describe('v3.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteGlossary with call error', async () => { @@ -1563,26 +1598,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteGlossary = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.deleteGlossary(request), expectedError); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteGlossary with LRO error', async () => { @@ -1594,15 +1629,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteGlossary = stubLongRunningCall( undefined, @@ -1611,11 +1643,14 @@ describe('v3.TranslationServiceClient', () => { ); const [operation] = await client.deleteGlossary(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkDeleteGlossaryProgress without error', async () => { @@ -1670,15 +1705,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3.Glossary() @@ -1693,11 +1725,14 @@ describe('v3.TranslationServiceClient', () => { client.innerApiCalls.listGlossaries = stubSimpleCall(expectedResponse); const [response] = await client.listGlossaries(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listGlossaries without error using callback', async () => { @@ -1709,15 +1744,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3.Glossary() @@ -1748,11 +1780,14 @@ describe('v3.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listGlossaries with error', async () => { @@ -1764,26 +1799,26 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listGlossaries = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listGlossaries(request), expectedError); - assert( - (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listGlossariesStream without error', async () => { @@ -1795,8 +1830,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3.Glossary() @@ -1833,11 +1872,12 @@ describe('v3.TranslationServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listGlossaries, request) ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1850,8 +1890,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listGlossaries.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1877,11 +1921,12 @@ describe('v3.TranslationServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listGlossaries, request) ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1894,8 +1939,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3.Glossary() @@ -1921,11 +1970,12 @@ describe('v3.TranslationServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1938,8 +1988,12 @@ describe('v3.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listGlossaries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1956,11 +2010,12 @@ describe('v3.TranslationServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_translation_service_v3beta1.ts b/test/gapic_translation_service_v3beta1.ts index 313d4c88..ba1f72d3 100644 --- a/test/gapic_translation_service_v3beta1.ts +++ b/test/gapic_translation_service_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, LROperation, operationsProtos} from 'google-gax'; +// Dynamically loaded proto JSON is needed to get the type information +// to fill in default values for request objects +const root = protobuf.Root.fromJSON( + require('../protos/protos.json') +).resolveAll(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function getTypeDefaultValue(typeName: string, fields: string[]) { + let type = root.lookupType(typeName) as protobuf.Type; + for (const field of fields.slice(0, -1)) { + type = type.fields[field]?.resolvedType as protobuf.Type; + } + return type.fields[fields[fields.length - 1]]?.defaultValue; +} + function generateSampleMessage(instance: T) { const filledObject = ( instance.constructor as typeof protobuf.Message @@ -263,26 +278,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateTextResponse() ); client.innerApiCalls.translateText = stubSimpleCall(expectedResponse); const [response] = await client.translateText(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateText without error using callback', async () => { @@ -295,15 +310,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateTextResponse() ); @@ -326,11 +338,14 @@ describe('v3beta1.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateText with error', async () => { @@ -343,26 +358,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.translateText = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.translateText(request), expectedError); - assert( - (client.innerApiCalls.translateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateText with closed client', async () => { @@ -375,7 +390,11 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateTextRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.translateText(request), expectedError); @@ -393,26 +412,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DetectLanguageResponse() ); client.innerApiCalls.detectLanguage = stubSimpleCall(expectedResponse); const [response] = await client.detectLanguage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectLanguage without error using callback', async () => { @@ -425,15 +444,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DetectLanguageResponse() ); @@ -456,11 +472,14 @@ describe('v3beta1.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectLanguage with error', async () => { @@ -473,26 +492,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.detectLanguage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.detectLanguage(request), expectedError); - assert( - (client.innerApiCalls.detectLanguage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectLanguage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectLanguage with closed client', async () => { @@ -505,7 +524,11 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DetectLanguageRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DetectLanguageRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.detectLanguage(request), expectedError); @@ -523,15 +546,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.SupportedLanguages() ); @@ -539,11 +559,14 @@ describe('v3beta1.TranslationServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getSupportedLanguages(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSupportedLanguages without error using callback', async () => { @@ -556,15 +579,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.SupportedLanguages() ); @@ -587,11 +607,14 @@ describe('v3beta1.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSupportedLanguages with error', async () => { @@ -604,15 +627,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getSupportedLanguages = stubSimpleCall( undefined, @@ -622,11 +642,14 @@ describe('v3beta1.TranslationServiceClient', () => { client.getSupportedLanguages(request), expectedError ); - assert( - (client.innerApiCalls.getSupportedLanguages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSupportedLanguages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSupportedLanguages with closed client', async () => { @@ -639,7 +662,11 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetSupportedLanguagesRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -660,26 +687,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateDocumentResponse() ); client.innerApiCalls.translateDocument = stubSimpleCall(expectedResponse); const [response] = await client.translateDocument(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateDocument without error using callback', async () => { @@ -692,15 +719,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateDocumentResponse() ); @@ -723,11 +747,14 @@ describe('v3beta1.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.translateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateDocument with error', async () => { @@ -740,26 +767,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.translateDocument = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.translateDocument(request), expectedError); - assert( - (client.innerApiCalls.translateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.translateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes translateDocument with closed client', async () => { @@ -772,7 +799,11 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.TranslateDocumentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.TranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.translateDocument(request), expectedError); @@ -790,26 +821,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.Glossary() ); client.innerApiCalls.getGlossary = stubSimpleCall(expectedResponse); const [response] = await client.getGlossary(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getGlossary without error using callback', async () => { @@ -822,15 +853,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.translation.v3beta1.Glossary() ); @@ -853,11 +881,14 @@ describe('v3beta1.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getGlossary with error', async () => { @@ -870,26 +901,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getGlossary = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getGlossary(request), expectedError); - assert( - (client.innerApiCalls.getGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getGlossary with closed client', async () => { @@ -902,7 +933,11 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.GetGlossaryRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.GetGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getGlossary(request), expectedError); @@ -920,15 +955,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -937,11 +969,14 @@ describe('v3beta1.TranslationServiceClient', () => { const [operation] = await client.batchTranslateText(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateText without error using callback', async () => { @@ -954,15 +989,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -992,11 +1024,14 @@ describe('v3beta1.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateText with call error', async () => { @@ -1009,26 +1044,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateText = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.batchTranslateText(request), expectedError); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateText with LRO error', async () => { @@ -1041,15 +1076,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateTextRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateTextRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateText = stubLongRunningCall( undefined, @@ -1058,11 +1090,14 @@ describe('v3beta1.TranslationServiceClient', () => { ); const [operation] = await client.batchTranslateText(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.batchTranslateText as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateText as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkBatchTranslateTextProgress without error', async () => { @@ -1120,15 +1155,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1137,11 +1169,14 @@ describe('v3beta1.TranslationServiceClient', () => { const [operation] = await client.batchTranslateDocument(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateDocument without error using callback', async () => { @@ -1154,15 +1189,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1192,11 +1224,14 @@ describe('v3beta1.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateDocument with call error', async () => { @@ -1209,15 +1244,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateDocument = stubLongRunningCall( undefined, @@ -1227,11 +1259,14 @@ describe('v3beta1.TranslationServiceClient', () => { client.batchTranslateDocument(request), expectedError ); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchTranslateDocument with LRO error', async () => { @@ -1244,15 +1279,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.BatchTranslateDocumentRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchTranslateDocument = stubLongRunningCall( undefined, @@ -1261,11 +1293,14 @@ describe('v3beta1.TranslationServiceClient', () => { ); const [operation] = await client.batchTranslateDocument(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.batchTranslateDocument as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchTranslateDocument as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkBatchTranslateDocumentProgress without error', async () => { @@ -1323,15 +1358,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1340,11 +1372,14 @@ describe('v3beta1.TranslationServiceClient', () => { const [operation] = await client.createGlossary(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createGlossary without error using callback', async () => { @@ -1357,15 +1392,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1395,11 +1427,14 @@ describe('v3beta1.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createGlossary with call error', async () => { @@ -1412,26 +1447,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createGlossary = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createGlossary(request), expectedError); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createGlossary with LRO error', async () => { @@ -1444,15 +1479,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.CreateGlossaryRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.CreateGlossaryRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createGlossary = stubLongRunningCall( undefined, @@ -1461,11 +1493,14 @@ describe('v3beta1.TranslationServiceClient', () => { ); const [operation] = await client.createGlossary(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateGlossaryProgress without error', async () => { @@ -1523,15 +1558,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1540,11 +1572,14 @@ describe('v3beta1.TranslationServiceClient', () => { const [operation] = await client.deleteGlossary(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteGlossary without error using callback', async () => { @@ -1557,15 +1592,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1595,11 +1627,14 @@ describe('v3beta1.TranslationServiceClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteGlossary with call error', async () => { @@ -1612,26 +1647,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteGlossary = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.deleteGlossary(request), expectedError); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteGlossary with LRO error', async () => { @@ -1644,15 +1679,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.DeleteGlossaryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.DeleteGlossaryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteGlossary = stubLongRunningCall( undefined, @@ -1661,11 +1693,14 @@ describe('v3beta1.TranslationServiceClient', () => { ); const [operation] = await client.deleteGlossary(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.deleteGlossary as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteGlossary as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkDeleteGlossaryProgress without error', async () => { @@ -1723,15 +1758,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3beta1.Glossary() @@ -1746,11 +1778,14 @@ describe('v3beta1.TranslationServiceClient', () => { client.innerApiCalls.listGlossaries = stubSimpleCall(expectedResponse); const [response] = await client.listGlossaries(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listGlossaries without error using callback', async () => { @@ -1763,15 +1798,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3beta1.Glossary() @@ -1802,11 +1834,14 @@ describe('v3beta1.TranslationServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listGlossaries with error', async () => { @@ -1819,26 +1854,26 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listGlossaries = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listGlossaries(request), expectedError); - assert( - (client.innerApiCalls.listGlossaries as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listGlossaries as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listGlossariesStream without error', async () => { @@ -1851,8 +1886,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3beta1.Glossary() @@ -1890,11 +1929,12 @@ describe('v3beta1.TranslationServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listGlossaries, request) ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1908,8 +1948,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listGlossaries.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1936,11 +1980,12 @@ describe('v3beta1.TranslationServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listGlossaries, request) ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1954,8 +1999,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.translation.v3beta1.Glossary() @@ -1981,11 +2030,12 @@ describe('v3beta1.TranslationServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1999,8 +2049,12 @@ describe('v3beta1.TranslationServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.translation.v3beta1.ListGlossariesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.translation.v3beta1.ListGlossariesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listGlossaries.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2018,11 +2072,12 @@ describe('v3beta1.TranslationServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listGlossaries.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listGlossaries.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); });