From ea654b5bf2e4067bf7682f9729cf8364ca4145a5 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 22:30:41 +0000 Subject: [PATCH] fix: preserve default values in x-goog-request-params header (#928) - [ ] Regenerate this pull request now. 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 --- src/v1/adaptation_client.ts | 28 +- src/v1p1beta1/adaptation_client.ts | 28 +- test/gapic_adaptation_v1.ts | 1033 +++++++++++++++------------- test/gapic_adaptation_v1p1beta1.ts | 1033 +++++++++++++++------------- test/gapic_speech_v1.ts | 58 +- test/gapic_speech_v1p1beta1.ts | 58 +- 6 files changed, 1142 insertions(+), 1096 deletions(-) diff --git a/src/v1/adaptation_client.ts b/src/v1/adaptation_client.ts index f4e12fc6..33eec017 100644 --- a/src/v1/adaptation_client.ts +++ b/src/v1/adaptation_client.ts @@ -446,7 +446,7 @@ export class AdaptationClient { 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.createPhraseSet(request, options, callback); @@ -537,7 +537,7 @@ export class AdaptationClient { 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.getPhraseSet(request, options, callback); @@ -635,7 +635,7 @@ export class AdaptationClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'phrase_set.name': request.phraseSet!.name || '', + 'phrase_set.name': request.phraseSet!.name ?? '', }); this.initialize(); return this.innerApiCalls.updatePhraseSet(request, options, callback); @@ -722,7 +722,7 @@ export class AdaptationClient { 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.deletePhraseSet(request, options, callback); @@ -829,7 +829,7 @@ export class AdaptationClient { 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.createCustomClass(request, options, callback); @@ -916,7 +916,7 @@ export class AdaptationClient { 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.getCustomClass(request, options, callback); @@ -1020,7 +1020,7 @@ export class AdaptationClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'custom_class.name': request.customClass!.name || '', + 'custom_class.name': request.customClass!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateCustomClass(request, options, callback); @@ -1119,7 +1119,7 @@ export class AdaptationClient { 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.deleteCustomClass(request, options, callback); @@ -1227,7 +1227,7 @@ export class AdaptationClient { 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.listPhraseSet(request, options, callback); @@ -1280,7 +1280,7 @@ export class AdaptationClient { 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['listPhraseSet']; const callSettings = defaultCallSettings.merge(options); @@ -1342,7 +1342,7 @@ export class AdaptationClient { 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['listPhraseSet']; const callSettings = defaultCallSettings.merge(options); @@ -1461,7 +1461,7 @@ export class AdaptationClient { 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.listCustomClasses(request, options, callback); @@ -1514,7 +1514,7 @@ export class AdaptationClient { 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['listCustomClasses']; const callSettings = defaultCallSettings.merge(options); @@ -1576,7 +1576,7 @@ export class AdaptationClient { 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['listCustomClasses']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v1p1beta1/adaptation_client.ts b/src/v1p1beta1/adaptation_client.ts index 3350fafd..80f1ff00 100644 --- a/src/v1p1beta1/adaptation_client.ts +++ b/src/v1p1beta1/adaptation_client.ts @@ -452,7 +452,7 @@ export class AdaptationClient { 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.createPhraseSet(request, options, callback); @@ -551,7 +551,7 @@ export class AdaptationClient { 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.getPhraseSet(request, options, callback); @@ -655,7 +655,7 @@ export class AdaptationClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'phrase_set.name': request.phraseSet!.name || '', + 'phrase_set.name': request.phraseSet!.name ?? '', }); this.initialize(); return this.innerApiCalls.updatePhraseSet(request, options, callback); @@ -748,7 +748,7 @@ export class AdaptationClient { 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.deletePhraseSet(request, options, callback); @@ -861,7 +861,7 @@ export class AdaptationClient { 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.createCustomClass(request, options, callback); @@ -954,7 +954,7 @@ export class AdaptationClient { 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.getCustomClass(request, options, callback); @@ -1064,7 +1064,7 @@ export class AdaptationClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'custom_class.name': request.customClass!.name || '', + 'custom_class.name': request.customClass!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateCustomClass(request, options, callback); @@ -1169,7 +1169,7 @@ export class AdaptationClient { 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.deleteCustomClass(request, options, callback); @@ -1283,7 +1283,7 @@ export class AdaptationClient { 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.listPhraseSet(request, options, callback); @@ -1336,7 +1336,7 @@ export class AdaptationClient { 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['listPhraseSet']; const callSettings = defaultCallSettings.merge(options); @@ -1398,7 +1398,7 @@ export class AdaptationClient { 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['listPhraseSet']; const callSettings = defaultCallSettings.merge(options); @@ -1517,7 +1517,7 @@ export class AdaptationClient { 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.listCustomClasses(request, options, callback); @@ -1570,7 +1570,7 @@ export class AdaptationClient { 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['listCustomClasses']; const callSettings = defaultCallSettings.merge(options); @@ -1632,7 +1632,7 @@ export class AdaptationClient { 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['listCustomClasses']; const callSettings = defaultCallSettings.merge(options); diff --git a/test/gapic_adaptation_v1.ts b/test/gapic_adaptation_v1.ts index 277eb4df..62d7debc 100644 --- a/test/gapic_adaptation_v1.ts +++ b/test/gapic_adaptation_v1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf} 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 @@ -220,26 +235,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreatePhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.PhraseSet() ); client.innerApiCalls.createPhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.createPhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPhraseSet without error using callback', async () => { @@ -251,15 +265,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreatePhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.PhraseSet() ); @@ -282,11 +292,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPhraseSet with error', async () => { @@ -298,26 +311,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreatePhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createPhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createPhraseSet(request), expectedError); - assert( - (client.innerApiCalls.createPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPhraseSet with closed client', async () => { @@ -329,7 +341,10 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreatePhraseSetRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createPhraseSet(request), expectedError); @@ -346,26 +361,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetPhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.PhraseSet() ); client.innerApiCalls.getPhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.getPhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPhraseSet without error using callback', async () => { @@ -377,15 +391,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetPhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.PhraseSet() ); @@ -408,11 +418,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPhraseSet with error', async () => { @@ -424,26 +437,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetPhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getPhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getPhraseSet(request), expectedError); - assert( - (client.innerApiCalls.getPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPhraseSet with closed client', async () => { @@ -455,7 +467,10 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetPhraseSetRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getPhraseSet(request), expectedError); @@ -472,27 +487,27 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; - const expectedHeaderRequestParams = 'phrase_set.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; + const expectedHeaderRequestParams = `phrase_set.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.PhraseSet() ); client.innerApiCalls.updatePhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.updatePhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePhraseSet without error using callback', async () => { @@ -504,16 +519,13 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; - const expectedHeaderRequestParams = 'phrase_set.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; + const expectedHeaderRequestParams = `phrase_set.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.PhraseSet() ); @@ -536,11 +548,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePhraseSet with error', async () => { @@ -552,27 +567,27 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; - const expectedHeaderRequestParams = 'phrase_set.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; + const expectedHeaderRequestParams = `phrase_set.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updatePhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updatePhraseSet(request), expectedError); - assert( - (client.innerApiCalls.updatePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePhraseSet with closed client', async () => { @@ -584,8 +599,12 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updatePhraseSet(request), expectedError); @@ -602,26 +621,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeletePhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deletePhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.deletePhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePhraseSet without error using callback', async () => { @@ -633,15 +651,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeletePhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -664,11 +678,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePhraseSet with error', async () => { @@ -680,26 +697,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeletePhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deletePhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deletePhraseSet(request), expectedError); - assert( - (client.innerApiCalls.deletePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePhraseSet with closed client', async () => { @@ -711,7 +727,10 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeletePhraseSetRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deletePhraseSet(request), expectedError); @@ -728,26 +747,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreateCustomClassRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.CustomClass() ); client.innerApiCalls.createCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.createCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCustomClass without error using callback', async () => { @@ -759,15 +777,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreateCustomClassRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.CustomClass() ); @@ -790,11 +804,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCustomClass with error', async () => { @@ -806,26 +823,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreateCustomClassRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createCustomClass(request), expectedError); - assert( - (client.innerApiCalls.createCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCustomClass with closed client', async () => { @@ -837,7 +853,10 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.CreateCustomClassRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createCustomClass(request), expectedError); @@ -854,26 +873,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.CustomClass() ); client.innerApiCalls.getCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.getCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCustomClass without error using callback', async () => { @@ -885,15 +903,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.CustomClass() ); @@ -916,11 +930,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCustomClass with error', async () => { @@ -932,26 +949,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getCustomClass(request), expectedError); - assert( - (client.innerApiCalls.getCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCustomClass with closed client', async () => { @@ -963,7 +979,10 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.GetCustomClassRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getCustomClass(request), expectedError); @@ -980,27 +999,27 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; - const expectedHeaderRequestParams = 'custom_class.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; + const expectedHeaderRequestParams = `custom_class.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.CustomClass() ); client.innerApiCalls.updateCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.updateCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCustomClass without error using callback', async () => { @@ -1012,16 +1031,13 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; - const expectedHeaderRequestParams = 'custom_class.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; + const expectedHeaderRequestParams = `custom_class.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.CustomClass() ); @@ -1044,11 +1060,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCustomClass with error', async () => { @@ -1060,27 +1079,27 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; - const expectedHeaderRequestParams = 'custom_class.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; + const expectedHeaderRequestParams = `custom_class.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateCustomClass(request), expectedError); - assert( - (client.innerApiCalls.updateCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCustomClass with closed client', async () => { @@ -1092,8 +1111,12 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateCustomClass(request), expectedError); @@ -1110,26 +1133,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeleteCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.deleteCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCustomClass without error using callback', async () => { @@ -1141,15 +1163,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeleteCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -1172,11 +1190,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCustomClass with error', async () => { @@ -1188,26 +1209,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeleteCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteCustomClass(request), expectedError); - assert( - (client.innerApiCalls.deleteCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCustomClass with closed client', async () => { @@ -1219,7 +1239,10 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.DeleteCustomClassRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteCustomClass(request), expectedError); @@ -1236,15 +1259,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), @@ -1253,11 +1272,14 @@ describe('v1.AdaptationClient', () => { client.innerApiCalls.listPhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.listPhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPhraseSet without error using callback', async () => { @@ -1269,15 +1291,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), @@ -1302,11 +1320,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPhraseSet with error', async () => { @@ -1318,26 +1339,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listPhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listPhraseSet(request), expectedError); - assert( - (client.innerApiCalls.listPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPhraseSetStream without error', async () => { @@ -1349,8 +1369,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), @@ -1381,11 +1404,12 @@ describe('v1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPhraseSet, request) ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1398,8 +1422,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPhraseSet.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1425,11 +1452,12 @@ describe('v1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPhraseSet, request) ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1442,8 +1470,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), generateSampleMessage(new protos.google.cloud.speech.v1.PhraseSet()), @@ -1463,11 +1494,12 @@ describe('v1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1480,8 +1512,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPhraseSet.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1498,11 +1533,12 @@ describe('v1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1517,15 +1553,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), @@ -1534,11 +1566,14 @@ describe('v1.AdaptationClient', () => { client.innerApiCalls.listCustomClasses = stubSimpleCall(expectedResponse); const [response] = await client.listCustomClasses(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listCustomClasses as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listCustomClasses without error using callback', async () => { @@ -1550,15 +1585,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), @@ -1583,11 +1614,14 @@ describe('v1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listCustomClasses as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listCustomClasses with error', async () => { @@ -1599,26 +1633,25 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listCustomClasses = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listCustomClasses(request), expectedError); - assert( - (client.innerApiCalls.listCustomClasses as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listCustomClassesStream without error', async () => { @@ -1630,8 +1663,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), @@ -1662,11 +1698,12 @@ describe('v1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listCustomClasses, request) ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1679,8 +1716,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listCustomClasses.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1706,11 +1746,12 @@ describe('v1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listCustomClasses, request) ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1723,8 +1764,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), generateSampleMessage(new protos.google.cloud.speech.v1.CustomClass()), @@ -1744,11 +1788,12 @@ describe('v1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1761,8 +1806,11 @@ describe('v1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listCustomClasses.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1779,11 +1827,12 @@ describe('v1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_adaptation_v1p1beta1.ts b/test/gapic_adaptation_v1p1beta1.ts index b36b2370..54b4c86f 100644 --- a/test/gapic_adaptation_v1p1beta1.ts +++ b/test/gapic_adaptation_v1p1beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf} 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 @@ -222,26 +237,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreatePhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() ); client.innerApiCalls.createPhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.createPhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPhraseSet without error using callback', async () => { @@ -253,15 +267,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreatePhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() ); @@ -284,11 +294,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPhraseSet with error', async () => { @@ -300,26 +313,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreatePhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createPhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createPhraseSet(request), expectedError); - assert( - (client.innerApiCalls.createPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPhraseSet with closed client', async () => { @@ -331,7 +343,10 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreatePhraseSetRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreatePhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createPhraseSet(request), expectedError); @@ -348,26 +363,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetPhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() ); client.innerApiCalls.getPhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.getPhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPhraseSet without error using callback', async () => { @@ -379,15 +393,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetPhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() ); @@ -410,11 +420,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPhraseSet with error', async () => { @@ -426,26 +439,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetPhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getPhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getPhraseSet(request), expectedError); - assert( - (client.innerApiCalls.getPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPhraseSet with closed client', async () => { @@ -457,7 +469,10 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetPhraseSetRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetPhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getPhraseSet(request), expectedError); @@ -474,27 +489,27 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; - const expectedHeaderRequestParams = 'phrase_set.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; + const expectedHeaderRequestParams = `phrase_set.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() ); client.innerApiCalls.updatePhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.updatePhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePhraseSet without error using callback', async () => { @@ -506,16 +521,13 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; - const expectedHeaderRequestParams = 'phrase_set.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; + const expectedHeaderRequestParams = `phrase_set.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() ); @@ -538,11 +550,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePhraseSet with error', async () => { @@ -554,27 +569,27 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; - const expectedHeaderRequestParams = 'phrase_set.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; + const expectedHeaderRequestParams = `phrase_set.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updatePhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updatePhraseSet(request), expectedError); - assert( - (client.innerApiCalls.updatePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePhraseSet with closed client', async () => { @@ -586,8 +601,12 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdatePhraseSetRequest() ); - request.phraseSet = {}; - request.phraseSet.name = ''; + request.phraseSet ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePhraseSetRequest', [ + 'phraseSet', + 'name', + ]); + request.phraseSet.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updatePhraseSet(request), expectedError); @@ -604,26 +623,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeletePhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deletePhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.deletePhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePhraseSet without error using callback', async () => { @@ -635,15 +653,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeletePhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -666,11 +680,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePhraseSet with error', async () => { @@ -682,26 +699,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeletePhraseSetRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deletePhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deletePhraseSet(request), expectedError); - assert( - (client.innerApiCalls.deletePhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePhraseSet with closed client', async () => { @@ -713,7 +729,10 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeletePhraseSetRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeletePhraseSetRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deletePhraseSet(request), expectedError); @@ -730,26 +749,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreateCustomClassRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() ); client.innerApiCalls.createCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.createCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCustomClass without error using callback', async () => { @@ -761,15 +779,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreateCustomClassRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() ); @@ -792,11 +806,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCustomClass with error', async () => { @@ -808,26 +825,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreateCustomClassRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createCustomClass(request), expectedError); - assert( - (client.innerApiCalls.createCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createCustomClass with closed client', async () => { @@ -839,7 +855,10 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CreateCustomClassRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateCustomClassRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createCustomClass(request), expectedError); @@ -856,26 +875,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() ); client.innerApiCalls.getCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.getCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCustomClass without error using callback', async () => { @@ -887,15 +905,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() ); @@ -918,11 +932,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCustomClass with error', async () => { @@ -934,26 +951,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getCustomClass(request), expectedError); - assert( - (client.innerApiCalls.getCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getCustomClass with closed client', async () => { @@ -965,7 +981,10 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.GetCustomClassRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getCustomClass(request), expectedError); @@ -982,27 +1001,27 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; - const expectedHeaderRequestParams = 'custom_class.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; + const expectedHeaderRequestParams = `custom_class.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() ); client.innerApiCalls.updateCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.updateCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCustomClass without error using callback', async () => { @@ -1014,16 +1033,13 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; - const expectedHeaderRequestParams = 'custom_class.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; + const expectedHeaderRequestParams = `custom_class.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() ); @@ -1046,11 +1062,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCustomClass with error', async () => { @@ -1062,27 +1081,27 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; - const expectedHeaderRequestParams = 'custom_class.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; + const expectedHeaderRequestParams = `custom_class.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateCustomClass(request), expectedError); - assert( - (client.innerApiCalls.updateCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateCustomClass with closed client', async () => { @@ -1094,8 +1113,12 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.UpdateCustomClassRequest() ); - request.customClass = {}; - request.customClass.name = ''; + request.customClass ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateCustomClassRequest', [ + 'customClass', + 'name', + ]); + request.customClass.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateCustomClass(request), expectedError); @@ -1112,26 +1135,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeleteCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteCustomClass = stubSimpleCall(expectedResponse); const [response] = await client.deleteCustomClass(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCustomClass without error using callback', async () => { @@ -1143,15 +1165,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeleteCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -1174,11 +1192,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCustomClass with error', async () => { @@ -1190,26 +1211,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeleteCustomClassRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteCustomClass = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteCustomClass(request), expectedError); - assert( - (client.innerApiCalls.deleteCustomClass as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteCustomClass as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteCustomClass with closed client', async () => { @@ -1221,7 +1241,10 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.DeleteCustomClassRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteCustomClassRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteCustomClass(request), expectedError); @@ -1238,15 +1261,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() @@ -1261,11 +1280,14 @@ describe('v1p1beta1.AdaptationClient', () => { client.innerApiCalls.listPhraseSet = stubSimpleCall(expectedResponse); const [response] = await client.listPhraseSet(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPhraseSet without error using callback', async () => { @@ -1277,15 +1299,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() @@ -1316,11 +1334,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPhraseSet with error', async () => { @@ -1332,26 +1353,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listPhraseSet = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listPhraseSet(request), expectedError); - assert( - (client.innerApiCalls.listPhraseSet as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPhraseSet as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPhraseSetStream without error', async () => { @@ -1363,8 +1383,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() @@ -1401,11 +1424,12 @@ describe('v1p1beta1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPhraseSet, request) ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1418,8 +1442,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPhraseSet.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1445,11 +1472,12 @@ describe('v1p1beta1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPhraseSet, request) ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1462,8 +1490,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.PhraseSet() @@ -1489,11 +1520,12 @@ describe('v1p1beta1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1506,8 +1538,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListPhraseSetRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPhraseSetRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPhraseSet.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1524,11 +1559,12 @@ describe('v1p1beta1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listPhraseSet.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPhraseSet.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1543,15 +1579,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() @@ -1566,11 +1598,14 @@ describe('v1p1beta1.AdaptationClient', () => { client.innerApiCalls.listCustomClasses = stubSimpleCall(expectedResponse); const [response] = await client.listCustomClasses(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listCustomClasses as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listCustomClasses without error using callback', async () => { @@ -1582,15 +1617,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() @@ -1621,11 +1652,14 @@ describe('v1p1beta1.AdaptationClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listCustomClasses as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listCustomClasses with error', async () => { @@ -1637,26 +1671,25 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listCustomClasses = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listCustomClasses(request), expectedError); - assert( - (client.innerApiCalls.listCustomClasses as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listCustomClasses as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listCustomClassesStream without error', async () => { @@ -1668,8 +1701,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() @@ -1707,11 +1743,12 @@ describe('v1p1beta1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listCustomClasses, request) ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1724,8 +1761,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listCustomClasses.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1752,11 +1792,12 @@ describe('v1p1beta1.AdaptationClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listCustomClasses, request) ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1769,8 +1810,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.CustomClass() @@ -1796,11 +1840,12 @@ describe('v1p1beta1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1813,8 +1858,11 @@ describe('v1p1beta1.AdaptationClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.ListCustomClassesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListCustomClassesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listCustomClasses.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1832,11 +1880,12 @@ describe('v1p1beta1.AdaptationClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listCustomClasses.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listCustomClasses.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_speech_v1.ts b/test/gapic_speech_v1.ts index e7e18321..5ff11d05 100644 --- a/test/gapic_speech_v1.ts +++ b/test/gapic_speech_v1.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 @@ -205,18 +220,12 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.RecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.RecognizeResponse() ); client.innerApiCalls.recognize = stubSimpleCall(expectedResponse); const [response] = await client.recognize(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.recognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes recognize without error using callback', async () => { @@ -228,7 +237,6 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.RecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.RecognizeResponse() ); @@ -251,11 +259,6 @@ describe('v1.SpeechClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.recognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes recognize with error', async () => { @@ -267,15 +270,9 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.RecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.recognize = stubSimpleCall(undefined, expectedError); await assert.rejects(client.recognize(request), expectedError); - assert( - (client.innerApiCalls.recognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes recognize with closed client', async () => { @@ -303,7 +300,6 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -312,11 +308,6 @@ describe('v1.SpeechClient', () => { const [operation] = await client.longRunningRecognize(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes longRunningRecognize without error using callback', async () => { @@ -328,7 +319,6 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -358,11 +348,6 @@ describe('v1.SpeechClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes longRunningRecognize with call error', async () => { @@ -374,18 +359,12 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.longRunningRecognize = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.longRunningRecognize(request), expectedError); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes longRunningRecognize with LRO error', async () => { @@ -397,7 +376,6 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.longRunningRecognize = stubLongRunningCall( undefined, @@ -406,11 +384,6 @@ describe('v1.SpeechClient', () => { ); const [operation] = await client.longRunningRecognize(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes checkLongRunningRecognizeProgress without error', async () => { @@ -465,6 +438,7 @@ describe('v1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1.StreamingRecognizeRequest() ); + const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1.StreamingRecognizeResponse() ); diff --git a/test/gapic_speech_v1p1beta1.ts b/test/gapic_speech_v1p1beta1.ts index 2121fdfa..9784590e 100644 --- a/test/gapic_speech_v1p1beta1.ts +++ b/test/gapic_speech_v1p1beta1.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 @@ -205,18 +220,12 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.RecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.RecognizeResponse() ); client.innerApiCalls.recognize = stubSimpleCall(expectedResponse); const [response] = await client.recognize(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.recognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes recognize without error using callback', async () => { @@ -228,7 +237,6 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.RecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.RecognizeResponse() ); @@ -251,11 +259,6 @@ describe('v1p1beta1.SpeechClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.recognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes recognize with error', async () => { @@ -267,15 +270,9 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.RecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.recognize = stubSimpleCall(undefined, expectedError); await assert.rejects(client.recognize(request), expectedError); - assert( - (client.innerApiCalls.recognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes recognize with closed client', async () => { @@ -303,7 +300,6 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -312,11 +308,6 @@ describe('v1p1beta1.SpeechClient', () => { const [operation] = await client.longRunningRecognize(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes longRunningRecognize without error using callback', async () => { @@ -328,7 +319,6 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -358,11 +348,6 @@ describe('v1p1beta1.SpeechClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); }); it('invokes longRunningRecognize with call error', async () => { @@ -374,18 +359,12 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.longRunningRecognize = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.longRunningRecognize(request), expectedError); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes longRunningRecognize with LRO error', async () => { @@ -397,7 +376,6 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.LongRunningRecognizeRequest() ); - const expectedOptions = {otherArgs: {headers: {}}}; const expectedError = new Error('expected'); client.innerApiCalls.longRunningRecognize = stubLongRunningCall( undefined, @@ -406,11 +384,6 @@ describe('v1p1beta1.SpeechClient', () => { ); const [operation] = await client.longRunningRecognize(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.longRunningRecognize as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); }); it('invokes checkLongRunningRecognizeProgress without error', async () => { @@ -465,6 +438,7 @@ describe('v1p1beta1.SpeechClient', () => { const request = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.StreamingRecognizeRequest() ); + const expectedResponse = generateSampleMessage( new protos.google.cloud.speech.v1p1beta1.StreamingRecognizeResponse() );