diff --git a/src/v3/agents_client.ts b/src/v3/agents_client.ts index 7be60267..3f9ad8c0 100644 --- a/src/v3/agents_client.ts +++ b/src/v3/agents_client.ts @@ -566,7 +566,7 @@ export class AgentsClient { 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.getAgent(request, options, callback); @@ -664,7 +664,7 @@ export class AgentsClient { 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.createAgent(request, options, callback); @@ -762,7 +762,7 @@ export class AgentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'agent.name': request.agent!.name || '', + 'agent.name': request.agent!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateAgent(request, options, callback); @@ -854,7 +854,7 @@ export class AgentsClient { 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.deleteAgent(request, options, callback); @@ -950,7 +950,7 @@ export class AgentsClient { 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.validateAgent(request, options, callback); @@ -1052,7 +1052,7 @@ export class AgentsClient { 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.getAgentValidationResult( @@ -1186,7 +1186,7 @@ export class AgentsClient { 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.exportAgent(request, options, callback); @@ -1355,7 +1355,7 @@ export class AgentsClient { 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.restoreAgent(request, options, callback); @@ -1487,7 +1487,7 @@ export class AgentsClient { 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.listAgents(request, options, callback); @@ -1527,7 +1527,7 @@ export class AgentsClient { 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['listAgents']; const callSettings = defaultCallSettings.merge(options); @@ -1576,7 +1576,7 @@ export class AgentsClient { 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['listAgents']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/changelogs_client.ts b/src/v3/changelogs_client.ts index 530b2391..e3c87893 100644 --- a/src/v3/changelogs_client.ts +++ b/src/v3/changelogs_client.ts @@ -536,7 +536,7 @@ export class ChangelogsClient { 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.getChangelog(request, options, callback); @@ -658,7 +658,7 @@ export class ChangelogsClient { 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.listChangelogs(request, options, callback); @@ -719,7 +719,7 @@ export class ChangelogsClient { 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['listChangelogs']; const callSettings = defaultCallSettings.merge(options); @@ -789,7 +789,7 @@ export class ChangelogsClient { 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['listChangelogs']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/deployments_client.ts b/src/v3/deployments_client.ts index d00518ee..44389ba2 100644 --- a/src/v3/deployments_client.ts +++ b/src/v3/deployments_client.ts @@ -536,7 +536,7 @@ export class DeploymentsClient { 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.getDeployment(request, options, callback); @@ -638,7 +638,7 @@ export class DeploymentsClient { 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.listDeployments(request, options, callback); @@ -679,7 +679,7 @@ export class DeploymentsClient { 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['listDeployments']; const callSettings = defaultCallSettings.merge(options); @@ -729,7 +729,7 @@ export class DeploymentsClient { 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['listDeployments']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/entity_types_client.ts b/src/v3/entity_types_client.ts index 6a3c042b..183741e5 100644 --- a/src/v3/entity_types_client.ts +++ b/src/v3/entity_types_client.ts @@ -555,7 +555,7 @@ export class EntityTypesClient { 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.getEntityType(request, options, callback); @@ -665,7 +665,7 @@ export class EntityTypesClient { 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.createEntityType(request, options, callback); @@ -774,7 +774,7 @@ export class EntityTypesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'entity_type.name': request.entityType!.name || '', + 'entity_type.name': request.entityType!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateEntityType(request, options, callback); @@ -882,7 +882,7 @@ export class EntityTypesClient { 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.deleteEntityType(request, options, callback); @@ -996,7 +996,7 @@ export class EntityTypesClient { 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.listEntityTypes(request, options, callback); @@ -1049,7 +1049,7 @@ export class EntityTypesClient { 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['listEntityTypes']; const callSettings = defaultCallSettings.merge(options); @@ -1111,7 +1111,7 @@ export class EntityTypesClient { 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['listEntityTypes']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/environments_client.ts b/src/v3/environments_client.ts index 5486ca64..dafe9f7e 100644 --- a/src/v3/environments_client.ts +++ b/src/v3/environments_client.ts @@ -605,7 +605,7 @@ export class EnvironmentsClient { 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.getEnvironment(request, options, callback); @@ -704,7 +704,7 @@ export class EnvironmentsClient { 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.deleteEnvironment(request, options, callback); @@ -819,7 +819,7 @@ export class EnvironmentsClient { 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.createEnvironment(request, options, callback); @@ -967,7 +967,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'environment.name': request.environment!.name || '', + 'environment.name': request.environment!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateEnvironment(request, options, callback); @@ -1113,7 +1113,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - environment: request.environment || '', + environment: request.environment ?? '', }); this.initialize(); return this.innerApiCalls.runContinuousTest(request, options, callback); @@ -1264,7 +1264,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - environment: request.environment || '', + environment: request.environment ?? '', }); this.initialize(); return this.innerApiCalls.deployFlow(request, options, callback); @@ -1399,7 +1399,7 @@ export class EnvironmentsClient { 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.listEnvironments(request, options, callback); @@ -1439,7 +1439,7 @@ export class EnvironmentsClient { 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['listEnvironments']; const callSettings = defaultCallSettings.merge(options); @@ -1488,7 +1488,7 @@ export class EnvironmentsClient { 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['listEnvironments']; const callSettings = defaultCallSettings.merge(options); @@ -1595,7 +1595,7 @@ export class EnvironmentsClient { 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.lookupEnvironmentHistory( @@ -1640,7 +1640,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); const defaultCallSettings = this._defaults['lookupEnvironmentHistory']; const callSettings = defaultCallSettings.merge(options); @@ -1690,7 +1690,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); const defaultCallSettings = this._defaults['lookupEnvironmentHistory']; const callSettings = defaultCallSettings.merge(options); @@ -1797,7 +1797,7 @@ export class EnvironmentsClient { 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.listContinuousTestResults( @@ -1842,7 +1842,7 @@ export class EnvironmentsClient { 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['listContinuousTestResults']; const callSettings = defaultCallSettings.merge(options); @@ -1892,7 +1892,7 @@ export class EnvironmentsClient { 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['listContinuousTestResults']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/experiments_client.ts b/src/v3/experiments_client.ts index d5307a13..5d60861a 100644 --- a/src/v3/experiments_client.ts +++ b/src/v3/experiments_client.ts @@ -544,7 +544,7 @@ export class ExperimentsClient { 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.getExperiment(request, options, callback); @@ -639,7 +639,7 @@ export class ExperimentsClient { 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.createExperiment(request, options, callback); @@ -732,7 +732,7 @@ export class ExperimentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'experiment.name': request.experiment!.name || '', + 'experiment.name': request.experiment!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateExperiment(request, options, callback); @@ -825,7 +825,7 @@ export class ExperimentsClient { 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.deleteExperiment(request, options, callback); @@ -919,7 +919,7 @@ export class ExperimentsClient { 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.startExperiment(request, options, callback); @@ -1013,7 +1013,7 @@ export class ExperimentsClient { 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.stopExperiment(request, options, callback); @@ -1115,7 +1115,7 @@ export class ExperimentsClient { 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.listExperiments(request, options, callback); @@ -1156,7 +1156,7 @@ export class ExperimentsClient { 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['listExperiments']; const callSettings = defaultCallSettings.merge(options); @@ -1206,7 +1206,7 @@ export class ExperimentsClient { 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['listExperiments']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/flows_client.ts b/src/v3/flows_client.ts index 52596d10..ba7684c4 100644 --- a/src/v3/flows_client.ts +++ b/src/v3/flows_client.ts @@ -603,7 +603,7 @@ export class FlowsClient { 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.createFlow(request, options, callback); @@ -707,7 +707,7 @@ export class FlowsClient { 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.deleteFlow(request, options, callback); @@ -808,7 +808,7 @@ export class FlowsClient { 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.getFlow(request, options, callback); @@ -919,7 +919,7 @@ export class FlowsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'flow.name': request.flow!.name || '', + 'flow.name': request.flow!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateFlow(request, options, callback); @@ -1016,7 +1016,7 @@ export class FlowsClient { 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.validateFlow(request, options, callback); @@ -1118,7 +1118,7 @@ export class FlowsClient { 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.getFlowValidationResult( @@ -1242,7 +1242,7 @@ export class FlowsClient { 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.trainFlow(request, options, callback); @@ -1404,7 +1404,7 @@ export class FlowsClient { 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.importFlow(request, options, callback); @@ -1568,7 +1568,7 @@ export class FlowsClient { 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.exportFlow(request, options, callback); @@ -1717,7 +1717,7 @@ export class FlowsClient { 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.listFlows(request, options, callback); @@ -1771,7 +1771,7 @@ export class FlowsClient { 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['listFlows']; const callSettings = defaultCallSettings.merge(options); @@ -1834,7 +1834,7 @@ export class FlowsClient { 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['listFlows']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/intents_client.ts b/src/v3/intents_client.ts index 8796d639..f04f59b7 100644 --- a/src/v3/intents_client.ts +++ b/src/v3/intents_client.ts @@ -547,7 +547,7 @@ export class IntentsClient { 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.getIntent(request, options, callback); @@ -655,7 +655,7 @@ export class IntentsClient { 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.createIntent(request, options, callback); @@ -763,7 +763,7 @@ export class IntentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'intent.name': request.intent!.name || '', + 'intent.name': request.intent!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateIntent(request, options, callback); @@ -860,7 +860,7 @@ export class IntentsClient { 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.deleteIntent(request, options, callback); @@ -974,7 +974,7 @@ export class IntentsClient { 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.listIntents(request, options, callback); @@ -1027,7 +1027,7 @@ export class IntentsClient { 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['listIntents']; const callSettings = defaultCallSettings.merge(options); @@ -1089,7 +1089,7 @@ export class IntentsClient { 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['listIntents']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/pages_client.ts b/src/v3/pages_client.ts index 566f4795..55969cdf 100644 --- a/src/v3/pages_client.ts +++ b/src/v3/pages_client.ts @@ -558,7 +558,7 @@ export class PagesClient { 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.getPage(request, options, callback); @@ -678,7 +678,7 @@ export class PagesClient { 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.createPage(request, options, callback); @@ -797,7 +797,7 @@ export class PagesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'page.name': request.page!.name || '', + 'page.name': request.page!.name ?? '', }); this.initialize(); return this.innerApiCalls.updatePage(request, options, callback); @@ -905,7 +905,7 @@ export class PagesClient { 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.deletePage(request, options, callback); @@ -1029,7 +1029,7 @@ export class PagesClient { 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.listPages(request, options, callback); @@ -1092,7 +1092,7 @@ export class PagesClient { 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['listPages']; const callSettings = defaultCallSettings.merge(options); @@ -1164,7 +1164,7 @@ export class PagesClient { 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['listPages']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/security_settings_service_client.ts b/src/v3/security_settings_service_client.ts index 6f161a69..4338fb92 100644 --- a/src/v3/security_settings_service_client.ts +++ b/src/v3/security_settings_service_client.ts @@ -567,7 +567,7 @@ export class SecuritySettingsServiceClient { 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.createSecuritySettings( @@ -671,7 +671,7 @@ export class SecuritySettingsServiceClient { 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.getSecuritySettings(request, options, callback); @@ -772,7 +772,7 @@ export class SecuritySettingsServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'security_settings.name': request.securitySettings!.name || '', + 'security_settings.name': request.securitySettings!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateSecuritySettings( @@ -875,7 +875,7 @@ export class SecuritySettingsServiceClient { 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.deleteSecuritySettings( @@ -980,7 +980,7 @@ export class SecuritySettingsServiceClient { 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.listSecuritySettings(request, options, callback); @@ -1020,7 +1020,7 @@ export class SecuritySettingsServiceClient { 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['listSecuritySettings']; const callSettings = defaultCallSettings.merge(options); @@ -1069,7 +1069,7 @@ export class SecuritySettingsServiceClient { 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['listSecuritySettings']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/session_entity_types_client.ts b/src/v3/session_entity_types_client.ts index fb80c7d4..96764b6e 100644 --- a/src/v3/session_entity_types_client.ts +++ b/src/v3/session_entity_types_client.ts @@ -556,7 +556,7 @@ export class SessionEntityTypesClient { 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.getSessionEntityType(request, options, callback); @@ -660,7 +660,7 @@ export class SessionEntityTypesClient { 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.createSessionEntityType( @@ -769,7 +769,7 @@ export class SessionEntityTypesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'session_entity_type.name': request.sessionEntityType!.name || '', + 'session_entity_type.name': request.sessionEntityType!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateSessionEntityType( @@ -876,7 +876,7 @@ export class SessionEntityTypesClient { 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.deleteSessionEntityType( @@ -985,7 +985,7 @@ export class SessionEntityTypesClient { 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.listSessionEntityTypes( @@ -1033,7 +1033,7 @@ export class SessionEntityTypesClient { 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['listSessionEntityTypes']; const callSettings = defaultCallSettings.merge(options); @@ -1086,7 +1086,7 @@ export class SessionEntityTypesClient { 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['listSessionEntityTypes']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/sessions_client.ts b/src/v3/sessions_client.ts index 9464af84..e95ede07 100644 --- a/src/v3/sessions_client.ts +++ b/src/v3/sessions_client.ts @@ -578,7 +578,7 @@ export class SessionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - session: request.session || '', + session: request.session ?? '', }); this.initialize(); return this.innerApiCalls.detectIntent(request, options, callback); @@ -685,7 +685,7 @@ export class SessionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - session: request.session || '', + session: request.session ?? '', }); this.initialize(); return this.innerApiCalls.matchIntent(request, options, callback); @@ -784,7 +784,7 @@ export class SessionsClient { options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'match_intent_request.session': - request.matchIntentRequest!.session || '', + request.matchIntentRequest!.session ?? '', }); this.initialize(); return this.innerApiCalls.fulfillIntent(request, options, callback); diff --git a/src/v3/test_cases_client.ts b/src/v3/test_cases_client.ts index d2811aac..f053a0fa 100644 --- a/src/v3/test_cases_client.ts +++ b/src/v3/test_cases_client.ts @@ -612,7 +612,7 @@ export class TestCasesClient { 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.batchDeleteTestCases(request, options, callback); @@ -705,7 +705,7 @@ export class TestCasesClient { 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.getTestCase(request, options, callback); @@ -799,7 +799,7 @@ export class TestCasesClient { 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.createTestCase(request, options, callback); @@ -894,7 +894,7 @@ export class TestCasesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'test_case.name': request.testCase!.name || '', + 'test_case.name': request.testCase!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateTestCase(request, options, callback); @@ -994,7 +994,7 @@ export class TestCasesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - agent: request.agent || '', + agent: request.agent ?? '', }); this.initialize(); return this.innerApiCalls.calculateCoverage(request, options, callback); @@ -1093,7 +1093,7 @@ export class TestCasesClient { 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.getTestCaseResult(request, options, callback); @@ -1209,7 +1209,7 @@ export class TestCasesClient { 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.runTestCase(request, options, callback); @@ -1362,7 +1362,7 @@ export class TestCasesClient { 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.batchRunTestCases(request, options, callback); @@ -1522,7 +1522,7 @@ export class TestCasesClient { 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.importTestCases(request, options, callback); @@ -1694,7 +1694,7 @@ export class TestCasesClient { 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.exportTestCases(request, options, callback); @@ -1832,7 +1832,7 @@ export class TestCasesClient { 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.listTestCases(request, options, callback); @@ -1875,7 +1875,7 @@ export class TestCasesClient { 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['listTestCases']; const callSettings = defaultCallSettings.merge(options); @@ -1927,7 +1927,7 @@ export class TestCasesClient { 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['listTestCases']; const callSettings = defaultCallSettings.merge(options); @@ -2060,7 +2060,7 @@ export class TestCasesClient { 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.listTestCaseResults(request, options, callback); @@ -2127,7 +2127,7 @@ export class TestCasesClient { 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['listTestCaseResults']; const callSettings = defaultCallSettings.merge(options); @@ -2203,7 +2203,7 @@ export class TestCasesClient { 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['listTestCaseResults']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/transition_route_groups_client.ts b/src/v3/transition_route_groups_client.ts index e61b2595..7a791e32 100644 --- a/src/v3/transition_route_groups_client.ts +++ b/src/v3/transition_route_groups_client.ts @@ -563,7 +563,7 @@ export class TransitionRouteGroupsClient { 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.getTransitionRouteGroup( @@ -684,7 +684,7 @@ export class TransitionRouteGroupsClient { 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.createTransitionRouteGroup( @@ -803,7 +803,7 @@ export class TransitionRouteGroupsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'transition_route_group.name': request.transitionRouteGroup!.name || '', + 'transition_route_group.name': request.transitionRouteGroup!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateTransitionRouteGroup( @@ -918,7 +918,7 @@ export class TransitionRouteGroupsClient { 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.deleteTransitionRouteGroup( @@ -1038,7 +1038,7 @@ export class TransitionRouteGroupsClient { 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.listTransitionRouteGroups( @@ -1097,7 +1097,7 @@ export class TransitionRouteGroupsClient { 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['listTransitionRouteGroups']; const callSettings = defaultCallSettings.merge(options); @@ -1161,7 +1161,7 @@ export class TransitionRouteGroupsClient { 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['listTransitionRouteGroups']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/versions_client.ts b/src/v3/versions_client.ts index c9db4f6d..92284734 100644 --- a/src/v3/versions_client.ts +++ b/src/v3/versions_client.ts @@ -571,7 +571,7 @@ export class VersionsClient { 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.getVersion(request, options, callback); @@ -665,7 +665,7 @@ export class VersionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'version.name': request.version!.name || '', + 'version.name': request.version!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateVersion(request, options, callback); @@ -758,7 +758,7 @@ export class VersionsClient { 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.deleteVersion(request, options, callback); @@ -866,7 +866,7 @@ export class VersionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - base_version: request.baseVersion || '', + base_version: request.baseVersion ?? '', }); this.initialize(); return this.innerApiCalls.compareVersions(request, options, callback); @@ -981,7 +981,7 @@ export class VersionsClient { 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.createVersion(request, options, callback); @@ -1135,7 +1135,7 @@ export class VersionsClient { 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.loadVersion(request, options, callback); @@ -1268,7 +1268,7 @@ export class VersionsClient { 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.listVersions(request, options, callback); @@ -1309,7 +1309,7 @@ export class VersionsClient { 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['listVersions']; const callSettings = defaultCallSettings.merge(options); @@ -1359,7 +1359,7 @@ export class VersionsClient { 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['listVersions']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3/webhooks_client.ts b/src/v3/webhooks_client.ts index 335d4e71..4d1cda73 100644 --- a/src/v3/webhooks_client.ts +++ b/src/v3/webhooks_client.ts @@ -549,7 +549,7 @@ export class WebhooksClient { 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.getWebhook(request, options, callback); @@ -643,7 +643,7 @@ export class WebhooksClient { 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.createWebhook(request, options, callback); @@ -737,7 +737,7 @@ export class WebhooksClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'webhook.name': request.webhook!.name || '', + 'webhook.name': request.webhook!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateWebhook(request, options, callback); @@ -840,7 +840,7 @@ export class WebhooksClient { 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.deleteWebhook(request, options, callback); @@ -941,7 +941,7 @@ export class WebhooksClient { 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.listWebhooks(request, options, callback); @@ -981,7 +981,7 @@ export class WebhooksClient { 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['listWebhooks']; const callSettings = defaultCallSettings.merge(options); @@ -1030,7 +1030,7 @@ export class WebhooksClient { 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['listWebhooks']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/agents_client.ts b/src/v3beta1/agents_client.ts index 3f1fa727..f6d59991 100644 --- a/src/v3beta1/agents_client.ts +++ b/src/v3beta1/agents_client.ts @@ -574,7 +574,7 @@ export class AgentsClient { 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.getAgent(request, options, callback); @@ -672,7 +672,7 @@ export class AgentsClient { 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.createAgent(request, options, callback); @@ -770,7 +770,7 @@ export class AgentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'agent.name': request.agent!.name || '', + 'agent.name': request.agent!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateAgent(request, options, callback); @@ -862,7 +862,7 @@ export class AgentsClient { 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.deleteAgent(request, options, callback); @@ -964,7 +964,7 @@ export class AgentsClient { 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.validateAgent(request, options, callback); @@ -1066,7 +1066,7 @@ export class AgentsClient { 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.getAgentValidationResult( @@ -1200,7 +1200,7 @@ export class AgentsClient { 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.exportAgent(request, options, callback); @@ -1369,7 +1369,7 @@ export class AgentsClient { 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.restoreAgent(request, options, callback); @@ -1501,7 +1501,7 @@ export class AgentsClient { 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.listAgents(request, options, callback); @@ -1541,7 +1541,7 @@ export class AgentsClient { 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['listAgents']; const callSettings = defaultCallSettings.merge(options); @@ -1590,7 +1590,7 @@ export class AgentsClient { 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['listAgents']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/changelogs_client.ts b/src/v3beta1/changelogs_client.ts index b974e225..445bd064 100644 --- a/src/v3beta1/changelogs_client.ts +++ b/src/v3beta1/changelogs_client.ts @@ -544,7 +544,7 @@ export class ChangelogsClient { 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.getChangelog(request, options, callback); @@ -666,7 +666,7 @@ export class ChangelogsClient { 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.listChangelogs(request, options, callback); @@ -727,7 +727,7 @@ export class ChangelogsClient { 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['listChangelogs']; const callSettings = defaultCallSettings.merge(options); @@ -797,7 +797,7 @@ export class ChangelogsClient { 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['listChangelogs']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/deployments_client.ts b/src/v3beta1/deployments_client.ts index 464d1b9e..de1c22c4 100644 --- a/src/v3beta1/deployments_client.ts +++ b/src/v3beta1/deployments_client.ts @@ -544,7 +544,7 @@ export class DeploymentsClient { 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.getDeployment(request, options, callback); @@ -646,7 +646,7 @@ export class DeploymentsClient { 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.listDeployments(request, options, callback); @@ -687,7 +687,7 @@ export class DeploymentsClient { 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['listDeployments']; const callSettings = defaultCallSettings.merge(options); @@ -737,7 +737,7 @@ export class DeploymentsClient { 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['listDeployments']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/entity_types_client.ts b/src/v3beta1/entity_types_client.ts index b73c4e31..ed533ce3 100644 --- a/src/v3beta1/entity_types_client.ts +++ b/src/v3beta1/entity_types_client.ts @@ -563,7 +563,7 @@ export class EntityTypesClient { 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.getEntityType(request, options, callback); @@ -675,7 +675,7 @@ export class EntityTypesClient { 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.createEntityType(request, options, callback); @@ -790,7 +790,7 @@ export class EntityTypesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'entity_type.name': request.entityType!.name || '', + 'entity_type.name': request.entityType!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateEntityType(request, options, callback); @@ -904,7 +904,7 @@ export class EntityTypesClient { 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.deleteEntityType(request, options, callback); @@ -1018,7 +1018,7 @@ export class EntityTypesClient { 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.listEntityTypes(request, options, callback); @@ -1071,7 +1071,7 @@ export class EntityTypesClient { 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['listEntityTypes']; const callSettings = defaultCallSettings.merge(options); @@ -1133,7 +1133,7 @@ export class EntityTypesClient { 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['listEntityTypes']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/environments_client.ts b/src/v3beta1/environments_client.ts index b77b724f..aa1b1a30 100644 --- a/src/v3beta1/environments_client.ts +++ b/src/v3beta1/environments_client.ts @@ -613,7 +613,7 @@ export class EnvironmentsClient { 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.getEnvironment(request, options, callback); @@ -712,7 +712,7 @@ export class EnvironmentsClient { 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.deleteEnvironment(request, options, callback); @@ -827,7 +827,7 @@ export class EnvironmentsClient { 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.createEnvironment(request, options, callback); @@ -975,7 +975,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'environment.name': request.environment!.name || '', + 'environment.name': request.environment!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateEnvironment(request, options, callback); @@ -1121,7 +1121,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - environment: request.environment || '', + environment: request.environment ?? '', }); this.initialize(); return this.innerApiCalls.runContinuousTest(request, options, callback); @@ -1272,7 +1272,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - environment: request.environment || '', + environment: request.environment ?? '', }); this.initialize(); return this.innerApiCalls.deployFlow(request, options, callback); @@ -1407,7 +1407,7 @@ export class EnvironmentsClient { 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.listEnvironments(request, options, callback); @@ -1447,7 +1447,7 @@ export class EnvironmentsClient { 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['listEnvironments']; const callSettings = defaultCallSettings.merge(options); @@ -1496,7 +1496,7 @@ export class EnvironmentsClient { 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['listEnvironments']; const callSettings = defaultCallSettings.merge(options); @@ -1603,7 +1603,7 @@ export class EnvironmentsClient { 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.lookupEnvironmentHistory( @@ -1648,7 +1648,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); const defaultCallSettings = this._defaults['lookupEnvironmentHistory']; const callSettings = defaultCallSettings.merge(options); @@ -1698,7 +1698,7 @@ export class EnvironmentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - name: request.name || '', + name: request.name ?? '', }); const defaultCallSettings = this._defaults['lookupEnvironmentHistory']; const callSettings = defaultCallSettings.merge(options); @@ -1805,7 +1805,7 @@ export class EnvironmentsClient { 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.listContinuousTestResults( @@ -1850,7 +1850,7 @@ export class EnvironmentsClient { 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['listContinuousTestResults']; const callSettings = defaultCallSettings.merge(options); @@ -1900,7 +1900,7 @@ export class EnvironmentsClient { 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['listContinuousTestResults']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/experiments_client.ts b/src/v3beta1/experiments_client.ts index 79643bdd..495db33f 100644 --- a/src/v3beta1/experiments_client.ts +++ b/src/v3beta1/experiments_client.ts @@ -552,7 +552,7 @@ export class ExperimentsClient { 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.getExperiment(request, options, callback); @@ -653,7 +653,7 @@ export class ExperimentsClient { 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.createExperiment(request, options, callback); @@ -752,7 +752,7 @@ export class ExperimentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'experiment.name': request.experiment!.name || '', + 'experiment.name': request.experiment!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateExperiment(request, options, callback); @@ -851,7 +851,7 @@ export class ExperimentsClient { 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.deleteExperiment(request, options, callback); @@ -951,7 +951,7 @@ export class ExperimentsClient { 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.startExperiment(request, options, callback); @@ -1051,7 +1051,7 @@ export class ExperimentsClient { 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.stopExperiment(request, options, callback); @@ -1153,7 +1153,7 @@ export class ExperimentsClient { 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.listExperiments(request, options, callback); @@ -1194,7 +1194,7 @@ export class ExperimentsClient { 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['listExperiments']; const callSettings = defaultCallSettings.merge(options); @@ -1244,7 +1244,7 @@ export class ExperimentsClient { 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['listExperiments']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/flows_client.ts b/src/v3beta1/flows_client.ts index 35d5dc4e..dbb15696 100644 --- a/src/v3beta1/flows_client.ts +++ b/src/v3beta1/flows_client.ts @@ -605,7 +605,7 @@ export class FlowsClient { 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.createFlow(request, options, callback); @@ -709,7 +709,7 @@ export class FlowsClient { 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.deleteFlow(request, options, callback); @@ -816,7 +816,7 @@ export class FlowsClient { 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.getFlow(request, options, callback); @@ -927,7 +927,7 @@ export class FlowsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'flow.name': request.flow!.name || '', + 'flow.name': request.flow!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateFlow(request, options, callback); @@ -1030,7 +1030,7 @@ export class FlowsClient { 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.validateFlow(request, options, callback); @@ -1132,7 +1132,7 @@ export class FlowsClient { 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.getFlowValidationResult( @@ -1256,7 +1256,7 @@ export class FlowsClient { 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.trainFlow(request, options, callback); @@ -1418,7 +1418,7 @@ export class FlowsClient { 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.importFlow(request, options, callback); @@ -1582,7 +1582,7 @@ export class FlowsClient { 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.exportFlow(request, options, callback); @@ -1731,7 +1731,7 @@ export class FlowsClient { 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.listFlows(request, options, callback); @@ -1785,7 +1785,7 @@ export class FlowsClient { 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['listFlows']; const callSettings = defaultCallSettings.merge(options); @@ -1848,7 +1848,7 @@ export class FlowsClient { 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['listFlows']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/intents_client.ts b/src/v3beta1/intents_client.ts index cc797c0b..adf9879f 100644 --- a/src/v3beta1/intents_client.ts +++ b/src/v3beta1/intents_client.ts @@ -555,7 +555,7 @@ export class IntentsClient { 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.getIntent(request, options, callback); @@ -669,7 +669,7 @@ export class IntentsClient { 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.createIntent(request, options, callback); @@ -783,7 +783,7 @@ export class IntentsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'intent.name': request.intent!.name || '', + 'intent.name': request.intent!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateIntent(request, options, callback); @@ -886,7 +886,7 @@ export class IntentsClient { 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.deleteIntent(request, options, callback); @@ -1000,7 +1000,7 @@ export class IntentsClient { 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.listIntents(request, options, callback); @@ -1053,7 +1053,7 @@ export class IntentsClient { 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['listIntents']; const callSettings = defaultCallSettings.merge(options); @@ -1115,7 +1115,7 @@ export class IntentsClient { 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['listIntents']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/pages_client.ts b/src/v3beta1/pages_client.ts index eacecc8f..e4589217 100644 --- a/src/v3beta1/pages_client.ts +++ b/src/v3beta1/pages_client.ts @@ -566,7 +566,7 @@ export class PagesClient { 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.getPage(request, options, callback); @@ -682,7 +682,7 @@ export class PagesClient { 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.createPage(request, options, callback); @@ -797,7 +797,7 @@ export class PagesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'page.name': request.page!.name || '', + 'page.name': request.page!.name ?? '', }); this.initialize(); return this.innerApiCalls.updatePage(request, options, callback); @@ -901,7 +901,7 @@ export class PagesClient { 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.deletePage(request, options, callback); @@ -1025,7 +1025,7 @@ export class PagesClient { 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.listPages(request, options, callback); @@ -1088,7 +1088,7 @@ export class PagesClient { 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['listPages']; const callSettings = defaultCallSettings.merge(options); @@ -1160,7 +1160,7 @@ export class PagesClient { 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['listPages']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/security_settings_service_client.ts b/src/v3beta1/security_settings_service_client.ts index 4318e587..88c30c4c 100644 --- a/src/v3beta1/security_settings_service_client.ts +++ b/src/v3beta1/security_settings_service_client.ts @@ -569,7 +569,7 @@ export class SecuritySettingsServiceClient { 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.createSecuritySettings( @@ -673,7 +673,7 @@ export class SecuritySettingsServiceClient { 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.getSecuritySettings(request, options, callback); @@ -774,7 +774,7 @@ export class SecuritySettingsServiceClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'security_settings.name': request.securitySettings!.name || '', + 'security_settings.name': request.securitySettings!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateSecuritySettings( @@ -877,7 +877,7 @@ export class SecuritySettingsServiceClient { 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.deleteSecuritySettings( @@ -982,7 +982,7 @@ export class SecuritySettingsServiceClient { 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.listSecuritySettings(request, options, callback); @@ -1022,7 +1022,7 @@ export class SecuritySettingsServiceClient { 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['listSecuritySettings']; const callSettings = defaultCallSettings.merge(options); @@ -1071,7 +1071,7 @@ export class SecuritySettingsServiceClient { 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['listSecuritySettings']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/session_entity_types_client.ts b/src/v3beta1/session_entity_types_client.ts index 9d9cfa02..51bb0b34 100644 --- a/src/v3beta1/session_entity_types_client.ts +++ b/src/v3beta1/session_entity_types_client.ts @@ -558,7 +558,7 @@ export class SessionEntityTypesClient { 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.getSessionEntityType(request, options, callback); @@ -662,7 +662,7 @@ export class SessionEntityTypesClient { 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.createSessionEntityType( @@ -771,7 +771,7 @@ export class SessionEntityTypesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'session_entity_type.name': request.sessionEntityType!.name || '', + 'session_entity_type.name': request.sessionEntityType!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateSessionEntityType( @@ -878,7 +878,7 @@ export class SessionEntityTypesClient { 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.deleteSessionEntityType( @@ -987,7 +987,7 @@ export class SessionEntityTypesClient { 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.listSessionEntityTypes( @@ -1035,7 +1035,7 @@ export class SessionEntityTypesClient { 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['listSessionEntityTypes']; const callSettings = defaultCallSettings.merge(options); @@ -1088,7 +1088,7 @@ export class SessionEntityTypesClient { 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['listSessionEntityTypes']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/sessions_client.ts b/src/v3beta1/sessions_client.ts index 629e084c..da7f9584 100644 --- a/src/v3beta1/sessions_client.ts +++ b/src/v3beta1/sessions_client.ts @@ -586,7 +586,7 @@ export class SessionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - session: request.session || '', + session: request.session ?? '', }); this.initialize(); return this.innerApiCalls.detectIntent(request, options, callback); @@ -693,7 +693,7 @@ export class SessionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - session: request.session || '', + session: request.session ?? '', }); this.initialize(); return this.innerApiCalls.matchIntent(request, options, callback); @@ -798,7 +798,7 @@ export class SessionsClient { options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ 'match_intent_request.session': - request.matchIntentRequest!.session || '', + request.matchIntentRequest!.session ?? '', }); this.initialize(); return this.innerApiCalls.fulfillIntent(request, options, callback); diff --git a/src/v3beta1/test_cases_client.ts b/src/v3beta1/test_cases_client.ts index e44da361..30142a59 100644 --- a/src/v3beta1/test_cases_client.ts +++ b/src/v3beta1/test_cases_client.ts @@ -614,7 +614,7 @@ export class TestCasesClient { 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.batchDeleteTestCases(request, options, callback); @@ -707,7 +707,7 @@ export class TestCasesClient { 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.getTestCase(request, options, callback); @@ -807,7 +807,7 @@ export class TestCasesClient { 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.createTestCase(request, options, callback); @@ -908,7 +908,7 @@ export class TestCasesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'test_case.name': request.testCase!.name || '', + 'test_case.name': request.testCase!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateTestCase(request, options, callback); @@ -1008,7 +1008,7 @@ export class TestCasesClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - agent: request.agent || '', + agent: request.agent ?? '', }); this.initialize(); return this.innerApiCalls.calculateCoverage(request, options, callback); @@ -1107,7 +1107,7 @@ export class TestCasesClient { 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.getTestCaseResult(request, options, callback); @@ -1223,7 +1223,7 @@ export class TestCasesClient { 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.runTestCase(request, options, callback); @@ -1376,7 +1376,7 @@ export class TestCasesClient { 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.batchRunTestCases(request, options, callback); @@ -1536,7 +1536,7 @@ export class TestCasesClient { 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.importTestCases(request, options, callback); @@ -1708,7 +1708,7 @@ export class TestCasesClient { 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.exportTestCases(request, options, callback); @@ -1846,7 +1846,7 @@ export class TestCasesClient { 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.listTestCases(request, options, callback); @@ -1889,7 +1889,7 @@ export class TestCasesClient { 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['listTestCases']; const callSettings = defaultCallSettings.merge(options); @@ -1941,7 +1941,7 @@ export class TestCasesClient { 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['listTestCases']; const callSettings = defaultCallSettings.merge(options); @@ -2074,7 +2074,7 @@ export class TestCasesClient { 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.listTestCaseResults(request, options, callback); @@ -2141,7 +2141,7 @@ export class TestCasesClient { 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['listTestCaseResults']; const callSettings = defaultCallSettings.merge(options); @@ -2217,7 +2217,7 @@ export class TestCasesClient { 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['listTestCaseResults']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/transition_route_groups_client.ts b/src/v3beta1/transition_route_groups_client.ts index 95b24d41..d1f5cdb1 100644 --- a/src/v3beta1/transition_route_groups_client.ts +++ b/src/v3beta1/transition_route_groups_client.ts @@ -565,7 +565,7 @@ export class TransitionRouteGroupsClient { 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.getTransitionRouteGroup( @@ -686,7 +686,7 @@ export class TransitionRouteGroupsClient { 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.createTransitionRouteGroup( @@ -805,7 +805,7 @@ export class TransitionRouteGroupsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'transition_route_group.name': request.transitionRouteGroup!.name || '', + 'transition_route_group.name': request.transitionRouteGroup!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateTransitionRouteGroup( @@ -920,7 +920,7 @@ export class TransitionRouteGroupsClient { 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.deleteTransitionRouteGroup( @@ -1039,7 +1039,7 @@ export class TransitionRouteGroupsClient { 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.listTransitionRouteGroups( @@ -1097,7 +1097,7 @@ export class TransitionRouteGroupsClient { 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['listTransitionRouteGroups']; const callSettings = defaultCallSettings.merge(options); @@ -1160,7 +1160,7 @@ export class TransitionRouteGroupsClient { 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['listTransitionRouteGroups']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/versions_client.ts b/src/v3beta1/versions_client.ts index 1491f71c..411e982f 100644 --- a/src/v3beta1/versions_client.ts +++ b/src/v3beta1/versions_client.ts @@ -573,7 +573,7 @@ export class VersionsClient { 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.getVersion(request, options, callback); @@ -673,7 +673,7 @@ export class VersionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'version.name': request.version!.name || '', + 'version.name': request.version!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateVersion(request, options, callback); @@ -772,7 +772,7 @@ export class VersionsClient { 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.deleteVersion(request, options, callback); @@ -886,7 +886,7 @@ export class VersionsClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - base_version: request.baseVersion || '', + base_version: request.baseVersion ?? '', }); this.initialize(); return this.innerApiCalls.compareVersions(request, options, callback); @@ -1001,7 +1001,7 @@ export class VersionsClient { 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.createVersion(request, options, callback); @@ -1155,7 +1155,7 @@ export class VersionsClient { 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.loadVersion(request, options, callback); @@ -1288,7 +1288,7 @@ export class VersionsClient { 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.listVersions(request, options, callback); @@ -1329,7 +1329,7 @@ export class VersionsClient { 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['listVersions']; const callSettings = defaultCallSettings.merge(options); @@ -1379,7 +1379,7 @@ export class VersionsClient { 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['listVersions']; const callSettings = defaultCallSettings.merge(options); diff --git a/src/v3beta1/webhooks_client.ts b/src/v3beta1/webhooks_client.ts index 98157240..a1465a69 100644 --- a/src/v3beta1/webhooks_client.ts +++ b/src/v3beta1/webhooks_client.ts @@ -551,7 +551,7 @@ export class WebhooksClient { 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.getWebhook(request, options, callback); @@ -651,7 +651,7 @@ export class WebhooksClient { 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.createWebhook(request, options, callback); @@ -751,7 +751,7 @@ export class WebhooksClient { options.otherArgs.headers = options.otherArgs.headers || {}; options.otherArgs.headers['x-goog-request-params'] = this._gaxModule.routingHeader.fromParams({ - 'webhook.name': request.webhook!.name || '', + 'webhook.name': request.webhook!.name ?? '', }); this.initialize(); return this.innerApiCalls.updateWebhook(request, options, callback); @@ -860,7 +860,7 @@ export class WebhooksClient { 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.deleteWebhook(request, options, callback); @@ -961,7 +961,7 @@ export class WebhooksClient { 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.listWebhooks(request, options, callback); @@ -1001,7 +1001,7 @@ export class WebhooksClient { 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['listWebhooks']; const callSettings = defaultCallSettings.merge(options); @@ -1050,7 +1050,7 @@ export class WebhooksClient { 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['listWebhooks']; const callSettings = defaultCallSettings.merge(options); diff --git a/test/gapic_agents_v3.ts b/test/gapic_agents_v3.ts index d7152f34..fe7620a7 100644 --- a/test/gapic_agents_v3.ts +++ b/test/gapic_agents_v3.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,26 +272,23 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Agent() ); client.innerApiCalls.getAgent = stubSimpleCall(expectedResponse); const [response] = await client.getAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgent without error using callback', async () => { @@ -288,15 +300,9 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Agent() ); @@ -319,11 +325,14 @@ describe('v3.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgent with error', async () => { @@ -335,23 +344,20 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getAgent = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getAgent(request), expectedError); - assert( - (client.innerApiCalls.getAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgent with closed client', async () => { @@ -363,7 +369,8 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getAgent(request), expectedError); @@ -380,26 +387,25 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateAgentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Agent() ); client.innerApiCalls.createAgent = stubSimpleCall(expectedResponse); const [response] = await client.createAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAgent without error using callback', async () => { @@ -411,15 +417,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateAgentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Agent() ); @@ -442,11 +444,14 @@ describe('v3.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAgent with error', async () => { @@ -458,26 +463,25 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateAgentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createAgent(request), expectedError); - assert( - (client.innerApiCalls.createAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAgent with closed client', async () => { @@ -489,7 +493,10 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateAgentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createAgent(request), expectedError); @@ -506,27 +513,27 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; - const expectedHeaderRequestParams = 'agent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; + const expectedHeaderRequestParams = `agent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Agent() ); client.innerApiCalls.updateAgent = stubSimpleCall(expectedResponse); const [response] = await client.updateAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAgent without error using callback', async () => { @@ -538,16 +545,13 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; - const expectedHeaderRequestParams = 'agent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; + const expectedHeaderRequestParams = `agent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Agent() ); @@ -570,11 +574,14 @@ describe('v3.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAgent with error', async () => { @@ -586,27 +593,27 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; - const expectedHeaderRequestParams = 'agent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; + const expectedHeaderRequestParams = `agent.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateAgent(request), expectedError); - assert( - (client.innerApiCalls.updateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAgent with closed client', async () => { @@ -618,8 +625,12 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateAgent(request), expectedError); @@ -636,26 +647,23 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteAgent = stubSimpleCall(expectedResponse); const [response] = await client.deleteAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAgent without error using callback', async () => { @@ -667,15 +675,9 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -698,11 +700,14 @@ describe('v3.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAgent with error', async () => { @@ -714,26 +719,23 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteAgent(request), expectedError); - assert( - (client.innerApiCalls.deleteAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAgent with closed client', async () => { @@ -745,7 +747,8 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteAgentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteAgent(request), expectedError); @@ -762,26 +765,25 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.AgentValidationResult() ); client.innerApiCalls.validateAgent = stubSimpleCall(expectedResponse); const [response] = await client.validateAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateAgent without error using callback', async () => { @@ -793,15 +795,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.AgentValidationResult() ); @@ -824,11 +822,14 @@ describe('v3.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateAgent with error', async () => { @@ -840,26 +841,25 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.validateAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.validateAgent(request), expectedError); - assert( - (client.innerApiCalls.validateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateAgent with closed client', async () => { @@ -871,7 +871,10 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateAgentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.validateAgent(request), expectedError); @@ -888,15 +891,12 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.AgentValidationResult() ); @@ -904,11 +904,14 @@ describe('v3.AgentsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getAgentValidationResult(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgentValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgentValidationResult without error using callback', async () => { @@ -920,15 +923,12 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.AgentValidationResult() ); @@ -951,11 +951,14 @@ describe('v3.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgentValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgentValidationResult with error', async () => { @@ -967,15 +970,12 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getAgentValidationResult = stubSimpleCall( undefined, @@ -985,11 +985,14 @@ describe('v3.AgentsClient', () => { client.getAgentValidationResult(request), expectedError ); - assert( - (client.innerApiCalls.getAgentValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgentValidationResult with closed client', async () => { @@ -1001,7 +1004,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetAgentValidationResultRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -1021,15 +1028,9 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1037,11 +1038,14 @@ describe('v3.AgentsClient', () => { const [operation] = await client.exportAgent(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportAgent without error using callback', async () => { @@ -1053,15 +1057,9 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1091,11 +1089,14 @@ describe('v3.AgentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportAgent with call error', async () => { @@ -1107,26 +1108,23 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportAgent = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.exportAgent(request), expectedError); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportAgent with LRO error', async () => { @@ -1138,15 +1136,9 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportAgent = stubLongRunningCall( undefined, @@ -1155,11 +1147,14 @@ describe('v3.AgentsClient', () => { ); const [operation] = await client.exportAgent(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkExportAgentProgress without error', async () => { @@ -1211,15 +1206,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1227,11 +1218,14 @@ describe('v3.AgentsClient', () => { const [operation] = await client.restoreAgent(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes restoreAgent without error using callback', async () => { @@ -1243,15 +1237,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1281,11 +1271,14 @@ describe('v3.AgentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes restoreAgent with call error', async () => { @@ -1297,26 +1290,25 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.restoreAgent = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.restoreAgent(request), expectedError); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes restoreAgent with LRO error', async () => { @@ -1328,15 +1320,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.restoreAgent = stubLongRunningCall( undefined, @@ -1345,11 +1333,14 @@ describe('v3.AgentsClient', () => { ); const [operation] = await client.restoreAgent(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkRestoreAgentProgress without error', async () => { @@ -1401,15 +1392,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), @@ -1418,11 +1405,14 @@ describe('v3.AgentsClient', () => { client.innerApiCalls.listAgents = stubSimpleCall(expectedResponse); const [response] = await client.listAgents(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listAgents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAgents without error using callback', async () => { @@ -1434,15 +1424,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), @@ -1467,11 +1453,14 @@ describe('v3.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listAgents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAgents with error', async () => { @@ -1483,26 +1472,25 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listAgents = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listAgents(request), expectedError); - assert( - (client.innerApiCalls.listAgents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAgentsStream without error', async () => { @@ -1514,8 +1502,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), @@ -1546,11 +1537,12 @@ describe('v3.AgentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listAgents, request) ); - assert.strictEqual( - (client.descriptors.page.listAgents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1563,8 +1555,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listAgents.createStream = stubPageStreamingCall( undefined, @@ -1592,11 +1587,12 @@ describe('v3.AgentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listAgents, request) ); - assert.strictEqual( - (client.descriptors.page.listAgents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1609,8 +1605,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Agent()), @@ -1630,11 +1629,12 @@ describe('v3.AgentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listAgents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1647,8 +1647,11 @@ describe('v3.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listAgents.asyncIterate = stubAsyncIterationCall( undefined, @@ -1667,11 +1670,12 @@ describe('v3.AgentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listAgents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1822,12 +1826,15 @@ describe('v3.AgentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1858,12 +1865,15 @@ describe('v3.AgentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_agents_v3beta1.ts b/test/gapic_agents_v3beta1.ts index a1646cd3..bab01d7b 100644 --- a/test/gapic_agents_v3beta1.ts +++ b/test/gapic_agents_v3beta1.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,26 +272,23 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() ); client.innerApiCalls.getAgent = stubSimpleCall(expectedResponse); const [response] = await client.getAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgent without error using callback', async () => { @@ -288,15 +300,9 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() ); @@ -319,11 +325,14 @@ describe('v3beta1.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgent with error', async () => { @@ -335,23 +344,20 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getAgent = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getAgent(request), expectedError); - assert( - (client.innerApiCalls.getAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgent with closed client', async () => { @@ -363,7 +369,8 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetAgentRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getAgent(request), expectedError); @@ -380,26 +387,25 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateAgentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() ); client.innerApiCalls.createAgent = stubSimpleCall(expectedResponse); const [response] = await client.createAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAgent without error using callback', async () => { @@ -411,15 +417,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateAgentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() ); @@ -442,11 +444,14 @@ describe('v3beta1.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAgent with error', async () => { @@ -458,26 +463,25 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateAgentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createAgent(request), expectedError); - assert( - (client.innerApiCalls.createAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createAgent with closed client', async () => { @@ -489,7 +493,10 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateAgentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateAgentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createAgent(request), expectedError); @@ -506,27 +513,27 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; - const expectedHeaderRequestParams = 'agent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; + const expectedHeaderRequestParams = `agent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() ); client.innerApiCalls.updateAgent = stubSimpleCall(expectedResponse); const [response] = await client.updateAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAgent without error using callback', async () => { @@ -538,16 +545,13 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; - const expectedHeaderRequestParams = 'agent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; + const expectedHeaderRequestParams = `agent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() ); @@ -570,11 +574,14 @@ describe('v3beta1.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAgent with error', async () => { @@ -586,27 +593,27 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; - const expectedHeaderRequestParams = 'agent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; + const expectedHeaderRequestParams = `agent.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateAgent(request), expectedError); - assert( - (client.innerApiCalls.updateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateAgent with closed client', async () => { @@ -618,8 +625,12 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateAgentRequest() ); - request.agent = {}; - request.agent.name = ''; + request.agent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateAgentRequest', [ + 'agent', + 'name', + ]); + request.agent.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateAgent(request), expectedError); @@ -636,26 +647,23 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteAgent = stubSimpleCall(expectedResponse); const [response] = await client.deleteAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAgent without error using callback', async () => { @@ -667,15 +675,9 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -698,11 +700,14 @@ describe('v3beta1.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAgent with error', async () => { @@ -714,26 +719,23 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteAgent(request), expectedError); - assert( - (client.innerApiCalls.deleteAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteAgent with closed client', async () => { @@ -745,7 +747,8 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteAgentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteAgentRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteAgent(request), expectedError); @@ -762,26 +765,25 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.AgentValidationResult() ); client.innerApiCalls.validateAgent = stubSimpleCall(expectedResponse); const [response] = await client.validateAgent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateAgent without error using callback', async () => { @@ -793,15 +795,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.AgentValidationResult() ); @@ -824,11 +822,14 @@ describe('v3beta1.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateAgent with error', async () => { @@ -840,26 +841,25 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.validateAgent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.validateAgent(request), expectedError); - assert( - (client.innerApiCalls.validateAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateAgent with closed client', async () => { @@ -871,7 +871,10 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateAgentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('ValidateAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.validateAgent(request), expectedError); @@ -888,15 +891,12 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.AgentValidationResult() ); @@ -904,11 +904,14 @@ describe('v3beta1.AgentsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getAgentValidationResult(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgentValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgentValidationResult without error using callback', async () => { @@ -920,15 +923,12 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.AgentValidationResult() ); @@ -951,11 +951,14 @@ describe('v3beta1.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getAgentValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgentValidationResult with error', async () => { @@ -967,15 +970,12 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getAgentValidationResult = stubSimpleCall( undefined, @@ -985,11 +985,14 @@ describe('v3beta1.AgentsClient', () => { client.getAgentValidationResult(request), expectedError ); - assert( - (client.innerApiCalls.getAgentValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getAgentValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getAgentValidationResult with closed client', async () => { @@ -1001,7 +1004,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetAgentValidationResultRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'GetAgentValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -1021,15 +1028,9 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1037,11 +1038,14 @@ describe('v3beta1.AgentsClient', () => { const [operation] = await client.exportAgent(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportAgent without error using callback', async () => { @@ -1053,15 +1057,9 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1091,11 +1089,14 @@ describe('v3beta1.AgentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportAgent with call error', async () => { @@ -1107,26 +1108,23 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportAgent = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.exportAgent(request), expectedError); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportAgent with LRO error', async () => { @@ -1138,15 +1136,9 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportAgentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportAgent = stubLongRunningCall( undefined, @@ -1155,11 +1147,14 @@ describe('v3beta1.AgentsClient', () => { ); const [operation] = await client.exportAgent(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.exportAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkExportAgentProgress without error', async () => { @@ -1211,15 +1206,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1227,11 +1218,14 @@ describe('v3beta1.AgentsClient', () => { const [operation] = await client.restoreAgent(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes restoreAgent without error using callback', async () => { @@ -1243,15 +1237,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1281,11 +1271,14 @@ describe('v3beta1.AgentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes restoreAgent with call error', async () => { @@ -1297,26 +1290,25 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.restoreAgent = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.restoreAgent(request), expectedError); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes restoreAgent with LRO error', async () => { @@ -1328,15 +1320,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RestoreAgentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RestoreAgentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.restoreAgent = stubLongRunningCall( undefined, @@ -1345,11 +1333,14 @@ describe('v3beta1.AgentsClient', () => { ); const [operation] = await client.restoreAgent(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.restoreAgent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.restoreAgent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkRestoreAgentProgress without error', async () => { @@ -1401,15 +1392,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() @@ -1424,11 +1411,14 @@ describe('v3beta1.AgentsClient', () => { client.innerApiCalls.listAgents = stubSimpleCall(expectedResponse); const [response] = await client.listAgents(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listAgents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAgents without error using callback', async () => { @@ -1440,15 +1430,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() @@ -1479,11 +1465,14 @@ describe('v3beta1.AgentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listAgents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAgents with error', async () => { @@ -1495,26 +1484,25 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listAgents = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listAgents(request), expectedError); - assert( - (client.innerApiCalls.listAgents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listAgents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listAgentsStream without error', async () => { @@ -1526,8 +1514,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() @@ -1564,11 +1555,12 @@ describe('v3beta1.AgentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listAgents, request) ); - assert.strictEqual( - (client.descriptors.page.listAgents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1581,8 +1573,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listAgents.createStream = stubPageStreamingCall( undefined, @@ -1610,11 +1605,12 @@ describe('v3beta1.AgentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listAgents, request) ); - assert.strictEqual( - (client.descriptors.page.listAgents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1627,8 +1623,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Agent() @@ -1654,11 +1653,12 @@ describe('v3beta1.AgentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listAgents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1671,8 +1671,11 @@ describe('v3beta1.AgentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListAgentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListAgentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listAgents.asyncIterate = stubAsyncIterationCall( undefined, @@ -1692,11 +1695,12 @@ describe('v3beta1.AgentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listAgents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listAgents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1847,12 +1851,15 @@ describe('v3beta1.AgentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1883,12 +1890,15 @@ describe('v3beta1.AgentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_changelogs_v3.ts b/test/gapic_changelogs_v3.ts index 2582d95a..815b1577 100644 --- a/test/gapic_changelogs_v3.ts +++ b/test/gapic_changelogs_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetChangelogRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Changelog() ); client.innerApiCalls.getChangelog = stubSimpleCall(expectedResponse); const [response] = await client.getChangelog(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getChangelog as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getChangelog without error using callback', async () => { @@ -251,15 +265,11 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetChangelogRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Changelog() ); @@ -282,11 +292,14 @@ describe('v3.ChangelogsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getChangelog as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getChangelog with error', async () => { @@ -298,26 +311,25 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetChangelogRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getChangelog = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getChangelog(request), expectedError); - assert( - (client.innerApiCalls.getChangelog as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getChangelog with closed client', async () => { @@ -329,7 +341,10 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetChangelogRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getChangelog(request), expectedError); @@ -346,15 +361,11 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Changelog() @@ -369,11 +380,14 @@ describe('v3.ChangelogsClient', () => { client.innerApiCalls.listChangelogs = stubSimpleCall(expectedResponse); const [response] = await client.listChangelogs(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listChangelogs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listChangelogs without error using callback', async () => { @@ -385,15 +399,11 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Changelog() @@ -424,11 +434,14 @@ describe('v3.ChangelogsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listChangelogs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listChangelogs with error', async () => { @@ -440,26 +453,25 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listChangelogs = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listChangelogs(request), expectedError); - assert( - (client.innerApiCalls.listChangelogs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listChangelogsStream without error', async () => { @@ -471,8 +483,11 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Changelog() @@ -509,11 +524,12 @@ describe('v3.ChangelogsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listChangelogs, request) ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -526,8 +542,11 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listChangelogs.createStream = stubPageStreamingCall(undefined, expectedError); @@ -553,11 +572,12 @@ describe('v3.ChangelogsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listChangelogs, request) ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -570,8 +590,11 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Changelog() @@ -597,11 +620,12 @@ describe('v3.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -614,8 +638,11 @@ describe('v3.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listChangelogs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -632,11 +659,12 @@ describe('v3.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -787,12 +815,15 @@ describe('v3.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -823,12 +854,15 @@ describe('v3.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_changelogs_v3beta1.ts b/test/gapic_changelogs_v3beta1.ts index e778becf..236f7789 100644 --- a/test/gapic_changelogs_v3beta1.ts +++ b/test/gapic_changelogs_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetChangelogRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Changelog() ); client.innerApiCalls.getChangelog = stubSimpleCall(expectedResponse); const [response] = await client.getChangelog(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getChangelog as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getChangelog without error using callback', async () => { @@ -251,15 +265,11 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetChangelogRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Changelog() ); @@ -282,11 +292,14 @@ describe('v3beta1.ChangelogsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getChangelog as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getChangelog with error', async () => { @@ -298,26 +311,25 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetChangelogRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getChangelog = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getChangelog(request), expectedError); - assert( - (client.innerApiCalls.getChangelog as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getChangelog as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getChangelog with closed client', async () => { @@ -329,7 +341,10 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetChangelogRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetChangelogRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getChangelog(request), expectedError); @@ -346,15 +361,11 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Changelog() @@ -369,11 +380,14 @@ describe('v3beta1.ChangelogsClient', () => { client.innerApiCalls.listChangelogs = stubSimpleCall(expectedResponse); const [response] = await client.listChangelogs(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listChangelogs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listChangelogs without error using callback', async () => { @@ -385,15 +399,11 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Changelog() @@ -426,11 +436,14 @@ describe('v3beta1.ChangelogsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listChangelogs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listChangelogs with error', async () => { @@ -442,26 +455,25 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listChangelogs = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listChangelogs(request), expectedError); - assert( - (client.innerApiCalls.listChangelogs as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listChangelogs as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listChangelogsStream without error', async () => { @@ -473,8 +485,11 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Changelog() @@ -512,11 +527,12 @@ describe('v3beta1.ChangelogsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listChangelogs, request) ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -529,8 +545,11 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listChangelogs.createStream = stubPageStreamingCall(undefined, expectedError); @@ -557,11 +576,12 @@ describe('v3beta1.ChangelogsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listChangelogs, request) ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -574,8 +594,11 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Changelog() @@ -602,11 +625,12 @@ describe('v3beta1.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -619,8 +643,11 @@ describe('v3beta1.ChangelogsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListChangelogsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListChangelogsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listChangelogs.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -638,11 +665,12 @@ describe('v3beta1.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listChangelogs.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listChangelogs.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -793,12 +821,15 @@ describe('v3beta1.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -829,12 +860,15 @@ describe('v3beta1.ChangelogsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_deployments_v3.ts b/test/gapic_deployments_v3.ts index 9f27533c..6e77749e 100644 --- a/test/gapic_deployments_v3.ts +++ b/test/gapic_deployments_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetDeploymentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Deployment() ); client.innerApiCalls.getDeployment = stubSimpleCall(expectedResponse); const [response] = await client.getDeployment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getDeployment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getDeployment without error using callback', async () => { @@ -251,15 +265,11 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetDeploymentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Deployment() ); @@ -282,11 +292,14 @@ describe('v3.DeploymentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getDeployment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getDeployment with error', async () => { @@ -298,26 +311,25 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetDeploymentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getDeployment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getDeployment(request), expectedError); - assert( - (client.innerApiCalls.getDeployment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getDeployment with closed client', async () => { @@ -329,7 +341,10 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetDeploymentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getDeployment(request), expectedError); @@ -346,15 +361,11 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Deployment() @@ -369,11 +380,14 @@ describe('v3.DeploymentsClient', () => { client.innerApiCalls.listDeployments = stubSimpleCall(expectedResponse); const [response] = await client.listDeployments(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listDeployments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listDeployments without error using callback', async () => { @@ -385,15 +399,11 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Deployment() @@ -424,11 +434,14 @@ describe('v3.DeploymentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listDeployments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listDeployments with error', async () => { @@ -440,26 +453,25 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listDeployments = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listDeployments(request), expectedError); - assert( - (client.innerApiCalls.listDeployments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listDeploymentsStream without error', async () => { @@ -471,8 +483,11 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Deployment() @@ -509,11 +524,12 @@ describe('v3.DeploymentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listDeployments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -526,8 +542,11 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listDeployments.createStream = stubPageStreamingCall(undefined, expectedError); @@ -553,11 +572,12 @@ describe('v3.DeploymentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listDeployments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -570,8 +590,11 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Deployment() @@ -597,11 +620,12 @@ describe('v3.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -614,8 +638,11 @@ describe('v3.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listDeployments.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -633,11 +660,12 @@ describe('v3.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -788,12 +816,15 @@ describe('v3.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -824,12 +855,15 @@ describe('v3.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_deployments_v3beta1.ts b/test/gapic_deployments_v3beta1.ts index d78fbc3d..31e4d95a 100644 --- a/test/gapic_deployments_v3beta1.ts +++ b/test/gapic_deployments_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetDeploymentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Deployment() ); client.innerApiCalls.getDeployment = stubSimpleCall(expectedResponse); const [response] = await client.getDeployment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getDeployment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getDeployment without error using callback', async () => { @@ -253,15 +267,11 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetDeploymentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Deployment() ); @@ -284,11 +294,14 @@ describe('v3beta1.DeploymentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getDeployment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getDeployment with error', async () => { @@ -300,26 +313,25 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetDeploymentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getDeployment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getDeployment(request), expectedError); - assert( - (client.innerApiCalls.getDeployment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getDeployment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getDeployment with closed client', async () => { @@ -331,7 +343,10 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetDeploymentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetDeploymentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getDeployment(request), expectedError); @@ -348,15 +363,11 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Deployment() @@ -371,11 +382,14 @@ describe('v3beta1.DeploymentsClient', () => { client.innerApiCalls.listDeployments = stubSimpleCall(expectedResponse); const [response] = await client.listDeployments(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listDeployments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listDeployments without error using callback', async () => { @@ -387,15 +401,11 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Deployment() @@ -428,11 +438,14 @@ describe('v3beta1.DeploymentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listDeployments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listDeployments with error', async () => { @@ -444,26 +457,25 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listDeployments = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listDeployments(request), expectedError); - assert( - (client.innerApiCalls.listDeployments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listDeployments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listDeploymentsStream without error', async () => { @@ -475,8 +487,11 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Deployment() @@ -514,11 +529,12 @@ describe('v3beta1.DeploymentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listDeployments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -531,8 +547,11 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listDeployments.createStream = stubPageStreamingCall(undefined, expectedError); @@ -559,11 +578,12 @@ describe('v3beta1.DeploymentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listDeployments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -576,8 +596,11 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Deployment() @@ -604,11 +627,12 @@ describe('v3beta1.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -621,8 +645,11 @@ describe('v3beta1.DeploymentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListDeploymentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListDeploymentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listDeployments.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -640,11 +667,12 @@ describe('v3beta1.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listDeployments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listDeployments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -795,12 +823,15 @@ describe('v3beta1.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -831,12 +862,15 @@ describe('v3beta1.DeploymentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_entity_types_v3.ts b/test/gapic_entity_types_v3.ts index d956c5c9..f03656a6 100644 --- a/test/gapic_entity_types_v3.ts +++ b/test/gapic_entity_types_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() ); client.innerApiCalls.getEntityType = stubSimpleCall(expectedResponse); const [response] = await client.getEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEntityType without error using callback', async () => { @@ -251,15 +265,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() ); @@ -282,11 +292,14 @@ describe('v3.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEntityType with error', async () => { @@ -298,26 +311,25 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getEntityType(request), expectedError); - assert( - (client.innerApiCalls.getEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEntityType with closed client', async () => { @@ -329,7 +341,10 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getEntityType(request), expectedError); @@ -346,26 +361,25 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() ); client.innerApiCalls.createEntityType = stubSimpleCall(expectedResponse); const [response] = await client.createEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEntityType without error using callback', async () => { @@ -377,15 +391,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() ); @@ -408,11 +418,14 @@ describe('v3.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEntityType with error', async () => { @@ -424,26 +437,25 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createEntityType(request), expectedError); - assert( - (client.innerApiCalls.createEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEntityType with closed client', async () => { @@ -455,7 +467,10 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEntityTypeRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createEntityType(request), expectedError); @@ -472,27 +487,27 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; - const expectedHeaderRequestParams = 'entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; + const expectedHeaderRequestParams = `entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() ); client.innerApiCalls.updateEntityType = stubSimpleCall(expectedResponse); const [response] = await client.updateEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEntityType without error using callback', async () => { @@ -504,16 +519,13 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; - const expectedHeaderRequestParams = 'entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; + const expectedHeaderRequestParams = `entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() ); @@ -536,11 +548,14 @@ describe('v3.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEntityType with error', async () => { @@ -552,27 +567,27 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; - const expectedHeaderRequestParams = 'entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; + const expectedHeaderRequestParams = `entity_type.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateEntityType(request), expectedError); - assert( - (client.innerApiCalls.updateEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEntityType with closed client', async () => { @@ -584,8 +599,12 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateEntityType(request), expectedError); @@ -602,26 +621,25 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteEntityType = stubSimpleCall(expectedResponse); const [response] = await client.deleteEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEntityType without error using callback', async () => { @@ -633,15 +651,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -664,11 +678,14 @@ describe('v3.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEntityType with error', async () => { @@ -680,26 +697,25 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteEntityType(request), expectedError); - assert( - (client.innerApiCalls.deleteEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEntityType with closed client', async () => { @@ -711,7 +727,10 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteEntityType(request), expectedError); @@ -728,15 +747,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() @@ -751,11 +766,14 @@ describe('v3.EntityTypesClient', () => { client.innerApiCalls.listEntityTypes = stubSimpleCall(expectedResponse); const [response] = await client.listEntityTypes(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEntityTypes without error using callback', async () => { @@ -767,15 +785,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() @@ -806,11 +820,14 @@ describe('v3.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEntityTypes with error', async () => { @@ -822,26 +839,25 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listEntityTypes = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listEntityTypes(request), expectedError); - assert( - (client.innerApiCalls.listEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEntityTypesStream without error', async () => { @@ -853,8 +869,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() @@ -891,11 +910,12 @@ describe('v3.EntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEntityTypes, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -908,8 +928,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEntityTypes.createStream = stubPageStreamingCall(undefined, expectedError); @@ -935,11 +958,12 @@ describe('v3.EntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEntityTypes, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -952,8 +976,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.EntityType() @@ -979,11 +1006,12 @@ describe('v3.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -996,8 +1024,11 @@ describe('v3.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEntityTypes.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1015,11 +1046,12 @@ describe('v3.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1170,12 +1202,15 @@ describe('v3.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1206,12 +1241,15 @@ describe('v3.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_entity_types_v3beta1.ts b/test/gapic_entity_types_v3beta1.ts index b3a23353..29c4b810 100644 --- a/test/gapic_entity_types_v3beta1.ts +++ b/test/gapic_entity_types_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() ); client.innerApiCalls.getEntityType = stubSimpleCall(expectedResponse); const [response] = await client.getEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEntityType without error using callback', async () => { @@ -253,15 +267,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() ); @@ -284,11 +294,14 @@ describe('v3beta1.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEntityType with error', async () => { @@ -300,26 +313,25 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getEntityType(request), expectedError); - assert( - (client.innerApiCalls.getEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEntityType with closed client', async () => { @@ -331,7 +343,10 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getEntityType(request), expectedError); @@ -348,26 +363,25 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() ); client.innerApiCalls.createEntityType = stubSimpleCall(expectedResponse); const [response] = await client.createEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEntityType without error using callback', async () => { @@ -379,15 +393,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() ); @@ -410,11 +420,14 @@ describe('v3beta1.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEntityType with error', async () => { @@ -426,26 +439,25 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createEntityType(request), expectedError); - assert( - (client.innerApiCalls.createEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEntityType with closed client', async () => { @@ -457,7 +469,10 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateEntityTypeRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createEntityType(request), expectedError); @@ -474,27 +489,27 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; - const expectedHeaderRequestParams = 'entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; + const expectedHeaderRequestParams = `entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() ); client.innerApiCalls.updateEntityType = stubSimpleCall(expectedResponse); const [response] = await client.updateEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEntityType without error using callback', async () => { @@ -506,16 +521,13 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; - const expectedHeaderRequestParams = 'entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; + const expectedHeaderRequestParams = `entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() ); @@ -538,11 +550,14 @@ describe('v3beta1.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEntityType with error', async () => { @@ -554,27 +569,27 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; - const expectedHeaderRequestParams = 'entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; + const expectedHeaderRequestParams = `entity_type.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateEntityType(request), expectedError); - assert( - (client.innerApiCalls.updateEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEntityType with closed client', async () => { @@ -586,8 +601,12 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEntityTypeRequest() ); - request.entityType = {}; - request.entityType.name = ''; + request.entityType ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEntityTypeRequest', [ + 'entityType', + 'name', + ]); + request.entityType.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateEntityType(request), expectedError); @@ -604,26 +623,25 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteEntityType = stubSimpleCall(expectedResponse); const [response] = await client.deleteEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEntityType without error using callback', async () => { @@ -635,15 +653,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -666,11 +680,14 @@ describe('v3beta1.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEntityType with error', async () => { @@ -682,26 +699,25 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteEntityType(request), expectedError); - assert( - (client.innerApiCalls.deleteEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEntityType with closed client', async () => { @@ -713,7 +729,10 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteEntityType(request), expectedError); @@ -730,15 +749,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() @@ -753,11 +768,14 @@ describe('v3beta1.EntityTypesClient', () => { client.innerApiCalls.listEntityTypes = stubSimpleCall(expectedResponse); const [response] = await client.listEntityTypes(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEntityTypes without error using callback', async () => { @@ -769,15 +787,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() @@ -810,11 +824,14 @@ describe('v3beta1.EntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEntityTypes with error', async () => { @@ -826,26 +843,25 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listEntityTypes = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listEntityTypes(request), expectedError); - assert( - (client.innerApiCalls.listEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEntityTypesStream without error', async () => { @@ -857,8 +873,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() @@ -896,11 +915,12 @@ describe('v3beta1.EntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEntityTypes, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -913,8 +933,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEntityTypes.createStream = stubPageStreamingCall(undefined, expectedError); @@ -941,11 +964,12 @@ describe('v3beta1.EntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEntityTypes, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -958,8 +982,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.EntityType() @@ -986,11 +1013,12 @@ describe('v3beta1.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1003,8 +1031,11 @@ describe('v3beta1.EntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEntityTypesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEntityTypes.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1022,11 +1053,12 @@ describe('v3beta1.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEntityTypes.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEntityTypes.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1177,12 +1209,15 @@ describe('v3beta1.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1213,12 +1248,15 @@ describe('v3beta1.EntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_environments_v3.ts b/test/gapic_environments_v3.ts index abba1a49..bbefa732 100644 --- a/test/gapic_environments_v3.ts +++ b/test/gapic_environments_v3.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,26 +272,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() ); client.innerApiCalls.getEnvironment = stubSimpleCall(expectedResponse); const [response] = await client.getEnvironment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEnvironment without error using callback', async () => { @@ -288,15 +302,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() ); @@ -319,11 +329,14 @@ describe('v3.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEnvironment with error', async () => { @@ -335,26 +348,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getEnvironment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getEnvironment(request), expectedError); - assert( - (client.innerApiCalls.getEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEnvironment with closed client', async () => { @@ -366,7 +378,10 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetEnvironmentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getEnvironment(request), expectedError); @@ -383,26 +398,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteEnvironment = stubSimpleCall(expectedResponse); const [response] = await client.deleteEnvironment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEnvironment without error using callback', async () => { @@ -414,15 +428,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -445,11 +455,14 @@ describe('v3.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEnvironment with error', async () => { @@ -461,26 +474,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteEnvironment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteEnvironment(request), expectedError); - assert( - (client.innerApiCalls.deleteEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEnvironment with closed client', async () => { @@ -492,7 +504,10 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteEnvironmentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteEnvironment(request), expectedError); @@ -509,15 +524,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -526,11 +537,14 @@ describe('v3.EnvironmentsClient', () => { const [operation] = await client.createEnvironment(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEnvironment without error using callback', async () => { @@ -542,15 +556,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -580,11 +590,14 @@ describe('v3.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEnvironment with call error', async () => { @@ -596,26 +609,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createEnvironment = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createEnvironment(request), expectedError); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEnvironment with LRO error', async () => { @@ -627,15 +639,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createEnvironment = stubLongRunningCall( undefined, @@ -644,11 +652,14 @@ describe('v3.EnvironmentsClient', () => { ); const [operation] = await client.createEnvironment(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateEnvironmentProgress without error', async () => { @@ -703,16 +714,13 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -721,11 +729,14 @@ describe('v3.EnvironmentsClient', () => { const [operation] = await client.updateEnvironment(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEnvironment without error using callback', async () => { @@ -737,16 +748,13 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -776,11 +784,14 @@ describe('v3.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEnvironment with call error', async () => { @@ -792,27 +803,27 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateEnvironment = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.updateEnvironment(request), expectedError); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEnvironment with LRO error', async () => { @@ -824,16 +835,13 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateEnvironment = stubLongRunningCall( undefined, @@ -842,11 +850,14 @@ describe('v3.EnvironmentsClient', () => { ); const [operation] = await client.updateEnvironment(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkUpdateEnvironmentProgress without error', async () => { @@ -901,15 +912,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -918,11 +925,14 @@ describe('v3.EnvironmentsClient', () => { const [operation] = await client.runContinuousTest(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runContinuousTest without error using callback', async () => { @@ -934,15 +944,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -972,11 +978,14 @@ describe('v3.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runContinuousTest with call error', async () => { @@ -988,26 +997,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runContinuousTest = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.runContinuousTest(request), expectedError); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runContinuousTest with LRO error', async () => { @@ -1019,15 +1027,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runContinuousTest = stubLongRunningCall( undefined, @@ -1036,11 +1040,14 @@ describe('v3.EnvironmentsClient', () => { ); const [operation] = await client.runContinuousTest(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkRunContinuousTestProgress without error', async () => { @@ -1095,15 +1102,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1111,11 +1114,14 @@ describe('v3.EnvironmentsClient', () => { const [operation] = await client.deployFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deployFlow without error using callback', async () => { @@ -1127,15 +1133,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1165,11 +1167,14 @@ describe('v3.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deployFlow with call error', async () => { @@ -1181,26 +1186,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deployFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.deployFlow(request), expectedError); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deployFlow with LRO error', async () => { @@ -1212,15 +1216,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deployFlow = stubLongRunningCall( undefined, @@ -1229,11 +1229,14 @@ describe('v3.EnvironmentsClient', () => { ); const [operation] = await client.deployFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkDeployFlowProgress without error', async () => { @@ -1285,15 +1288,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1308,11 +1307,14 @@ describe('v3.EnvironmentsClient', () => { client.innerApiCalls.listEnvironments = stubSimpleCall(expectedResponse); const [response] = await client.listEnvironments(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEnvironments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEnvironments without error using callback', async () => { @@ -1324,15 +1326,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1363,11 +1361,14 @@ describe('v3.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEnvironments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEnvironments with error', async () => { @@ -1379,26 +1380,25 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listEnvironments = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listEnvironments(request), expectedError); - assert( - (client.innerApiCalls.listEnvironments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEnvironmentsStream without error', async () => { @@ -1410,8 +1410,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1449,11 +1452,12 @@ describe('v3.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEnvironments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1466,8 +1470,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEnvironments.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1494,11 +1501,12 @@ describe('v3.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEnvironments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1511,8 +1519,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1538,11 +1549,12 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1555,8 +1567,11 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEnvironments.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1574,11 +1589,12 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1593,15 +1609,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1617,11 +1630,14 @@ describe('v3.EnvironmentsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.lookupEnvironmentHistory(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.lookupEnvironmentHistory as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes lookupEnvironmentHistory without error using callback', async () => { @@ -1633,15 +1649,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1672,11 +1685,14 @@ describe('v3.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.lookupEnvironmentHistory as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes lookupEnvironmentHistory with error', async () => { @@ -1688,15 +1704,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.lookupEnvironmentHistory = stubSimpleCall( undefined, @@ -1706,11 +1719,14 @@ describe('v3.EnvironmentsClient', () => { client.lookupEnvironmentHistory(request), expectedError ); - assert( - (client.innerApiCalls.lookupEnvironmentHistory as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes lookupEnvironmentHistoryStream without error', async () => { @@ -1722,8 +1738,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1764,12 +1784,15 @@ describe('v3.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.lookupEnvironmentHistory, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1782,8 +1805,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.lookupEnvironmentHistory.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1813,12 +1840,15 @@ describe('v3.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.lookupEnvironmentHistory, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1831,8 +1861,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Environment() @@ -1859,12 +1893,15 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1877,8 +1914,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.lookupEnvironmentHistory.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1897,12 +1938,15 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1917,15 +1961,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ContinuousTestResult() @@ -1941,11 +1982,14 @@ describe('v3.EnvironmentsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listContinuousTestResults(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listContinuousTestResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listContinuousTestResults without error using callback', async () => { @@ -1957,15 +2001,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ContinuousTestResult() @@ -1998,11 +2039,14 @@ describe('v3.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listContinuousTestResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listContinuousTestResults with error', async () => { @@ -2014,15 +2058,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listContinuousTestResults = stubSimpleCall( undefined, @@ -2032,11 +2073,14 @@ describe('v3.EnvironmentsClient', () => { client.listContinuousTestResults(request), expectedError ); - assert( - (client.innerApiCalls.listContinuousTestResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listContinuousTestResultsStream without error', async () => { @@ -2048,8 +2092,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ContinuousTestResult() @@ -2092,12 +2140,15 @@ describe('v3.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listContinuousTestResults, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2110,8 +2161,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listContinuousTestResults.createStream = stubPageStreamingCall(undefined, expectedError); @@ -2143,12 +2198,15 @@ describe('v3.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listContinuousTestResults, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2161,8 +2219,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ContinuousTestResult() @@ -2190,12 +2252,15 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2208,8 +2273,12 @@ describe('v3.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listContinuousTestResults.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2228,12 +2297,15 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2384,12 +2456,15 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -2420,12 +2495,15 @@ describe('v3.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_environments_v3beta1.ts b/test/gapic_environments_v3beta1.ts index 41026385..445456d7 100644 --- a/test/gapic_environments_v3beta1.ts +++ b/test/gapic_environments_v3beta1.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -259,26 +274,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() ); client.innerApiCalls.getEnvironment = stubSimpleCall(expectedResponse); const [response] = await client.getEnvironment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEnvironment without error using callback', async () => { @@ -290,15 +304,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() ); @@ -321,11 +331,14 @@ describe('v3beta1.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEnvironment with error', async () => { @@ -337,26 +350,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getEnvironment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getEnvironment(request), expectedError); - assert( - (client.innerApiCalls.getEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getEnvironment with closed client', async () => { @@ -368,7 +380,10 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetEnvironmentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getEnvironment(request), expectedError); @@ -385,26 +400,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteEnvironment = stubSimpleCall(expectedResponse); const [response] = await client.deleteEnvironment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEnvironment without error using callback', async () => { @@ -416,15 +430,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -447,11 +457,14 @@ describe('v3beta1.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEnvironment with error', async () => { @@ -463,26 +476,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEnvironmentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteEnvironment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteEnvironment(request), expectedError); - assert( - (client.innerApiCalls.deleteEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteEnvironment with closed client', async () => { @@ -494,7 +506,10 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteEnvironmentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteEnvironmentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteEnvironment(request), expectedError); @@ -511,15 +526,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -528,11 +539,14 @@ describe('v3beta1.EnvironmentsClient', () => { const [operation] = await client.createEnvironment(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEnvironment without error using callback', async () => { @@ -544,15 +558,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -582,11 +592,14 @@ describe('v3beta1.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEnvironment with call error', async () => { @@ -598,26 +611,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createEnvironment = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createEnvironment(request), expectedError); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createEnvironment with LRO error', async () => { @@ -629,15 +641,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateEnvironmentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateEnvironmentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createEnvironment = stubLongRunningCall( undefined, @@ -646,11 +654,14 @@ describe('v3beta1.EnvironmentsClient', () => { ); const [operation] = await client.createEnvironment(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateEnvironmentProgress without error', async () => { @@ -705,16 +716,13 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -723,11 +731,14 @@ describe('v3beta1.EnvironmentsClient', () => { const [operation] = await client.updateEnvironment(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEnvironment without error using callback', async () => { @@ -739,16 +750,13 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -778,11 +786,14 @@ describe('v3beta1.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEnvironment with call error', async () => { @@ -794,27 +805,27 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateEnvironment = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.updateEnvironment(request), expectedError); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateEnvironment with LRO error', async () => { @@ -826,16 +837,13 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateEnvironmentRequest() ); - request.environment = {}; - request.environment.name = ''; - const expectedHeaderRequestParams = 'environment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.environment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateEnvironmentRequest', [ + 'environment', + 'name', + ]); + request.environment.name = defaultValue1; + const expectedHeaderRequestParams = `environment.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateEnvironment = stubLongRunningCall( undefined, @@ -844,11 +852,14 @@ describe('v3beta1.EnvironmentsClient', () => { ); const [operation] = await client.updateEnvironment(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.updateEnvironment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateEnvironment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkUpdateEnvironmentProgress without error', async () => { @@ -903,15 +914,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -920,11 +927,14 @@ describe('v3beta1.EnvironmentsClient', () => { const [operation] = await client.runContinuousTest(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runContinuousTest without error using callback', async () => { @@ -936,15 +946,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -974,11 +980,14 @@ describe('v3beta1.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runContinuousTest with call error', async () => { @@ -990,26 +999,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runContinuousTest = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.runContinuousTest(request), expectedError); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runContinuousTest with LRO error', async () => { @@ -1021,15 +1029,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunContinuousTestRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunContinuousTestRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runContinuousTest = stubLongRunningCall( undefined, @@ -1038,11 +1042,14 @@ describe('v3beta1.EnvironmentsClient', () => { ); const [operation] = await client.runContinuousTest(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.runContinuousTest as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runContinuousTest as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkRunContinuousTestProgress without error', async () => { @@ -1097,15 +1104,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1113,11 +1116,14 @@ describe('v3beta1.EnvironmentsClient', () => { const [operation] = await client.deployFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deployFlow without error using callback', async () => { @@ -1129,15 +1135,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1167,11 +1169,14 @@ describe('v3beta1.EnvironmentsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deployFlow with call error', async () => { @@ -1183,26 +1188,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deployFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.deployFlow(request), expectedError); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deployFlow with LRO error', async () => { @@ -1214,15 +1218,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeployFlowRequest() ); - request.environment = ''; - const expectedHeaderRequestParams = 'environment='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeployFlowRequest', [ + 'environment', + ]); + request.environment = defaultValue1; + const expectedHeaderRequestParams = `environment=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deployFlow = stubLongRunningCall( undefined, @@ -1231,11 +1231,14 @@ describe('v3beta1.EnvironmentsClient', () => { ); const [operation] = await client.deployFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.deployFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deployFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkDeployFlowProgress without error', async () => { @@ -1287,15 +1290,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1310,11 +1309,14 @@ describe('v3beta1.EnvironmentsClient', () => { client.innerApiCalls.listEnvironments = stubSimpleCall(expectedResponse); const [response] = await client.listEnvironments(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEnvironments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEnvironments without error using callback', async () => { @@ -1326,15 +1328,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1367,11 +1365,14 @@ describe('v3beta1.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listEnvironments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEnvironments with error', async () => { @@ -1383,26 +1384,25 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listEnvironments = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listEnvironments(request), expectedError); - assert( - (client.innerApiCalls.listEnvironments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listEnvironments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listEnvironmentsStream without error', async () => { @@ -1414,8 +1414,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1453,11 +1456,12 @@ describe('v3beta1.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEnvironments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1470,8 +1474,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEnvironments.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1498,11 +1505,12 @@ describe('v3beta1.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listEnvironments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1515,8 +1523,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1543,11 +1554,12 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1560,8 +1572,11 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListEnvironmentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListEnvironmentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listEnvironments.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1579,11 +1594,12 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listEnvironments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listEnvironments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1598,15 +1614,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1622,11 +1635,14 @@ describe('v3beta1.EnvironmentsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.lookupEnvironmentHistory(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.lookupEnvironmentHistory as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes lookupEnvironmentHistory without error using callback', async () => { @@ -1638,15 +1654,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1679,11 +1692,14 @@ describe('v3beta1.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.lookupEnvironmentHistory as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes lookupEnvironmentHistory with error', async () => { @@ -1695,15 +1711,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.lookupEnvironmentHistory = stubSimpleCall( undefined, @@ -1713,11 +1726,14 @@ describe('v3beta1.EnvironmentsClient', () => { client.lookupEnvironmentHistory(request), expectedError ); - assert( - (client.innerApiCalls.lookupEnvironmentHistory as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.lookupEnvironmentHistory as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes lookupEnvironmentHistoryStream without error', async () => { @@ -1729,8 +1745,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1771,12 +1791,15 @@ describe('v3beta1.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.lookupEnvironmentHistory, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1789,8 +1812,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.lookupEnvironmentHistory.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1820,12 +1847,15 @@ describe('v3beta1.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.lookupEnvironmentHistory, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1838,8 +1868,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Environment() @@ -1867,12 +1901,15 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1885,8 +1922,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LookupEnvironmentHistoryRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; + const defaultValue1 = getTypeDefaultValue( + 'LookupEnvironmentHistoryRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.lookupEnvironmentHistory.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1905,12 +1946,15 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.lookupEnvironmentHistory .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1925,15 +1969,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ContinuousTestResult() @@ -1949,11 +1990,14 @@ describe('v3beta1.EnvironmentsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listContinuousTestResults(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listContinuousTestResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listContinuousTestResults without error using callback', async () => { @@ -1965,15 +2009,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ContinuousTestResult() @@ -2006,11 +2047,14 @@ describe('v3beta1.EnvironmentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listContinuousTestResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listContinuousTestResults with error', async () => { @@ -2022,15 +2066,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listContinuousTestResults = stubSimpleCall( undefined, @@ -2040,11 +2081,14 @@ describe('v3beta1.EnvironmentsClient', () => { client.listContinuousTestResults(request), expectedError ); - assert( - (client.innerApiCalls.listContinuousTestResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listContinuousTestResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listContinuousTestResultsStream without error', async () => { @@ -2056,8 +2100,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ContinuousTestResult() @@ -2100,12 +2148,15 @@ describe('v3beta1.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listContinuousTestResults, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2118,8 +2169,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listContinuousTestResults.createStream = stubPageStreamingCall(undefined, expectedError); @@ -2151,12 +2206,15 @@ describe('v3beta1.EnvironmentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listContinuousTestResults, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2169,8 +2227,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ContinuousTestResult() @@ -2198,12 +2260,15 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2216,8 +2281,12 @@ describe('v3beta1.EnvironmentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListContinuousTestResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListContinuousTestResultsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listContinuousTestResults.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2236,12 +2305,15 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listContinuousTestResults .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2392,12 +2464,15 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -2428,12 +2503,15 @@ describe('v3beta1.EnvironmentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_experiments_v3.ts b/test/gapic_experiments_v3.ts index ec7a436a..b7aaa1a1 100644 --- a/test/gapic_experiments_v3.ts +++ b/test/gapic_experiments_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); client.innerApiCalls.getExperiment = stubSimpleCall(expectedResponse); const [response] = await client.getExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getExperiment without error using callback', async () => { @@ -251,15 +265,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); @@ -282,11 +292,14 @@ describe('v3.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getExperiment with error', async () => { @@ -298,26 +311,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getExperiment(request), expectedError); - assert( - (client.innerApiCalls.getExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getExperiment with closed client', async () => { @@ -329,7 +341,10 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getExperiment(request), expectedError); @@ -346,26 +361,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateExperimentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); client.innerApiCalls.createExperiment = stubSimpleCall(expectedResponse); const [response] = await client.createExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createExperiment without error using callback', async () => { @@ -377,15 +391,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateExperimentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); @@ -408,11 +418,14 @@ describe('v3.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createExperiment with error', async () => { @@ -424,26 +437,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateExperimentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createExperiment(request), expectedError); - assert( - (client.innerApiCalls.createExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createExperiment with closed client', async () => { @@ -455,7 +467,10 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateExperimentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createExperiment(request), expectedError); @@ -472,27 +487,27 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; - const expectedHeaderRequestParams = 'experiment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; + const expectedHeaderRequestParams = `experiment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); client.innerApiCalls.updateExperiment = stubSimpleCall(expectedResponse); const [response] = await client.updateExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateExperiment without error using callback', async () => { @@ -504,16 +519,13 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; - const expectedHeaderRequestParams = 'experiment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; + const expectedHeaderRequestParams = `experiment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); @@ -536,11 +548,14 @@ describe('v3.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateExperiment with error', async () => { @@ -552,27 +567,27 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; - const expectedHeaderRequestParams = 'experiment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; + const expectedHeaderRequestParams = `experiment.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateExperiment(request), expectedError); - assert( - (client.innerApiCalls.updateExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateExperiment with closed client', async () => { @@ -584,8 +599,12 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateExperiment(request), expectedError); @@ -602,26 +621,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteExperiment = stubSimpleCall(expectedResponse); const [response] = await client.deleteExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteExperiment without error using callback', async () => { @@ -633,15 +651,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -664,11 +678,14 @@ describe('v3.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteExperiment with error', async () => { @@ -680,26 +697,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteExperiment(request), expectedError); - assert( - (client.innerApiCalls.deleteExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteExperiment with closed client', async () => { @@ -711,7 +727,10 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteExperiment(request), expectedError); @@ -728,26 +747,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StartExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); client.innerApiCalls.startExperiment = stubSimpleCall(expectedResponse); const [response] = await client.startExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.startExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startExperiment without error using callback', async () => { @@ -759,15 +777,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StartExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); @@ -790,11 +804,14 @@ describe('v3.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.startExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startExperiment with error', async () => { @@ -806,26 +823,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StartExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.startExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.startExperiment(request), expectedError); - assert( - (client.innerApiCalls.startExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startExperiment with closed client', async () => { @@ -837,7 +853,10 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StartExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.startExperiment(request), expectedError); @@ -854,26 +873,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StopExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); client.innerApiCalls.stopExperiment = stubSimpleCall(expectedResponse); const [response] = await client.stopExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.stopExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopExperiment without error using callback', async () => { @@ -885,15 +903,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StopExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() ); @@ -916,11 +930,14 @@ describe('v3.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.stopExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopExperiment with error', async () => { @@ -932,26 +949,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StopExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.stopExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.stopExperiment(request), expectedError); - assert( - (client.innerApiCalls.stopExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopExperiment with closed client', async () => { @@ -963,7 +979,10 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StopExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.stopExperiment(request), expectedError); @@ -980,15 +999,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() @@ -1003,11 +1018,14 @@ describe('v3.ExperimentsClient', () => { client.innerApiCalls.listExperiments = stubSimpleCall(expectedResponse); const [response] = await client.listExperiments(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listExperiments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listExperiments without error using callback', async () => { @@ -1019,15 +1037,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() @@ -1058,11 +1072,14 @@ describe('v3.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listExperiments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listExperiments with error', async () => { @@ -1074,26 +1091,25 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listExperiments = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listExperiments(request), expectedError); - assert( - (client.innerApiCalls.listExperiments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listExperimentsStream without error', async () => { @@ -1105,8 +1121,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() @@ -1143,11 +1162,12 @@ describe('v3.ExperimentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listExperiments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1160,8 +1180,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listExperiments.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1187,11 +1210,12 @@ describe('v3.ExperimentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listExperiments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1204,8 +1228,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Experiment() @@ -1231,11 +1258,12 @@ describe('v3.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1248,8 +1276,11 @@ describe('v3.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listExperiments.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1267,11 +1298,12 @@ describe('v3.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1422,12 +1454,15 @@ describe('v3.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1458,12 +1493,15 @@ describe('v3.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_experiments_v3beta1.ts b/test/gapic_experiments_v3beta1.ts index 4830f7fb..f15c6812 100644 --- a/test/gapic_experiments_v3beta1.ts +++ b/test/gapic_experiments_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); client.innerApiCalls.getExperiment = stubSimpleCall(expectedResponse); const [response] = await client.getExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getExperiment without error using callback', async () => { @@ -253,15 +267,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); @@ -284,11 +294,14 @@ describe('v3beta1.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getExperiment with error', async () => { @@ -300,26 +313,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getExperiment(request), expectedError); - assert( - (client.innerApiCalls.getExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getExperiment with closed client', async () => { @@ -331,7 +343,10 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getExperiment(request), expectedError); @@ -348,26 +363,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateExperimentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); client.innerApiCalls.createExperiment = stubSimpleCall(expectedResponse); const [response] = await client.createExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createExperiment without error using callback', async () => { @@ -379,15 +393,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateExperimentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); @@ -410,11 +420,14 @@ describe('v3beta1.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createExperiment with error', async () => { @@ -426,26 +439,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateExperimentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createExperiment(request), expectedError); - assert( - (client.innerApiCalls.createExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createExperiment with closed client', async () => { @@ -457,7 +469,10 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateExperimentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateExperimentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createExperiment(request), expectedError); @@ -474,27 +489,27 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; - const expectedHeaderRequestParams = 'experiment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; + const expectedHeaderRequestParams = `experiment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); client.innerApiCalls.updateExperiment = stubSimpleCall(expectedResponse); const [response] = await client.updateExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateExperiment without error using callback', async () => { @@ -506,16 +521,13 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; - const expectedHeaderRequestParams = 'experiment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; + const expectedHeaderRequestParams = `experiment.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); @@ -538,11 +550,14 @@ describe('v3beta1.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateExperiment with error', async () => { @@ -554,27 +569,27 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; - const expectedHeaderRequestParams = 'experiment.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; + const expectedHeaderRequestParams = `experiment.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateExperiment(request), expectedError); - assert( - (client.innerApiCalls.updateExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateExperiment with closed client', async () => { @@ -586,8 +601,12 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateExperimentRequest() ); - request.experiment = {}; - request.experiment.name = ''; + request.experiment ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateExperimentRequest', [ + 'experiment', + 'name', + ]); + request.experiment.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateExperiment(request), expectedError); @@ -604,26 +623,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteExperiment = stubSimpleCall(expectedResponse); const [response] = await client.deleteExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteExperiment without error using callback', async () => { @@ -635,15 +653,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -666,11 +680,14 @@ describe('v3beta1.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteExperiment with error', async () => { @@ -682,26 +699,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteExperiment(request), expectedError); - assert( - (client.innerApiCalls.deleteExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteExperiment with closed client', async () => { @@ -713,7 +729,10 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteExperiment(request), expectedError); @@ -730,26 +749,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StartExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); client.innerApiCalls.startExperiment = stubSimpleCall(expectedResponse); const [response] = await client.startExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.startExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startExperiment without error using callback', async () => { @@ -761,15 +779,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StartExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); @@ -792,11 +806,14 @@ describe('v3beta1.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.startExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startExperiment with error', async () => { @@ -808,26 +825,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StartExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.startExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.startExperiment(request), expectedError); - assert( - (client.innerApiCalls.startExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.startExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes startExperiment with closed client', async () => { @@ -839,7 +855,10 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StartExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('StartExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.startExperiment(request), expectedError); @@ -856,26 +875,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StopExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); client.innerApiCalls.stopExperiment = stubSimpleCall(expectedResponse); const [response] = await client.stopExperiment(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.stopExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopExperiment without error using callback', async () => { @@ -887,15 +905,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StopExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() ); @@ -918,11 +932,14 @@ describe('v3beta1.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.stopExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopExperiment with error', async () => { @@ -934,26 +951,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StopExperimentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.stopExperiment = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.stopExperiment(request), expectedError); - assert( - (client.innerApiCalls.stopExperiment as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.stopExperiment as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes stopExperiment with closed client', async () => { @@ -965,7 +981,10 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StopExperimentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('StopExperimentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.stopExperiment(request), expectedError); @@ -982,15 +1001,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() @@ -1005,11 +1020,14 @@ describe('v3beta1.ExperimentsClient', () => { client.innerApiCalls.listExperiments = stubSimpleCall(expectedResponse); const [response] = await client.listExperiments(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listExperiments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listExperiments without error using callback', async () => { @@ -1021,15 +1039,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() @@ -1062,11 +1076,14 @@ describe('v3beta1.ExperimentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listExperiments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listExperiments with error', async () => { @@ -1078,26 +1095,25 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listExperiments = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listExperiments(request), expectedError); - assert( - (client.innerApiCalls.listExperiments as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listExperiments as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listExperimentsStream without error', async () => { @@ -1109,8 +1125,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() @@ -1148,11 +1167,12 @@ describe('v3beta1.ExperimentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listExperiments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1165,8 +1185,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listExperiments.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1193,11 +1216,12 @@ describe('v3beta1.ExperimentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listExperiments, request) ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1210,8 +1234,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Experiment() @@ -1238,11 +1265,12 @@ describe('v3beta1.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1255,8 +1283,11 @@ describe('v3beta1.ExperimentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListExperimentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListExperimentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listExperiments.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1274,11 +1305,12 @@ describe('v3beta1.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listExperiments.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listExperiments.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1429,12 +1461,15 @@ describe('v3beta1.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1465,12 +1500,15 @@ describe('v3beta1.ExperimentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_flows_v3.ts b/test/gapic_flows_v3.ts index 77e05c93..b6b6490f 100644 --- a/test/gapic_flows_v3.ts +++ b/test/gapic_flows_v3.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,26 +272,25 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Flow() ); client.innerApiCalls.createFlow = stubSimpleCall(expectedResponse); const [response] = await client.createFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createFlow without error using callback', async () => { @@ -288,15 +302,11 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Flow() ); @@ -319,11 +329,14 @@ describe('v3.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createFlow with error', async () => { @@ -335,26 +348,25 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createFlow(request), expectedError); - assert( - (client.innerApiCalls.createFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createFlow with closed client', async () => { @@ -366,7 +378,10 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateFlowRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createFlow(request), expectedError); @@ -383,26 +398,23 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteFlow = stubSimpleCall(expectedResponse); const [response] = await client.deleteFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteFlow without error using callback', async () => { @@ -414,15 +426,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -445,11 +451,14 @@ describe('v3.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteFlow with error', async () => { @@ -461,26 +470,23 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteFlow(request), expectedError); - assert( - (client.innerApiCalls.deleteFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteFlow with closed client', async () => { @@ -492,7 +498,8 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteFlowRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteFlow(request), expectedError); @@ -509,26 +516,23 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Flow() ); client.innerApiCalls.getFlow = stubSimpleCall(expectedResponse); const [response] = await client.getFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getFlow as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlow without error using callback', async () => { @@ -540,15 +544,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Flow() ); @@ -571,11 +569,14 @@ describe('v3.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = (client.innerApiCalls.getFlow as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlow with error', async () => { @@ -587,23 +588,20 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getFlow = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getFlow(request), expectedError); - assert( - (client.innerApiCalls.getFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getFlow as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlow with closed client', async () => { @@ -615,7 +613,8 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getFlow(request), expectedError); @@ -632,27 +631,27 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; - const expectedHeaderRequestParams = 'flow.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; + const expectedHeaderRequestParams = `flow.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Flow() ); client.innerApiCalls.updateFlow = stubSimpleCall(expectedResponse); const [response] = await client.updateFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateFlow without error using callback', async () => { @@ -664,16 +663,13 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; - const expectedHeaderRequestParams = 'flow.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; + const expectedHeaderRequestParams = `flow.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Flow() ); @@ -696,11 +692,14 @@ describe('v3.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateFlow with error', async () => { @@ -712,27 +711,27 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; - const expectedHeaderRequestParams = 'flow.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; + const expectedHeaderRequestParams = `flow.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateFlow(request), expectedError); - assert( - (client.innerApiCalls.updateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateFlow with closed client', async () => { @@ -744,8 +743,12 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateFlow(request), expectedError); @@ -762,26 +765,25 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FlowValidationResult() ); client.innerApiCalls.validateFlow = stubSimpleCall(expectedResponse); const [response] = await client.validateFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateFlow without error using callback', async () => { @@ -793,15 +795,11 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FlowValidationResult() ); @@ -824,11 +822,14 @@ describe('v3.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateFlow with error', async () => { @@ -840,26 +841,25 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.validateFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.validateFlow(request), expectedError); - assert( - (client.innerApiCalls.validateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateFlow with closed client', async () => { @@ -871,7 +871,10 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ValidateFlowRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.validateFlow(request), expectedError); @@ -888,15 +891,12 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FlowValidationResult() ); @@ -904,11 +904,14 @@ describe('v3.FlowsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getFlowValidationResult(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlowValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlowValidationResult without error using callback', async () => { @@ -920,15 +923,12 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FlowValidationResult() ); @@ -951,11 +951,14 @@ describe('v3.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlowValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlowValidationResult with error', async () => { @@ -967,15 +970,12 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getFlowValidationResult = stubSimpleCall( undefined, @@ -985,11 +985,14 @@ describe('v3.FlowsClient', () => { client.getFlowValidationResult(request), expectedError ); - assert( - (client.innerApiCalls.getFlowValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlowValidationResult with closed client', async () => { @@ -1001,7 +1004,11 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetFlowValidationResultRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -1021,15 +1028,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1037,11 +1038,14 @@ describe('v3.FlowsClient', () => { const [operation] = await client.trainFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes trainFlow without error using callback', async () => { @@ -1053,15 +1057,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1091,11 +1089,14 @@ describe('v3.FlowsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes trainFlow with call error', async () => { @@ -1107,26 +1108,23 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.trainFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.trainFlow(request), expectedError); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes trainFlow with LRO error', async () => { @@ -1138,15 +1136,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.trainFlow = stubLongRunningCall( undefined, @@ -1155,11 +1147,14 @@ describe('v3.FlowsClient', () => { ); const [operation] = await client.trainFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkTrainFlowProgress without error', async () => { @@ -1211,15 +1206,11 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1227,11 +1218,14 @@ describe('v3.FlowsClient', () => { const [operation] = await client.importFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importFlow without error using callback', async () => { @@ -1243,15 +1237,11 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1281,11 +1271,14 @@ describe('v3.FlowsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importFlow with call error', async () => { @@ -1297,26 +1290,25 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.importFlow(request), expectedError); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importFlow with LRO error', async () => { @@ -1328,15 +1320,11 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importFlow = stubLongRunningCall( undefined, @@ -1345,11 +1333,14 @@ describe('v3.FlowsClient', () => { ); const [operation] = await client.importFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkImportFlowProgress without error', async () => { @@ -1401,15 +1392,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1417,11 +1402,14 @@ describe('v3.FlowsClient', () => { const [operation] = await client.exportFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportFlow without error using callback', async () => { @@ -1433,15 +1421,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1471,11 +1453,14 @@ describe('v3.FlowsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportFlow with call error', async () => { @@ -1487,26 +1472,23 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.exportFlow(request), expectedError); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportFlow with LRO error', async () => { @@ -1518,15 +1500,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportFlow = stubLongRunningCall( undefined, @@ -1535,11 +1511,14 @@ describe('v3.FlowsClient', () => { ); const [operation] = await client.exportFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkExportFlowProgress without error', async () => { @@ -1591,15 +1570,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), @@ -1608,11 +1581,14 @@ describe('v3.FlowsClient', () => { client.innerApiCalls.listFlows = stubSimpleCall(expectedResponse); const [response] = await client.listFlows(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listFlows as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listFlows without error using callback', async () => { @@ -1624,15 +1600,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), @@ -1657,11 +1627,14 @@ describe('v3.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listFlows as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listFlows with error', async () => { @@ -1673,23 +1646,20 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listFlows = stubSimpleCall(undefined, expectedError); await assert.rejects(client.listFlows(request), expectedError); - assert( - (client.innerApiCalls.listFlows as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listFlowsStream without error', async () => { @@ -1701,8 +1671,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), @@ -1733,10 +1704,12 @@ describe('v3.FlowsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listFlows, request) ); - assert.strictEqual( - (client.descriptors.page.listFlows.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1749,8 +1722,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listFlows.createStream = stubPageStreamingCall( undefined, @@ -1778,10 +1752,12 @@ describe('v3.FlowsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listFlows, request) ); - assert.strictEqual( - (client.descriptors.page.listFlows.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1794,8 +1770,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Flow()), @@ -1814,10 +1791,12 @@ describe('v3.FlowsClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listFlows.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1830,8 +1809,9 @@ describe('v3.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listFlows.asyncIterate = stubAsyncIterationCall( undefined, @@ -1849,10 +1829,12 @@ describe('v3.FlowsClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listFlows.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2003,12 +1985,15 @@ describe('v3.FlowsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -2039,12 +2024,15 @@ describe('v3.FlowsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_flows_v3beta1.ts b/test/gapic_flows_v3beta1.ts index 66966621..26f939dc 100644 --- a/test/gapic_flows_v3beta1.ts +++ b/test/gapic_flows_v3beta1.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,26 +272,25 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() ); client.innerApiCalls.createFlow = stubSimpleCall(expectedResponse); const [response] = await client.createFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createFlow without error using callback', async () => { @@ -288,15 +302,11 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() ); @@ -319,11 +329,14 @@ describe('v3beta1.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createFlow with error', async () => { @@ -335,26 +348,25 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createFlow(request), expectedError); - assert( - (client.innerApiCalls.createFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createFlow with closed client', async () => { @@ -366,7 +378,10 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createFlow(request), expectedError); @@ -383,26 +398,23 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteFlow = stubSimpleCall(expectedResponse); const [response] = await client.deleteFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteFlow without error using callback', async () => { @@ -414,15 +426,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -445,11 +451,14 @@ describe('v3beta1.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteFlow with error', async () => { @@ -461,26 +470,23 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteFlow(request), expectedError); - assert( - (client.innerApiCalls.deleteFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteFlow with closed client', async () => { @@ -492,7 +498,8 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteFlowRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteFlowRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteFlow(request), expectedError); @@ -509,26 +516,23 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() ); client.innerApiCalls.getFlow = stubSimpleCall(expectedResponse); const [response] = await client.getFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getFlow as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlow without error using callback', async () => { @@ -540,15 +544,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() ); @@ -571,11 +569,14 @@ describe('v3beta1.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = (client.innerApiCalls.getFlow as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlow with error', async () => { @@ -587,23 +588,20 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getFlow = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getFlow(request), expectedError); - assert( - (client.innerApiCalls.getFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getFlow as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlow with closed client', async () => { @@ -615,7 +613,8 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetFlowRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getFlow(request), expectedError); @@ -632,27 +631,27 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; - const expectedHeaderRequestParams = 'flow.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; + const expectedHeaderRequestParams = `flow.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() ); client.innerApiCalls.updateFlow = stubSimpleCall(expectedResponse); const [response] = await client.updateFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateFlow without error using callback', async () => { @@ -664,16 +663,13 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; - const expectedHeaderRequestParams = 'flow.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; + const expectedHeaderRequestParams = `flow.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() ); @@ -696,11 +692,14 @@ describe('v3beta1.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateFlow with error', async () => { @@ -712,27 +711,27 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; - const expectedHeaderRequestParams = 'flow.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; + const expectedHeaderRequestParams = `flow.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateFlow(request), expectedError); - assert( - (client.innerApiCalls.updateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateFlow with closed client', async () => { @@ -744,8 +743,12 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateFlowRequest() ); - request.flow = {}; - request.flow.name = ''; + request.flow ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateFlowRequest', [ + 'flow', + 'name', + ]); + request.flow.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateFlow(request), expectedError); @@ -762,26 +765,25 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FlowValidationResult() ); client.innerApiCalls.validateFlow = stubSimpleCall(expectedResponse); const [response] = await client.validateFlow(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateFlow without error using callback', async () => { @@ -793,15 +795,11 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FlowValidationResult() ); @@ -824,11 +822,14 @@ describe('v3beta1.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.validateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateFlow with error', async () => { @@ -840,26 +841,25 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.validateFlow = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.validateFlow(request), expectedError); - assert( - (client.innerApiCalls.validateFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.validateFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes validateFlow with closed client', async () => { @@ -871,7 +871,10 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ValidateFlowRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('ValidateFlowRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.validateFlow(request), expectedError); @@ -888,15 +891,12 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FlowValidationResult() ); @@ -904,11 +904,14 @@ describe('v3beta1.FlowsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getFlowValidationResult(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlowValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlowValidationResult without error using callback', async () => { @@ -920,15 +923,12 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FlowValidationResult() ); @@ -951,11 +951,14 @@ describe('v3beta1.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getFlowValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlowValidationResult with error', async () => { @@ -967,15 +970,12 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowValidationResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getFlowValidationResult = stubSimpleCall( undefined, @@ -985,11 +985,14 @@ describe('v3beta1.FlowsClient', () => { client.getFlowValidationResult(request), expectedError ); - assert( - (client.innerApiCalls.getFlowValidationResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getFlowValidationResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getFlowValidationResult with closed client', async () => { @@ -1001,7 +1004,11 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetFlowValidationResultRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'GetFlowValidationResultRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -1021,15 +1028,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1037,11 +1038,14 @@ describe('v3beta1.FlowsClient', () => { const [operation] = await client.trainFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes trainFlow without error using callback', async () => { @@ -1053,15 +1057,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1091,11 +1089,14 @@ describe('v3beta1.FlowsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes trainFlow with call error', async () => { @@ -1107,26 +1108,23 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.trainFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.trainFlow(request), expectedError); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes trainFlow with LRO error', async () => { @@ -1138,15 +1136,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TrainFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('TrainFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.trainFlow = stubLongRunningCall( undefined, @@ -1155,11 +1147,14 @@ describe('v3beta1.FlowsClient', () => { ); const [operation] = await client.trainFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.trainFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.trainFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkTrainFlowProgress without error', async () => { @@ -1211,15 +1206,11 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1227,11 +1218,14 @@ describe('v3beta1.FlowsClient', () => { const [operation] = await client.importFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importFlow without error using callback', async () => { @@ -1243,15 +1237,11 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1281,11 +1271,14 @@ describe('v3beta1.FlowsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importFlow with call error', async () => { @@ -1297,26 +1290,25 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.importFlow(request), expectedError); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importFlow with LRO error', async () => { @@ -1328,15 +1320,11 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportFlowRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportFlowRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importFlow = stubLongRunningCall( undefined, @@ -1345,11 +1333,14 @@ describe('v3beta1.FlowsClient', () => { ); const [operation] = await client.importFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.importFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkImportFlowProgress without error', async () => { @@ -1401,15 +1392,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1417,11 +1402,14 @@ describe('v3beta1.FlowsClient', () => { const [operation] = await client.exportFlow(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportFlow without error using callback', async () => { @@ -1433,15 +1421,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1471,11 +1453,14 @@ describe('v3beta1.FlowsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportFlow with call error', async () => { @@ -1487,26 +1472,23 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportFlow = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.exportFlow(request), expectedError); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportFlow with LRO error', async () => { @@ -1518,15 +1500,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportFlowRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportFlowRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportFlow = stubLongRunningCall( undefined, @@ -1535,11 +1511,14 @@ describe('v3beta1.FlowsClient', () => { ); const [operation] = await client.exportFlow(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.exportFlow as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportFlow as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkExportFlowProgress without error', async () => { @@ -1591,15 +1570,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() @@ -1614,11 +1587,14 @@ describe('v3beta1.FlowsClient', () => { client.innerApiCalls.listFlows = stubSimpleCall(expectedResponse); const [response] = await client.listFlows(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listFlows as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listFlows without error using callback', async () => { @@ -1630,15 +1606,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() @@ -1669,11 +1639,14 @@ describe('v3beta1.FlowsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listFlows as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listFlows with error', async () => { @@ -1685,23 +1658,20 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listFlows = stubSimpleCall(undefined, expectedError); await assert.rejects(client.listFlows(request), expectedError); - assert( - (client.innerApiCalls.listFlows as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listFlows as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listFlowsStream without error', async () => { @@ -1713,8 +1683,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() @@ -1751,10 +1722,12 @@ describe('v3beta1.FlowsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listFlows, request) ); - assert.strictEqual( - (client.descriptors.page.listFlows.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1767,8 +1740,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listFlows.createStream = stubPageStreamingCall( undefined, @@ -1796,10 +1770,12 @@ describe('v3beta1.FlowsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listFlows, request) ); - assert.strictEqual( - (client.descriptors.page.listFlows.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1812,8 +1788,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Flow() @@ -1838,10 +1815,12 @@ describe('v3beta1.FlowsClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listFlows.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1854,8 +1833,9 @@ describe('v3beta1.FlowsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListFlowsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListFlowsRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listFlows.asyncIterate = stubAsyncIterationCall( undefined, @@ -1873,10 +1853,12 @@ describe('v3beta1.FlowsClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listFlows.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listFlows.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2027,12 +2009,15 @@ describe('v3beta1.FlowsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -2063,12 +2048,15 @@ describe('v3beta1.FlowsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_intents_v3.ts b/test/gapic_intents_v3.ts index 8a5f1bd5..78641187 100644 --- a/test/gapic_intents_v3.ts +++ b/test/gapic_intents_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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,23 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() ); client.innerApiCalls.getIntent = stubSimpleCall(expectedResponse); const [response] = await client.getIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIntent without error using callback', async () => { @@ -251,15 +263,9 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() ); @@ -282,11 +288,14 @@ describe('v3.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIntent with error', async () => { @@ -298,23 +307,20 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getIntent = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getIntent(request), expectedError); - assert( - (client.innerApiCalls.getIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIntent with closed client', async () => { @@ -326,7 +332,8 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetIntentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getIntent(request), expectedError); @@ -343,26 +350,25 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateIntentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() ); client.innerApiCalls.createIntent = stubSimpleCall(expectedResponse); const [response] = await client.createIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createIntent without error using callback', async () => { @@ -374,15 +380,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateIntentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() ); @@ -405,11 +407,14 @@ describe('v3.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createIntent with error', async () => { @@ -421,26 +426,25 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateIntentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createIntent(request), expectedError); - assert( - (client.innerApiCalls.createIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createIntent with closed client', async () => { @@ -452,7 +456,10 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateIntentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createIntent(request), expectedError); @@ -469,27 +476,27 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; - const expectedHeaderRequestParams = 'intent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; + const expectedHeaderRequestParams = `intent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() ); client.innerApiCalls.updateIntent = stubSimpleCall(expectedResponse); const [response] = await client.updateIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateIntent without error using callback', async () => { @@ -501,16 +508,13 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; - const expectedHeaderRequestParams = 'intent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; + const expectedHeaderRequestParams = `intent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() ); @@ -533,11 +537,14 @@ describe('v3.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateIntent with error', async () => { @@ -549,27 +556,27 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; - const expectedHeaderRequestParams = 'intent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; + const expectedHeaderRequestParams = `intent.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateIntent(request), expectedError); - assert( - (client.innerApiCalls.updateIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateIntent with closed client', async () => { @@ -581,8 +588,12 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateIntent(request), expectedError); @@ -599,26 +610,25 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteIntent = stubSimpleCall(expectedResponse); const [response] = await client.deleteIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteIntent without error using callback', async () => { @@ -630,15 +640,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -661,11 +667,14 @@ describe('v3.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteIntent with error', async () => { @@ -677,26 +686,25 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteIntent(request), expectedError); - assert( - (client.innerApiCalls.deleteIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteIntent with closed client', async () => { @@ -708,7 +716,10 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteIntentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteIntent(request), expectedError); @@ -725,15 +736,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() @@ -748,11 +755,14 @@ describe('v3.IntentsClient', () => { client.innerApiCalls.listIntents = stubSimpleCall(expectedResponse); const [response] = await client.listIntents(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listIntents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listIntents without error using callback', async () => { @@ -764,15 +774,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() @@ -803,11 +809,14 @@ describe('v3.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listIntents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listIntents with error', async () => { @@ -819,26 +828,25 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listIntents = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listIntents(request), expectedError); - assert( - (client.innerApiCalls.listIntents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listIntentsStream without error', async () => { @@ -850,8 +858,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() @@ -888,11 +899,12 @@ describe('v3.IntentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listIntents, request) ); - assert.strictEqual( - (client.descriptors.page.listIntents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -905,8 +917,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listIntents.createStream = stubPageStreamingCall( undefined, @@ -934,11 +949,12 @@ describe('v3.IntentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listIntents, request) ); - assert.strictEqual( - (client.descriptors.page.listIntents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -951,8 +967,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Intent() @@ -978,11 +997,12 @@ describe('v3.IntentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listIntents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -995,8 +1015,11 @@ describe('v3.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listIntents.asyncIterate = stubAsyncIterationCall( undefined, @@ -1015,11 +1038,12 @@ describe('v3.IntentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listIntents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1170,12 +1194,15 @@ describe('v3.IntentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1206,12 +1233,15 @@ describe('v3.IntentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_intents_v3beta1.ts b/test/gapic_intents_v3beta1.ts index 4e5600e8..1d0f30f7 100644 --- a/test/gapic_intents_v3beta1.ts +++ b/test/gapic_intents_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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,23 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() ); client.innerApiCalls.getIntent = stubSimpleCall(expectedResponse); const [response] = await client.getIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIntent without error using callback', async () => { @@ -251,15 +263,9 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() ); @@ -282,11 +288,14 @@ describe('v3beta1.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIntent with error', async () => { @@ -298,23 +307,20 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getIntent = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getIntent(request), expectedError); - assert( - (client.innerApiCalls.getIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getIntent with closed client', async () => { @@ -326,7 +332,8 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetIntentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetIntentRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getIntent(request), expectedError); @@ -343,26 +350,25 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateIntentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() ); client.innerApiCalls.createIntent = stubSimpleCall(expectedResponse); const [response] = await client.createIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createIntent without error using callback', async () => { @@ -374,15 +380,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateIntentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() ); @@ -405,11 +407,14 @@ describe('v3beta1.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createIntent with error', async () => { @@ -421,26 +426,25 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateIntentRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createIntent(request), expectedError); - assert( - (client.innerApiCalls.createIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createIntent with closed client', async () => { @@ -452,7 +456,10 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateIntentRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateIntentRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createIntent(request), expectedError); @@ -469,27 +476,27 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; - const expectedHeaderRequestParams = 'intent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; + const expectedHeaderRequestParams = `intent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() ); client.innerApiCalls.updateIntent = stubSimpleCall(expectedResponse); const [response] = await client.updateIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateIntent without error using callback', async () => { @@ -501,16 +508,13 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; - const expectedHeaderRequestParams = 'intent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; + const expectedHeaderRequestParams = `intent.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() ); @@ -533,11 +537,14 @@ describe('v3beta1.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateIntent with error', async () => { @@ -549,27 +556,27 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; - const expectedHeaderRequestParams = 'intent.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; + const expectedHeaderRequestParams = `intent.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateIntent(request), expectedError); - assert( - (client.innerApiCalls.updateIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateIntent with closed client', async () => { @@ -581,8 +588,12 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateIntentRequest() ); - request.intent = {}; - request.intent.name = ''; + request.intent ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateIntentRequest', [ + 'intent', + 'name', + ]); + request.intent.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateIntent(request), expectedError); @@ -599,26 +610,25 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteIntent = stubSimpleCall(expectedResponse); const [response] = await client.deleteIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteIntent without error using callback', async () => { @@ -630,15 +640,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -661,11 +667,14 @@ describe('v3beta1.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteIntent with error', async () => { @@ -677,26 +686,25 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteIntentRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteIntent(request), expectedError); - assert( - (client.innerApiCalls.deleteIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteIntent with closed client', async () => { @@ -708,7 +716,10 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteIntentRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteIntentRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteIntent(request), expectedError); @@ -725,15 +736,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() @@ -748,11 +755,14 @@ describe('v3beta1.IntentsClient', () => { client.innerApiCalls.listIntents = stubSimpleCall(expectedResponse); const [response] = await client.listIntents(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listIntents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listIntents without error using callback', async () => { @@ -764,15 +774,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() @@ -803,11 +809,14 @@ describe('v3beta1.IntentsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listIntents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listIntents with error', async () => { @@ -819,26 +828,25 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listIntents = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listIntents(request), expectedError); - assert( - (client.innerApiCalls.listIntents as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listIntents as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listIntentsStream without error', async () => { @@ -850,8 +858,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() @@ -889,11 +900,12 @@ describe('v3beta1.IntentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listIntents, request) ); - assert.strictEqual( - (client.descriptors.page.listIntents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -906,8 +918,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listIntents.createStream = stubPageStreamingCall( undefined, @@ -936,11 +951,12 @@ describe('v3beta1.IntentsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listIntents, request) ); - assert.strictEqual( - (client.descriptors.page.listIntents.createStream as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -953,8 +969,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Intent() @@ -980,11 +999,12 @@ describe('v3beta1.IntentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listIntents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -997,8 +1017,11 @@ describe('v3beta1.IntentsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListIntentsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListIntentsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listIntents.asyncIterate = stubAsyncIterationCall( undefined, @@ -1018,11 +1041,12 @@ describe('v3beta1.IntentsClient', () => { ).args[1], request ); - assert.strictEqual( - (client.descriptors.page.listIntents.asyncIterate as SinonStub).getCall( - 0 - ).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listIntents.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1173,12 +1197,15 @@ describe('v3beta1.IntentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1209,12 +1236,15 @@ describe('v3beta1.IntentsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_pages_v3.ts b/test/gapic_pages_v3.ts index 660dd288..e898e307 100644 --- a/test/gapic_pages_v3.ts +++ b/test/gapic_pages_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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,23 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetPageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Page() ); client.innerApiCalls.getPage = stubSimpleCall(expectedResponse); const [response] = await client.getPage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getPage as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPage without error using callback', async () => { @@ -251,15 +263,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetPageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Page() ); @@ -282,11 +288,14 @@ describe('v3.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = (client.innerApiCalls.getPage as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPage with error', async () => { @@ -298,23 +307,20 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetPageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getPage = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getPage(request), expectedError); - assert( - (client.innerApiCalls.getPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getPage as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPage with closed client', async () => { @@ -326,7 +332,8 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetPageRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getPage(request), expectedError); @@ -343,26 +350,25 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreatePageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Page() ); client.innerApiCalls.createPage = stubSimpleCall(expectedResponse); const [response] = await client.createPage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPage without error using callback', async () => { @@ -374,15 +380,11 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreatePageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Page() ); @@ -405,11 +407,14 @@ describe('v3.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPage with error', async () => { @@ -421,26 +426,25 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreatePageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createPage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createPage(request), expectedError); - assert( - (client.innerApiCalls.createPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPage with closed client', async () => { @@ -452,7 +456,10 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreatePageRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createPage(request), expectedError); @@ -469,27 +476,27 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; - const expectedHeaderRequestParams = 'page.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; + const expectedHeaderRequestParams = `page.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Page() ); client.innerApiCalls.updatePage = stubSimpleCall(expectedResponse); const [response] = await client.updatePage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePage without error using callback', async () => { @@ -501,16 +508,13 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; - const expectedHeaderRequestParams = 'page.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; + const expectedHeaderRequestParams = `page.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Page() ); @@ -533,11 +537,14 @@ describe('v3.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePage with error', async () => { @@ -549,27 +556,27 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; - const expectedHeaderRequestParams = 'page.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; + const expectedHeaderRequestParams = `page.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updatePage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updatePage(request), expectedError); - assert( - (client.innerApiCalls.updatePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePage with closed client', async () => { @@ -581,8 +588,12 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updatePage(request), expectedError); @@ -599,26 +610,23 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeletePageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deletePage = stubSimpleCall(expectedResponse); const [response] = await client.deletePage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePage without error using callback', async () => { @@ -630,15 +638,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeletePageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -661,11 +663,14 @@ describe('v3.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePage with error', async () => { @@ -677,26 +682,23 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeletePageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deletePage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deletePage(request), expectedError); - assert( - (client.innerApiCalls.deletePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePage with closed client', async () => { @@ -708,7 +710,8 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeletePageRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deletePage(request), expectedError); @@ -725,15 +728,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), @@ -742,11 +739,14 @@ describe('v3.PagesClient', () => { client.innerApiCalls.listPages = stubSimpleCall(expectedResponse); const [response] = await client.listPages(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPages without error using callback', async () => { @@ -758,15 +758,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), @@ -791,11 +785,14 @@ describe('v3.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPages with error', async () => { @@ -807,23 +804,20 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listPages = stubSimpleCall(undefined, expectedError); await assert.rejects(client.listPages(request), expectedError); - assert( - (client.innerApiCalls.listPages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPagesStream without error', async () => { @@ -835,8 +829,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), @@ -867,10 +862,12 @@ describe('v3.PagesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPages, request) ); - assert.strictEqual( - (client.descriptors.page.listPages.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -883,8 +880,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPages.createStream = stubPageStreamingCall( undefined, @@ -912,10 +910,12 @@ describe('v3.PagesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPages, request) ); - assert.strictEqual( - (client.descriptors.page.listPages.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -928,8 +928,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), generateSampleMessage(new protos.google.cloud.dialogflow.cx.v3.Page()), @@ -948,10 +949,12 @@ describe('v3.PagesClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listPages.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -964,8 +967,9 @@ describe('v3.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPages.asyncIterate = stubAsyncIterationCall( undefined, @@ -983,10 +987,12 @@ describe('v3.PagesClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listPages.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1137,12 +1143,15 @@ describe('v3.PagesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1173,12 +1182,15 @@ describe('v3.PagesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_pages_v3beta1.ts b/test/gapic_pages_v3beta1.ts index bd90b33d..d46fd858 100644 --- a/test/gapic_pages_v3beta1.ts +++ b/test/gapic_pages_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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,23 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetPageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() ); client.innerApiCalls.getPage = stubSimpleCall(expectedResponse); const [response] = await client.getPage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getPage as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPage without error using callback', async () => { @@ -251,15 +263,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetPageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() ); @@ -282,11 +288,14 @@ describe('v3beta1.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = (client.innerApiCalls.getPage as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPage with error', async () => { @@ -298,23 +307,20 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetPageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getPage = stubSimpleCall(undefined, expectedError); await assert.rejects(client.getPage(request), expectedError); - assert( - (client.innerApiCalls.getPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = (client.innerApiCalls.getPage as SinonStub).getCall( + 0 + ).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getPage with closed client', async () => { @@ -326,7 +332,8 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetPageRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetPageRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getPage(request), expectedError); @@ -343,26 +350,25 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreatePageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() ); client.innerApiCalls.createPage = stubSimpleCall(expectedResponse); const [response] = await client.createPage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPage without error using callback', async () => { @@ -374,15 +380,11 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreatePageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() ); @@ -405,11 +407,14 @@ describe('v3beta1.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPage with error', async () => { @@ -421,26 +426,25 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreatePageRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createPage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createPage(request), expectedError); - assert( - (client.innerApiCalls.createPage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createPage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createPage with closed client', async () => { @@ -452,7 +456,10 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreatePageRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreatePageRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createPage(request), expectedError); @@ -469,27 +476,27 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; - const expectedHeaderRequestParams = 'page.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; + const expectedHeaderRequestParams = `page.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() ); client.innerApiCalls.updatePage = stubSimpleCall(expectedResponse); const [response] = await client.updatePage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePage without error using callback', async () => { @@ -501,16 +508,13 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; - const expectedHeaderRequestParams = 'page.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; + const expectedHeaderRequestParams = `page.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() ); @@ -533,11 +537,14 @@ describe('v3beta1.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updatePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePage with error', async () => { @@ -549,27 +556,27 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; - const expectedHeaderRequestParams = 'page.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; + const expectedHeaderRequestParams = `page.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updatePage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updatePage(request), expectedError); - assert( - (client.innerApiCalls.updatePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updatePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updatePage with closed client', async () => { @@ -581,8 +588,12 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdatePageRequest() ); - request.page = {}; - request.page.name = ''; + request.page ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdatePageRequest', [ + 'page', + 'name', + ]); + request.page.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updatePage(request), expectedError); @@ -599,26 +610,23 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeletePageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deletePage = stubSimpleCall(expectedResponse); const [response] = await client.deletePage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePage without error using callback', async () => { @@ -630,15 +638,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeletePageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -661,11 +663,14 @@ describe('v3beta1.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deletePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePage with error', async () => { @@ -677,26 +682,23 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeletePageRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deletePage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deletePage(request), expectedError); - assert( - (client.innerApiCalls.deletePage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deletePage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deletePage with closed client', async () => { @@ -708,7 +710,8 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeletePageRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeletePageRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deletePage(request), expectedError); @@ -725,15 +728,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() @@ -748,11 +745,14 @@ describe('v3beta1.PagesClient', () => { client.innerApiCalls.listPages = stubSimpleCall(expectedResponse); const [response] = await client.listPages(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPages without error using callback', async () => { @@ -764,15 +764,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() @@ -803,11 +797,14 @@ describe('v3beta1.PagesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listPages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPages with error', async () => { @@ -819,23 +816,20 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listPages = stubSimpleCall(undefined, expectedError); await assert.rejects(client.listPages(request), expectedError); - assert( - (client.innerApiCalls.listPages as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listPages as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listPagesStream without error', async () => { @@ -847,8 +841,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() @@ -885,10 +880,12 @@ describe('v3beta1.PagesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPages, request) ); - assert.strictEqual( - (client.descriptors.page.listPages.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -901,8 +898,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPages.createStream = stubPageStreamingCall( undefined, @@ -930,10 +928,12 @@ describe('v3beta1.PagesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listPages, request) ); - assert.strictEqual( - (client.descriptors.page.listPages.createStream as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -946,8 +946,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Page() @@ -972,10 +973,12 @@ describe('v3beta1.PagesClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listPages.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -988,8 +991,9 @@ describe('v3beta1.PagesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListPagesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListPagesRequest', ['parent']); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listPages.asyncIterate = stubAsyncIterationCall( undefined, @@ -1007,10 +1011,12 @@ describe('v3beta1.PagesClient', () => { .args[1], request ); - assert.strictEqual( - (client.descriptors.page.listPages.asyncIterate as SinonStub).getCall(0) - .args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listPages.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1161,12 +1167,15 @@ describe('v3beta1.PagesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1197,12 +1206,15 @@ describe('v3beta1.PagesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_security_settings_service_v3.ts b/test/gapic_security_settings_service_v3.ts index 4fb89370..e51e4f1b 100644 --- a/test/gapic_security_settings_service_v3.ts +++ b/test/gapic_security_settings_service_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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 @@ -233,15 +248,12 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() ); @@ -249,11 +261,14 @@ describe('v3.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSecuritySettings without error using callback', async () => { @@ -266,15 +281,12 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() ); @@ -297,11 +309,14 @@ describe('v3.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSecuritySettings with error', async () => { @@ -314,15 +329,12 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createSecuritySettings = stubSimpleCall( undefined, @@ -332,11 +344,14 @@ describe('v3.SecuritySettingsServiceClient', () => { client.createSecuritySettings(request), expectedError ); - assert( - (client.innerApiCalls.createSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSecuritySettings with closed client', async () => { @@ -349,7 +364,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSecuritySettingsRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -370,15 +389,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() ); @@ -386,11 +401,14 @@ describe('v3.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSecuritySettings without error using callback', async () => { @@ -403,15 +421,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() ); @@ -434,11 +448,14 @@ describe('v3.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSecuritySettings with error', async () => { @@ -451,26 +468,25 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getSecuritySettings = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getSecuritySettings(request), expectedError); - assert( - (client.innerApiCalls.getSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSecuritySettings with closed client', async () => { @@ -483,7 +499,10 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSecuritySettingsRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getSecuritySettings(request), expectedError); @@ -501,16 +520,13 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; - const expectedHeaderRequestParams = 'security_settings.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; + const expectedHeaderRequestParams = `security_settings.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() ); @@ -518,11 +534,14 @@ describe('v3.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSecuritySettings without error using callback', async () => { @@ -535,16 +554,13 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; - const expectedHeaderRequestParams = 'security_settings.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; + const expectedHeaderRequestParams = `security_settings.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() ); @@ -567,11 +583,14 @@ describe('v3.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSecuritySettings with error', async () => { @@ -584,16 +603,13 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; - const expectedHeaderRequestParams = 'security_settings.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; + const expectedHeaderRequestParams = `security_settings.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateSecuritySettings = stubSimpleCall( undefined, @@ -603,11 +619,14 @@ describe('v3.SecuritySettingsServiceClient', () => { client.updateSecuritySettings(request), expectedError ); - assert( - (client.innerApiCalls.updateSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSecuritySettings with closed client', async () => { @@ -620,8 +639,12 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -642,15 +665,12 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -658,11 +678,14 @@ describe('v3.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSecuritySettings without error using callback', async () => { @@ -675,15 +698,12 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -706,11 +726,14 @@ describe('v3.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSecuritySettings with error', async () => { @@ -723,15 +746,12 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteSecuritySettings = stubSimpleCall( undefined, @@ -741,11 +761,14 @@ describe('v3.SecuritySettingsServiceClient', () => { client.deleteSecuritySettings(request), expectedError ); - assert( - (client.innerApiCalls.deleteSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSecuritySettings with closed client', async () => { @@ -758,7 +781,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSecuritySettingsRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -779,15 +806,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() @@ -803,11 +826,14 @@ describe('v3.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSecuritySettings without error using callback', async () => { @@ -820,15 +846,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() @@ -861,11 +883,14 @@ describe('v3.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSecuritySettings with error', async () => { @@ -878,26 +903,25 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listSecuritySettings = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listSecuritySettings(request), expectedError); - assert( - (client.innerApiCalls.listSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSecuritySettingsStream without error', async () => { @@ -910,8 +934,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() @@ -949,11 +976,12 @@ describe('v3.SecuritySettingsServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSecuritySettings, request) ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -967,8 +995,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSecuritySettings.createStream = stubPageStreamingCall(undefined, expectedError); @@ -995,11 +1026,12 @@ describe('v3.SecuritySettingsServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSecuritySettings, request) ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1013,8 +1045,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SecuritySettings() @@ -1041,11 +1076,12 @@ describe('v3.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1059,8 +1095,11 @@ describe('v3.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSecuritySettings.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1078,11 +1117,12 @@ describe('v3.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1237,12 +1277,15 @@ describe('v3.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1274,12 +1317,15 @@ describe('v3.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_security_settings_service_v3beta1.ts b/test/gapic_security_settings_service_v3beta1.ts index 7548cca0..2667612d 100644 --- a/test/gapic_security_settings_service_v3beta1.ts +++ b/test/gapic_security_settings_service_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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 @@ -248,15 +263,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() ); @@ -264,11 +276,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSecuritySettings without error using callback', async () => { @@ -283,15 +298,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() ); @@ -314,11 +326,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSecuritySettings with error', async () => { @@ -333,15 +348,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createSecuritySettings = stubSimpleCall( undefined, @@ -351,11 +363,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { client.createSecuritySettings(request), expectedError ); - assert( - (client.innerApiCalls.createSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSecuritySettings with closed client', async () => { @@ -370,7 +385,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSecuritySettingsRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateSecuritySettingsRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -393,15 +412,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() ); @@ -409,11 +424,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSecuritySettings without error using callback', async () => { @@ -428,15 +446,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() ); @@ -459,11 +473,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSecuritySettings with error', async () => { @@ -478,26 +495,25 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getSecuritySettings = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getSecuritySettings(request), expectedError); - assert( - (client.innerApiCalls.getSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSecuritySettings with closed client', async () => { @@ -512,7 +528,10 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSecuritySettingsRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetSecuritySettingsRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getSecuritySettings(request), expectedError); @@ -532,16 +551,13 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; - const expectedHeaderRequestParams = 'security_settings.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; + const expectedHeaderRequestParams = `security_settings.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() ); @@ -549,11 +565,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSecuritySettings without error using callback', async () => { @@ -568,16 +587,13 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; - const expectedHeaderRequestParams = 'security_settings.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; + const expectedHeaderRequestParams = `security_settings.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() ); @@ -600,11 +616,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSecuritySettings with error', async () => { @@ -619,16 +638,13 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; - const expectedHeaderRequestParams = 'security_settings.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; + const expectedHeaderRequestParams = `security_settings.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateSecuritySettings = stubSimpleCall( undefined, @@ -638,11 +654,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { client.updateSecuritySettings(request), expectedError ); - assert( - (client.innerApiCalls.updateSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSecuritySettings with closed client', async () => { @@ -657,8 +676,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSecuritySettingsRequest() ); - request.securitySettings = {}; - request.securitySettings.name = ''; + request.securitySettings ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSecuritySettingsRequest', + ['securitySettings', 'name'] + ); + request.securitySettings.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -681,15 +704,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -697,11 +717,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSecuritySettings without error using callback', async () => { @@ -716,15 +739,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -747,11 +767,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSecuritySettings with error', async () => { @@ -766,15 +789,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSecuritySettingsRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteSecuritySettings = stubSimpleCall( undefined, @@ -784,11 +804,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { client.deleteSecuritySettings(request), expectedError ); - assert( - (client.innerApiCalls.deleteSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSecuritySettings with closed client', async () => { @@ -803,7 +826,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSecuritySettingsRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSecuritySettingsRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -826,15 +853,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() @@ -850,11 +873,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listSecuritySettings(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSecuritySettings without error using callback', async () => { @@ -869,15 +895,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() @@ -910,11 +932,14 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSecuritySettings with error', async () => { @@ -929,26 +954,25 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listSecuritySettings = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listSecuritySettings(request), expectedError); - assert( - (client.innerApiCalls.listSecuritySettings as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSecuritySettings as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSecuritySettingsStream without error', async () => { @@ -963,8 +987,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() @@ -1004,11 +1031,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSecuritySettings, request) ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1024,8 +1052,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSecuritySettings.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1054,11 +1085,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSecuritySettings, request) ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1074,8 +1106,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SecuritySettings() @@ -1102,11 +1137,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1122,8 +1158,11 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSecuritySettingsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListSecuritySettingsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSecuritySettings.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1141,11 +1180,12 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listSecuritySettings.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1308,12 +1348,15 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1347,12 +1390,15 @@ describe('v3beta1.SecuritySettingsServiceClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_session_entity_types_v3.ts b/test/gapic_session_entity_types_v3.ts index a4aa9b68..1d7f4ddc 100644 --- a/test/gapic_session_entity_types_v3.ts +++ b/test/gapic_session_entity_types_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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,15 +237,11 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() ); @@ -238,11 +249,14 @@ describe('v3.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSessionEntityType without error using callback', async () => { @@ -254,15 +268,11 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() ); @@ -285,11 +295,14 @@ describe('v3.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSessionEntityType with error', async () => { @@ -301,26 +314,25 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getSessionEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getSessionEntityType(request), expectedError); - assert( - (client.innerApiCalls.getSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSessionEntityType with closed client', async () => { @@ -332,7 +344,10 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetSessionEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getSessionEntityType(request), expectedError); @@ -349,15 +364,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSessionEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() ); @@ -365,11 +377,14 @@ describe('v3.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSessionEntityType without error using callback', async () => { @@ -381,15 +396,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSessionEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() ); @@ -412,11 +424,14 @@ describe('v3.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSessionEntityType with error', async () => { @@ -428,15 +443,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSessionEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createSessionEntityType = stubSimpleCall( undefined, @@ -446,11 +458,14 @@ describe('v3.SessionEntityTypesClient', () => { client.createSessionEntityType(request), expectedError ); - assert( - (client.innerApiCalls.createSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSessionEntityType with closed client', async () => { @@ -462,7 +477,11 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateSessionEntityTypeRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -482,16 +501,13 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; - const expectedHeaderRequestParams = 'session_entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; + const expectedHeaderRequestParams = `session_entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() ); @@ -499,11 +515,14 @@ describe('v3.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSessionEntityType without error using callback', async () => { @@ -515,16 +534,13 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; - const expectedHeaderRequestParams = 'session_entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; + const expectedHeaderRequestParams = `session_entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() ); @@ -547,11 +563,14 @@ describe('v3.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSessionEntityType with error', async () => { @@ -563,16 +582,13 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; - const expectedHeaderRequestParams = 'session_entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; + const expectedHeaderRequestParams = `session_entity_type.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateSessionEntityType = stubSimpleCall( undefined, @@ -582,11 +598,14 @@ describe('v3.SessionEntityTypesClient', () => { client.updateSessionEntityType(request), expectedError ); - assert( - (client.innerApiCalls.updateSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSessionEntityType with closed client', async () => { @@ -598,8 +617,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -619,15 +642,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -635,11 +655,14 @@ describe('v3.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSessionEntityType without error using callback', async () => { @@ -651,15 +674,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -682,11 +702,14 @@ describe('v3.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSessionEntityType with error', async () => { @@ -698,15 +721,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteSessionEntityType = stubSimpleCall( undefined, @@ -716,11 +736,14 @@ describe('v3.SessionEntityTypesClient', () => { client.deleteSessionEntityType(request), expectedError ); - assert( - (client.innerApiCalls.deleteSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSessionEntityType with closed client', async () => { @@ -732,7 +755,11 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteSessionEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -752,15 +779,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() @@ -776,11 +800,14 @@ describe('v3.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listSessionEntityTypes(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSessionEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSessionEntityTypes without error using callback', async () => { @@ -792,15 +819,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() @@ -833,11 +857,14 @@ describe('v3.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSessionEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSessionEntityTypes with error', async () => { @@ -849,15 +876,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listSessionEntityTypes = stubSimpleCall( undefined, @@ -867,11 +891,14 @@ describe('v3.SessionEntityTypesClient', () => { client.listSessionEntityTypes(request), expectedError ); - assert( - (client.innerApiCalls.listSessionEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSessionEntityTypesStream without error', async () => { @@ -883,8 +910,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() @@ -927,12 +958,15 @@ describe('v3.SessionEntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSessionEntityTypes, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -945,8 +979,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSessionEntityTypes.createStream = stubPageStreamingCall(undefined, expectedError); @@ -978,12 +1016,15 @@ describe('v3.SessionEntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSessionEntityTypes, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -996,8 +1037,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.SessionEntityType() @@ -1025,12 +1070,15 @@ describe('v3.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1043,8 +1091,12 @@ describe('v3.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSessionEntityTypes.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1063,12 +1115,15 @@ describe('v3.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1219,12 +1274,15 @@ describe('v3.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1255,12 +1313,15 @@ describe('v3.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_session_entity_types_v3beta1.ts b/test/gapic_session_entity_types_v3beta1.ts index e3da2eb9..c19892db 100644 --- a/test/gapic_session_entity_types_v3beta1.ts +++ b/test/gapic_session_entity_types_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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 @@ -231,15 +246,11 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() ); @@ -247,11 +258,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSessionEntityType without error using callback', async () => { @@ -264,15 +278,11 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() ); @@ -295,11 +305,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSessionEntityType with error', async () => { @@ -312,26 +325,25 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getSessionEntityType = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getSessionEntityType(request), expectedError); - assert( - (client.innerApiCalls.getSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getSessionEntityType with closed client', async () => { @@ -344,7 +356,10 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetSessionEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetSessionEntityTypeRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getSessionEntityType(request), expectedError); @@ -362,15 +377,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSessionEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() ); @@ -378,11 +390,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSessionEntityType without error using callback', async () => { @@ -395,15 +410,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSessionEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() ); @@ -426,11 +438,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSessionEntityType with error', async () => { @@ -443,15 +458,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSessionEntityTypeRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createSessionEntityType = stubSimpleCall( undefined, @@ -461,11 +473,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { client.createSessionEntityType(request), expectedError ); - assert( - (client.innerApiCalls.createSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createSessionEntityType with closed client', async () => { @@ -478,7 +493,11 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateSessionEntityTypeRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateSessionEntityTypeRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -499,16 +518,13 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; - const expectedHeaderRequestParams = 'session_entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; + const expectedHeaderRequestParams = `session_entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() ); @@ -516,11 +532,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSessionEntityType without error using callback', async () => { @@ -533,16 +552,13 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; - const expectedHeaderRequestParams = 'session_entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; + const expectedHeaderRequestParams = `session_entity_type.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() ); @@ -565,11 +581,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSessionEntityType with error', async () => { @@ -582,16 +601,13 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; - const expectedHeaderRequestParams = 'session_entity_type.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; + const expectedHeaderRequestParams = `session_entity_type.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateSessionEntityType = stubSimpleCall( undefined, @@ -601,11 +617,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { client.updateSessionEntityType(request), expectedError ); - assert( - (client.innerApiCalls.updateSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateSessionEntityType with closed client', async () => { @@ -618,8 +637,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateSessionEntityTypeRequest() ); - request.sessionEntityType = {}; - request.sessionEntityType.name = ''; + request.sessionEntityType ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateSessionEntityTypeRequest', + ['sessionEntityType', 'name'] + ); + request.sessionEntityType.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -640,15 +663,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -656,11 +676,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteSessionEntityType(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSessionEntityType without error using callback', async () => { @@ -673,15 +696,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -704,11 +724,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSessionEntityType with error', async () => { @@ -721,15 +744,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSessionEntityTypeRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteSessionEntityType = stubSimpleCall( undefined, @@ -739,11 +759,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { client.deleteSessionEntityType(request), expectedError ); - assert( - (client.innerApiCalls.deleteSessionEntityType as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteSessionEntityType as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteSessionEntityType with closed client', async () => { @@ -756,7 +779,11 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteSessionEntityTypeRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteSessionEntityTypeRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -777,15 +804,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() @@ -801,11 +825,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listSessionEntityTypes(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSessionEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSessionEntityTypes without error using callback', async () => { @@ -818,15 +845,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() @@ -859,11 +883,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listSessionEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSessionEntityTypes with error', async () => { @@ -876,15 +903,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listSessionEntityTypes = stubSimpleCall( undefined, @@ -894,11 +918,14 @@ describe('v3beta1.SessionEntityTypesClient', () => { client.listSessionEntityTypes(request), expectedError ); - assert( - (client.innerApiCalls.listSessionEntityTypes as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listSessionEntityTypes as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listSessionEntityTypesStream without error', async () => { @@ -911,8 +938,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() @@ -955,12 +986,15 @@ describe('v3beta1.SessionEntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSessionEntityTypes, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -974,8 +1008,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSessionEntityTypes.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1007,12 +1045,15 @@ describe('v3beta1.SessionEntityTypesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listSessionEntityTypes, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1026,8 +1067,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.SessionEntityType() @@ -1055,12 +1100,15 @@ describe('v3beta1.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1074,8 +1122,12 @@ describe('v3beta1.SessionEntityTypesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListSessionEntityTypesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListSessionEntityTypesRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listSessionEntityTypes.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1094,12 +1146,15 @@ describe('v3beta1.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listSessionEntityTypes .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1254,12 +1309,15 @@ describe('v3beta1.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1291,12 +1349,15 @@ describe('v3beta1.SessionEntityTypesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_sessions_v3.ts b/test/gapic_sessions_v3.ts index 0c57a3cd..4bccb0fc 100644 --- a/test/gapic_sessions_v3.ts +++ b/test/gapic_sessions_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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 @@ -196,26 +211,25 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DetectIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DetectIntentResponse() ); client.innerApiCalls.detectIntent = stubSimpleCall(expectedResponse); const [response] = await client.detectIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectIntent without error using callback', async () => { @@ -227,15 +241,11 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DetectIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DetectIntentResponse() ); @@ -258,11 +268,14 @@ describe('v3.SessionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectIntent with error', async () => { @@ -274,26 +287,25 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DetectIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.detectIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.detectIntent(request), expectedError); - assert( - (client.innerApiCalls.detectIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectIntent with closed client', async () => { @@ -305,7 +317,10 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DetectIntentRequest() ); - request.session = ''; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.detectIntent(request), expectedError); @@ -322,26 +337,25 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.MatchIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.MatchIntentResponse() ); client.innerApiCalls.matchIntent = stubSimpleCall(expectedResponse); const [response] = await client.matchIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.matchIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes matchIntent without error using callback', async () => { @@ -353,15 +367,11 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.MatchIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.MatchIntentResponse() ); @@ -384,11 +394,14 @@ describe('v3.SessionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.matchIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes matchIntent with error', async () => { @@ -400,26 +413,25 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.MatchIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.matchIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.matchIntent(request), expectedError); - assert( - (client.innerApiCalls.matchIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes matchIntent with closed client', async () => { @@ -431,7 +443,10 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.MatchIntentRequest() ); - request.session = ''; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.matchIntent(request), expectedError); @@ -448,27 +463,27 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; - const expectedHeaderRequestParams = 'match_intent_request.session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; + const expectedHeaderRequestParams = `match_intent_request.session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FulfillIntentResponse() ); client.innerApiCalls.fulfillIntent = stubSimpleCall(expectedResponse); const [response] = await client.fulfillIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.fulfillIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes fulfillIntent without error using callback', async () => { @@ -480,16 +495,13 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; - const expectedHeaderRequestParams = 'match_intent_request.session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; + const expectedHeaderRequestParams = `match_intent_request.session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FulfillIntentResponse() ); @@ -512,11 +524,14 @@ describe('v3.SessionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.fulfillIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes fulfillIntent with error', async () => { @@ -528,27 +543,27 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; - const expectedHeaderRequestParams = 'match_intent_request.session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; + const expectedHeaderRequestParams = `match_intent_request.session=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.fulfillIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.fulfillIntent(request), expectedError); - assert( - (client.innerApiCalls.fulfillIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes fulfillIntent with closed client', async () => { @@ -560,8 +575,12 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.fulfillIntent(request), expectedError); @@ -578,6 +597,7 @@ describe('v3.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StreamingDetectIntentRequest() ); + const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.StreamingDetectIntentResponse() ); @@ -803,12 +823,15 @@ describe('v3.SessionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -839,12 +862,15 @@ describe('v3.SessionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_sessions_v3beta1.ts b/test/gapic_sessions_v3beta1.ts index 71f683bf..b7d9f285 100644 --- a/test/gapic_sessions_v3beta1.ts +++ b/test/gapic_sessions_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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 @@ -196,26 +211,25 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DetectIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DetectIntentResponse() ); client.innerApiCalls.detectIntent = stubSimpleCall(expectedResponse); const [response] = await client.detectIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectIntent without error using callback', async () => { @@ -227,15 +241,11 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DetectIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DetectIntentResponse() ); @@ -258,11 +268,14 @@ describe('v3beta1.SessionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.detectIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectIntent with error', async () => { @@ -274,26 +287,25 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DetectIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.detectIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.detectIntent(request), expectedError); - assert( - (client.innerApiCalls.detectIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.detectIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes detectIntent with closed client', async () => { @@ -305,7 +317,10 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DetectIntentRequest() ); - request.session = ''; + const defaultValue1 = getTypeDefaultValue('DetectIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.detectIntent(request), expectedError); @@ -322,26 +337,25 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.MatchIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.MatchIntentResponse() ); client.innerApiCalls.matchIntent = stubSimpleCall(expectedResponse); const [response] = await client.matchIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.matchIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes matchIntent without error using callback', async () => { @@ -353,15 +367,11 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.MatchIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.MatchIntentResponse() ); @@ -384,11 +394,14 @@ describe('v3beta1.SessionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.matchIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes matchIntent with error', async () => { @@ -400,26 +413,25 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.MatchIntentRequest() ); - request.session = ''; - const expectedHeaderRequestParams = 'session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; + const expectedHeaderRequestParams = `session=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.matchIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.matchIntent(request), expectedError); - assert( - (client.innerApiCalls.matchIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.matchIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes matchIntent with closed client', async () => { @@ -431,7 +443,10 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.MatchIntentRequest() ); - request.session = ''; + const defaultValue1 = getTypeDefaultValue('MatchIntentRequest', [ + 'session', + ]); + request.session = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.matchIntent(request), expectedError); @@ -448,27 +463,27 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; - const expectedHeaderRequestParams = 'match_intent_request.session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; + const expectedHeaderRequestParams = `match_intent_request.session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FulfillIntentResponse() ); client.innerApiCalls.fulfillIntent = stubSimpleCall(expectedResponse); const [response] = await client.fulfillIntent(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.fulfillIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes fulfillIntent without error using callback', async () => { @@ -480,16 +495,13 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; - const expectedHeaderRequestParams = 'match_intent_request.session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; + const expectedHeaderRequestParams = `match_intent_request.session=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FulfillIntentResponse() ); @@ -512,11 +524,14 @@ describe('v3beta1.SessionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.fulfillIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes fulfillIntent with error', async () => { @@ -528,27 +543,27 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; - const expectedHeaderRequestParams = 'match_intent_request.session='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; + const expectedHeaderRequestParams = `match_intent_request.session=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.fulfillIntent = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.fulfillIntent(request), expectedError); - assert( - (client.innerApiCalls.fulfillIntent as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.fulfillIntent as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes fulfillIntent with closed client', async () => { @@ -560,8 +575,12 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.FulfillIntentRequest() ); - request.matchIntentRequest = {}; - request.matchIntentRequest.session = ''; + request.matchIntentRequest ??= {}; + const defaultValue1 = getTypeDefaultValue('FulfillIntentRequest', [ + 'matchIntentRequest', + 'session', + ]); + request.matchIntentRequest.session = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.fulfillIntent(request), expectedError); @@ -578,6 +597,7 @@ describe('v3beta1.SessionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StreamingDetectIntentRequest() ); + const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.StreamingDetectIntentResponse() ); @@ -803,12 +823,15 @@ describe('v3beta1.SessionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -839,12 +862,15 @@ describe('v3beta1.SessionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_test_cases_v3.ts b/test/gapic_test_cases_v3.ts index 48c3d1ec..37d44d2c 100644 --- a/test/gapic_test_cases_v3.ts +++ b/test/gapic_test_cases_v3.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,15 +272,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchDeleteTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -273,11 +284,14 @@ describe('v3.TestCasesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.batchDeleteTestCases(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchDeleteTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchDeleteTestCases without error using callback', async () => { @@ -289,15 +303,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchDeleteTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -320,11 +330,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchDeleteTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchDeleteTestCases with error', async () => { @@ -336,26 +349,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchDeleteTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchDeleteTestCases = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.batchDeleteTestCases(request), expectedError); - assert( - (client.innerApiCalls.batchDeleteTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchDeleteTestCases with closed client', async () => { @@ -367,7 +379,10 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchDeleteTestCasesRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.batchDeleteTestCases(request), expectedError); @@ -384,26 +399,23 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() ); client.innerApiCalls.getTestCase = stubSimpleCall(expectedResponse); const [response] = await client.getTestCase(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCase without error using callback', async () => { @@ -415,15 +427,9 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() ); @@ -446,11 +452,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCase with error', async () => { @@ -462,26 +471,23 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getTestCase = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getTestCase(request), expectedError); - assert( - (client.innerApiCalls.getTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCase with closed client', async () => { @@ -493,7 +499,8 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getTestCase(request), expectedError); @@ -510,26 +517,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTestCaseRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() ); client.innerApiCalls.createTestCase = stubSimpleCall(expectedResponse); const [response] = await client.createTestCase(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTestCase without error using callback', async () => { @@ -541,15 +547,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTestCaseRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() ); @@ -572,11 +574,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTestCase with error', async () => { @@ -588,26 +593,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTestCaseRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createTestCase = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createTestCase(request), expectedError); - assert( - (client.innerApiCalls.createTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTestCase with closed client', async () => { @@ -619,7 +623,10 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTestCaseRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createTestCase(request), expectedError); @@ -636,27 +643,27 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; - const expectedHeaderRequestParams = 'test_case.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; + const expectedHeaderRequestParams = `test_case.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() ); client.innerApiCalls.updateTestCase = stubSimpleCall(expectedResponse); const [response] = await client.updateTestCase(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTestCase without error using callback', async () => { @@ -668,16 +675,13 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; - const expectedHeaderRequestParams = 'test_case.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; + const expectedHeaderRequestParams = `test_case.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() ); @@ -700,11 +704,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTestCase with error', async () => { @@ -716,27 +723,27 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; - const expectedHeaderRequestParams = 'test_case.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; + const expectedHeaderRequestParams = `test_case.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateTestCase = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateTestCase(request), expectedError); - assert( - (client.innerApiCalls.updateTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTestCase with closed client', async () => { @@ -748,8 +755,12 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateTestCase(request), expectedError); @@ -766,26 +777,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CalculateCoverageRequest() ); - request.agent = ''; - const expectedHeaderRequestParams = 'agent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; + const expectedHeaderRequestParams = `agent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CalculateCoverageResponse() ); client.innerApiCalls.calculateCoverage = stubSimpleCall(expectedResponse); const [response] = await client.calculateCoverage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.calculateCoverage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes calculateCoverage without error using callback', async () => { @@ -797,15 +807,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CalculateCoverageRequest() ); - request.agent = ''; - const expectedHeaderRequestParams = 'agent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; + const expectedHeaderRequestParams = `agent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CalculateCoverageResponse() ); @@ -828,11 +834,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.calculateCoverage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes calculateCoverage with error', async () => { @@ -844,26 +853,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CalculateCoverageRequest() ); - request.agent = ''; - const expectedHeaderRequestParams = 'agent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; + const expectedHeaderRequestParams = `agent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.calculateCoverage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.calculateCoverage(request), expectedError); - assert( - (client.innerApiCalls.calculateCoverage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes calculateCoverage with closed client', async () => { @@ -875,7 +883,10 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CalculateCoverageRequest() ); - request.agent = ''; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.calculateCoverage(request), expectedError); @@ -892,26 +903,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCaseResult() ); client.innerApiCalls.getTestCaseResult = stubSimpleCall(expectedResponse); const [response] = await client.getTestCaseResult(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCaseResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCaseResult without error using callback', async () => { @@ -923,15 +933,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCaseResult() ); @@ -954,11 +960,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCaseResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCaseResult with error', async () => { @@ -970,26 +979,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getTestCaseResult = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getTestCaseResult(request), expectedError); - assert( - (client.innerApiCalls.getTestCaseResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCaseResult with closed client', async () => { @@ -1001,7 +1009,10 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTestCaseResultRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getTestCaseResult(request), expectedError); @@ -1018,15 +1029,9 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1034,11 +1039,14 @@ describe('v3.TestCasesClient', () => { const [operation] = await client.runTestCase(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runTestCase without error using callback', async () => { @@ -1050,15 +1058,9 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1088,11 +1090,14 @@ describe('v3.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runTestCase with call error', async () => { @@ -1104,26 +1109,23 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runTestCase = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.runTestCase(request), expectedError); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runTestCase with LRO error', async () => { @@ -1135,15 +1137,9 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runTestCase = stubLongRunningCall( undefined, @@ -1152,11 +1148,14 @@ describe('v3.TestCasesClient', () => { ); const [operation] = await client.runTestCase(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkRunTestCaseProgress without error', async () => { @@ -1208,15 +1207,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1225,11 +1220,14 @@ describe('v3.TestCasesClient', () => { const [operation] = await client.batchRunTestCases(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchRunTestCases without error using callback', async () => { @@ -1241,15 +1239,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1279,11 +1273,14 @@ describe('v3.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchRunTestCases with call error', async () => { @@ -1295,26 +1292,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchRunTestCases = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.batchRunTestCases(request), expectedError); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchRunTestCases with LRO error', async () => { @@ -1326,15 +1322,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchRunTestCases = stubLongRunningCall( undefined, @@ -1343,11 +1335,14 @@ describe('v3.TestCasesClient', () => { ); const [operation] = await client.batchRunTestCases(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkBatchRunTestCasesProgress without error', async () => { @@ -1402,15 +1397,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1419,11 +1410,14 @@ describe('v3.TestCasesClient', () => { const [operation] = await client.importTestCases(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importTestCases without error using callback', async () => { @@ -1435,15 +1429,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1473,11 +1463,14 @@ describe('v3.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importTestCases with call error', async () => { @@ -1489,26 +1482,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importTestCases = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.importTestCases(request), expectedError); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importTestCases with LRO error', async () => { @@ -1520,15 +1512,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importTestCases = stubLongRunningCall( undefined, @@ -1537,11 +1525,14 @@ describe('v3.TestCasesClient', () => { ); const [operation] = await client.importTestCases(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkImportTestCasesProgress without error', async () => { @@ -1596,15 +1587,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1613,11 +1600,14 @@ describe('v3.TestCasesClient', () => { const [operation] = await client.exportTestCases(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportTestCases without error using callback', async () => { @@ -1629,15 +1619,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1667,11 +1653,14 @@ describe('v3.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportTestCases with call error', async () => { @@ -1683,26 +1672,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportTestCases = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.exportTestCases(request), expectedError); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportTestCases with LRO error', async () => { @@ -1714,15 +1702,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportTestCases = stubLongRunningCall( undefined, @@ -1731,11 +1715,14 @@ describe('v3.TestCasesClient', () => { ); const [operation] = await client.exportTestCases(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkExportTestCasesProgress without error', async () => { @@ -1790,15 +1777,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() @@ -1813,11 +1796,14 @@ describe('v3.TestCasesClient', () => { client.innerApiCalls.listTestCases = stubSimpleCall(expectedResponse); const [response] = await client.listTestCases(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCases without error using callback', async () => { @@ -1829,15 +1815,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() @@ -1868,11 +1850,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCases with error', async () => { @@ -1884,26 +1869,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listTestCases = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listTestCases(request), expectedError); - assert( - (client.innerApiCalls.listTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCasesStream without error', async () => { @@ -1915,8 +1899,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() @@ -1953,11 +1940,12 @@ describe('v3.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCases, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1970,8 +1958,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCases.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1997,11 +1988,12 @@ describe('v3.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCases, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2014,8 +2006,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCase() @@ -2041,11 +2036,12 @@ describe('v3.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2058,8 +2054,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCases.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2076,11 +2075,12 @@ describe('v3.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2095,15 +2095,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCaseResult() @@ -2119,11 +2115,14 @@ describe('v3.TestCasesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listTestCaseResults(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCaseResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCaseResults without error using callback', async () => { @@ -2135,15 +2134,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCaseResult() @@ -2176,11 +2171,14 @@ describe('v3.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCaseResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCaseResults with error', async () => { @@ -2192,26 +2190,25 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listTestCaseResults = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listTestCaseResults(request), expectedError); - assert( - (client.innerApiCalls.listTestCaseResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCaseResultsStream without error', async () => { @@ -2223,8 +2220,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCaseResult() @@ -2262,11 +2262,12 @@ describe('v3.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCaseResults, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2279,8 +2280,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCaseResults.createStream = stubPageStreamingCall(undefined, expectedError); @@ -2307,11 +2311,12 @@ describe('v3.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCaseResults, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2324,8 +2329,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TestCaseResult() @@ -2352,11 +2360,12 @@ describe('v3.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2369,8 +2378,11 @@ describe('v3.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCaseResults.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2388,11 +2400,12 @@ describe('v3.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2543,12 +2556,15 @@ describe('v3.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -2579,12 +2595,15 @@ describe('v3.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_test_cases_v3beta1.ts b/test/gapic_test_cases_v3beta1.ts index bfe12d5b..e49c9a05 100644 --- a/test/gapic_test_cases_v3beta1.ts +++ b/test/gapic_test_cases_v3beta1.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,15 +272,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchDeleteTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -273,11 +284,14 @@ describe('v3beta1.TestCasesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.batchDeleteTestCases(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchDeleteTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchDeleteTestCases without error using callback', async () => { @@ -289,15 +303,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchDeleteTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -320,11 +330,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchDeleteTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchDeleteTestCases with error', async () => { @@ -336,26 +349,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchDeleteTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchDeleteTestCases = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.batchDeleteTestCases(request), expectedError); - assert( - (client.innerApiCalls.batchDeleteTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchDeleteTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchDeleteTestCases with closed client', async () => { @@ -367,7 +379,10 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchDeleteTestCasesRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('BatchDeleteTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.batchDeleteTestCases(request), expectedError); @@ -384,26 +399,23 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() ); client.innerApiCalls.getTestCase = stubSimpleCall(expectedResponse); const [response] = await client.getTestCase(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCase without error using callback', async () => { @@ -415,15 +427,9 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() ); @@ -446,11 +452,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCase with error', async () => { @@ -462,26 +471,23 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getTestCase = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getTestCase(request), expectedError); - assert( - (client.innerApiCalls.getTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCase with closed client', async () => { @@ -493,7 +499,8 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetTestCaseRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getTestCase(request), expectedError); @@ -510,26 +517,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTestCaseRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() ); client.innerApiCalls.createTestCase = stubSimpleCall(expectedResponse); const [response] = await client.createTestCase(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTestCase without error using callback', async () => { @@ -541,15 +547,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTestCaseRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() ); @@ -572,11 +574,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTestCase with error', async () => { @@ -588,26 +593,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTestCaseRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createTestCase = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createTestCase(request), expectedError); - assert( - (client.innerApiCalls.createTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTestCase with closed client', async () => { @@ -619,7 +623,10 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTestCaseRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateTestCaseRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createTestCase(request), expectedError); @@ -636,27 +643,27 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; - const expectedHeaderRequestParams = 'test_case.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; + const expectedHeaderRequestParams = `test_case.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() ); client.innerApiCalls.updateTestCase = stubSimpleCall(expectedResponse); const [response] = await client.updateTestCase(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTestCase without error using callback', async () => { @@ -668,16 +675,13 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; - const expectedHeaderRequestParams = 'test_case.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; + const expectedHeaderRequestParams = `test_case.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() ); @@ -700,11 +704,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTestCase with error', async () => { @@ -716,27 +723,27 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; - const expectedHeaderRequestParams = 'test_case.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; + const expectedHeaderRequestParams = `test_case.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateTestCase = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateTestCase(request), expectedError); - assert( - (client.innerApiCalls.updateTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTestCase with closed client', async () => { @@ -748,8 +755,12 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTestCaseRequest() ); - request.testCase = {}; - request.testCase.name = ''; + request.testCase ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateTestCaseRequest', [ + 'testCase', + 'name', + ]); + request.testCase.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateTestCase(request), expectedError); @@ -766,26 +777,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CalculateCoverageRequest() ); - request.agent = ''; - const expectedHeaderRequestParams = 'agent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; + const expectedHeaderRequestParams = `agent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CalculateCoverageResponse() ); client.innerApiCalls.calculateCoverage = stubSimpleCall(expectedResponse); const [response] = await client.calculateCoverage(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.calculateCoverage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes calculateCoverage without error using callback', async () => { @@ -797,15 +807,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CalculateCoverageRequest() ); - request.agent = ''; - const expectedHeaderRequestParams = 'agent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; + const expectedHeaderRequestParams = `agent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CalculateCoverageResponse() ); @@ -828,11 +834,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.calculateCoverage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes calculateCoverage with error', async () => { @@ -844,26 +853,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CalculateCoverageRequest() ); - request.agent = ''; - const expectedHeaderRequestParams = 'agent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; + const expectedHeaderRequestParams = `agent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.calculateCoverage = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.calculateCoverage(request), expectedError); - assert( - (client.innerApiCalls.calculateCoverage as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.calculateCoverage as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes calculateCoverage with closed client', async () => { @@ -875,7 +883,10 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CalculateCoverageRequest() ); - request.agent = ''; + const defaultValue1 = getTypeDefaultValue('CalculateCoverageRequest', [ + 'agent', + ]); + request.agent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.calculateCoverage(request), expectedError); @@ -892,26 +903,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCaseResult() ); client.innerApiCalls.getTestCaseResult = stubSimpleCall(expectedResponse); const [response] = await client.getTestCaseResult(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCaseResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCaseResult without error using callback', async () => { @@ -923,15 +933,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCaseResult() ); @@ -954,11 +960,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTestCaseResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCaseResult with error', async () => { @@ -970,26 +979,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseResultRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getTestCaseResult = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getTestCaseResult(request), expectedError); - assert( - (client.innerApiCalls.getTestCaseResult as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTestCaseResult as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTestCaseResult with closed client', async () => { @@ -1001,7 +1009,10 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTestCaseResultRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetTestCaseResultRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getTestCaseResult(request), expectedError); @@ -1018,15 +1029,9 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1034,11 +1039,14 @@ describe('v3beta1.TestCasesClient', () => { const [operation] = await client.runTestCase(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runTestCase without error using callback', async () => { @@ -1050,15 +1058,9 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1088,11 +1090,14 @@ describe('v3beta1.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runTestCase with call error', async () => { @@ -1104,26 +1109,23 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runTestCase = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.runTestCase(request), expectedError); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes runTestCase with LRO error', async () => { @@ -1135,15 +1137,9 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.RunTestCaseRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('RunTestCaseRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.runTestCase = stubLongRunningCall( undefined, @@ -1152,11 +1148,14 @@ describe('v3beta1.TestCasesClient', () => { ); const [operation] = await client.runTestCase(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.runTestCase as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.runTestCase as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkRunTestCaseProgress without error', async () => { @@ -1208,15 +1207,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1225,11 +1220,14 @@ describe('v3beta1.TestCasesClient', () => { const [operation] = await client.batchRunTestCases(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchRunTestCases without error using callback', async () => { @@ -1241,15 +1239,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1279,11 +1273,14 @@ describe('v3beta1.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchRunTestCases with call error', async () => { @@ -1295,26 +1292,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchRunTestCases = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.batchRunTestCases(request), expectedError); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes batchRunTestCases with LRO error', async () => { @@ -1326,15 +1322,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.BatchRunTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('BatchRunTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.batchRunTestCases = stubLongRunningCall( undefined, @@ -1343,11 +1335,14 @@ describe('v3beta1.TestCasesClient', () => { ); const [operation] = await client.batchRunTestCases(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.batchRunTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.batchRunTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkBatchRunTestCasesProgress without error', async () => { @@ -1402,15 +1397,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1419,11 +1410,14 @@ describe('v3beta1.TestCasesClient', () => { const [operation] = await client.importTestCases(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importTestCases without error using callback', async () => { @@ -1435,15 +1429,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1473,11 +1463,14 @@ describe('v3beta1.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importTestCases with call error', async () => { @@ -1489,26 +1482,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importTestCases = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.importTestCases(request), expectedError); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes importTestCases with LRO error', async () => { @@ -1520,15 +1512,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ImportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ImportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.importTestCases = stubLongRunningCall( undefined, @@ -1537,11 +1525,14 @@ describe('v3beta1.TestCasesClient', () => { ); const [operation] = await client.importTestCases(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.importTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.importTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkImportTestCasesProgress without error', async () => { @@ -1596,15 +1587,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1613,11 +1600,14 @@ describe('v3beta1.TestCasesClient', () => { const [operation] = await client.exportTestCases(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportTestCases without error using callback', async () => { @@ -1629,15 +1619,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1667,11 +1653,14 @@ describe('v3beta1.TestCasesClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportTestCases with call error', async () => { @@ -1683,26 +1672,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportTestCases = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.exportTestCases(request), expectedError); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes exportTestCases with LRO error', async () => { @@ -1714,15 +1702,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ExportTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ExportTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.exportTestCases = stubLongRunningCall( undefined, @@ -1731,11 +1715,14 @@ describe('v3beta1.TestCasesClient', () => { ); const [operation] = await client.exportTestCases(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.exportTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.exportTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkExportTestCasesProgress without error', async () => { @@ -1790,15 +1777,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() @@ -1813,11 +1796,14 @@ describe('v3beta1.TestCasesClient', () => { client.innerApiCalls.listTestCases = stubSimpleCall(expectedResponse); const [response] = await client.listTestCases(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCases without error using callback', async () => { @@ -1829,15 +1815,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() @@ -1870,11 +1852,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCases with error', async () => { @@ -1886,26 +1871,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listTestCases = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listTestCases(request), expectedError); - assert( - (client.innerApiCalls.listTestCases as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCases as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCasesStream without error', async () => { @@ -1917,8 +1901,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() @@ -1956,11 +1943,12 @@ describe('v3beta1.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCases, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1973,8 +1961,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCases.createStream = stubPageStreamingCall(undefined, expectedError); @@ -2001,11 +1992,12 @@ describe('v3beta1.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCases, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2018,8 +2010,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCase() @@ -2046,11 +2041,12 @@ describe('v3beta1.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2063,8 +2059,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCasesRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCasesRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCases.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2082,11 +2081,12 @@ describe('v3beta1.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCases.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCases.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2101,15 +2101,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCaseResult() @@ -2125,11 +2121,14 @@ describe('v3beta1.TestCasesClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listTestCaseResults(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCaseResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCaseResults without error using callback', async () => { @@ -2141,15 +2140,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCaseResult() @@ -2182,11 +2177,14 @@ describe('v3beta1.TestCasesClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTestCaseResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCaseResults with error', async () => { @@ -2198,26 +2196,25 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listTestCaseResults = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listTestCaseResults(request), expectedError); - assert( - (client.innerApiCalls.listTestCaseResults as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTestCaseResults as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTestCaseResultsStream without error', async () => { @@ -2229,8 +2226,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCaseResult() @@ -2270,11 +2270,12 @@ describe('v3beta1.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCaseResults, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2287,8 +2288,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCaseResults.createStream = stubPageStreamingCall(undefined, expectedError); @@ -2317,11 +2321,12 @@ describe('v3beta1.TestCasesClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTestCaseResults, request) ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2334,8 +2339,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TestCaseResult() @@ -2362,11 +2370,12 @@ describe('v3beta1.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -2379,8 +2388,11 @@ describe('v3beta1.TestCasesClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTestCaseResultsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListTestCaseResultsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTestCaseResults.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -2398,11 +2410,12 @@ describe('v3beta1.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listTestCaseResults.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -2553,12 +2566,15 @@ describe('v3beta1.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -2589,12 +2605,15 @@ describe('v3beta1.TestCasesClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_transition_route_groups_v3.ts b/test/gapic_transition_route_groups_v3.ts index ede899cd..76ca7e82 100644 --- a/test/gapic_transition_route_groups_v3.ts +++ b/test/gapic_transition_route_groups_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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 @@ -231,15 +246,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() ); @@ -247,11 +259,14 @@ describe('v3.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTransitionRouteGroup without error using callback', async () => { @@ -264,15 +279,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() ); @@ -295,11 +307,14 @@ describe('v3.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTransitionRouteGroup with error', async () => { @@ -312,15 +327,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getTransitionRouteGroup = stubSimpleCall( undefined, @@ -330,11 +342,14 @@ describe('v3.TransitionRouteGroupsClient', () => { client.getTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.getTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTransitionRouteGroup with closed client', async () => { @@ -347,7 +362,11 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetTransitionRouteGroupRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -368,15 +387,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTransitionRouteGroupRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() ); @@ -384,11 +400,14 @@ describe('v3.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTransitionRouteGroup without error using callback', async () => { @@ -401,15 +420,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTransitionRouteGroupRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() ); @@ -432,11 +448,14 @@ describe('v3.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTransitionRouteGroup with error', async () => { @@ -449,15 +468,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTransitionRouteGroupRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createTransitionRouteGroup = stubSimpleCall( undefined, @@ -467,11 +483,14 @@ describe('v3.TransitionRouteGroupsClient', () => { client.createTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.createTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTransitionRouteGroup with closed client', async () => { @@ -484,7 +503,11 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateTransitionRouteGroupRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -505,16 +528,13 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; - const expectedHeaderRequestParams = 'transition_route_group.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; + const expectedHeaderRequestParams = `transition_route_group.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() ); @@ -522,11 +542,14 @@ describe('v3.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTransitionRouteGroup without error using callback', async () => { @@ -539,16 +562,13 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; - const expectedHeaderRequestParams = 'transition_route_group.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; + const expectedHeaderRequestParams = `transition_route_group.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() ); @@ -571,11 +591,14 @@ describe('v3.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTransitionRouteGroup with error', async () => { @@ -588,16 +611,13 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; - const expectedHeaderRequestParams = 'transition_route_group.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; + const expectedHeaderRequestParams = `transition_route_group.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateTransitionRouteGroup = stubSimpleCall( undefined, @@ -607,11 +627,14 @@ describe('v3.TransitionRouteGroupsClient', () => { client.updateTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.updateTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTransitionRouteGroup with closed client', async () => { @@ -624,8 +647,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -646,15 +673,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -662,11 +686,14 @@ describe('v3.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteTransitionRouteGroup without error using callback', async () => { @@ -679,15 +706,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -710,11 +734,14 @@ describe('v3.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteTransitionRouteGroup with error', async () => { @@ -727,15 +754,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteTransitionRouteGroup = stubSimpleCall( undefined, @@ -745,11 +769,14 @@ describe('v3.TransitionRouteGroupsClient', () => { client.deleteTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.deleteTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteTransitionRouteGroup with closed client', async () => { @@ -762,7 +789,11 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteTransitionRouteGroupRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -783,15 +814,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() @@ -807,11 +835,14 @@ describe('v3.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listTransitionRouteGroups(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTransitionRouteGroups as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTransitionRouteGroups without error using callback', async () => { @@ -824,15 +855,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() @@ -865,11 +893,14 @@ describe('v3.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTransitionRouteGroups as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTransitionRouteGroups with error', async () => { @@ -882,15 +913,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listTransitionRouteGroups = stubSimpleCall( undefined, @@ -900,11 +928,14 @@ describe('v3.TransitionRouteGroupsClient', () => { client.listTransitionRouteGroups(request), expectedError ); - assert( - (client.innerApiCalls.listTransitionRouteGroups as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTransitionRouteGroupsStream without error', async () => { @@ -917,8 +948,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() @@ -961,12 +996,15 @@ describe('v3.TransitionRouteGroupsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTransitionRouteGroups, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -980,8 +1018,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTransitionRouteGroups.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1013,12 +1055,15 @@ describe('v3.TransitionRouteGroupsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTransitionRouteGroups, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1032,8 +1077,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.TransitionRouteGroup() @@ -1061,12 +1110,15 @@ describe('v3.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1080,8 +1132,12 @@ describe('v3.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTransitionRouteGroups.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1100,12 +1156,15 @@ describe('v3.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1260,12 +1319,15 @@ describe('v3.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1297,12 +1359,15 @@ describe('v3.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_transition_route_groups_v3beta1.ts b/test/gapic_transition_route_groups_v3beta1.ts index e1c5a81f..4bcc7029 100644 --- a/test/gapic_transition_route_groups_v3beta1.ts +++ b/test/gapic_transition_route_groups_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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 @@ -233,15 +248,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() ); @@ -249,11 +261,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.getTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTransitionRouteGroup without error using callback', async () => { @@ -266,15 +281,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() ); @@ -297,11 +309,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTransitionRouteGroup with error', async () => { @@ -314,15 +329,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getTransitionRouteGroup = stubSimpleCall( undefined, @@ -332,11 +344,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { client.getTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.getTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getTransitionRouteGroup with closed client', async () => { @@ -349,7 +364,11 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetTransitionRouteGroupRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'GetTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -370,15 +389,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTransitionRouteGroupRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() ); @@ -386,11 +402,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.createTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTransitionRouteGroup without error using callback', async () => { @@ -403,15 +422,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTransitionRouteGroupRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() ); @@ -434,11 +450,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTransitionRouteGroup with error', async () => { @@ -451,15 +470,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTransitionRouteGroupRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createTransitionRouteGroup = stubSimpleCall( undefined, @@ -469,11 +485,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { client.createTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.createTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createTransitionRouteGroup with closed client', async () => { @@ -486,7 +505,11 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateTransitionRouteGroupRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue( + 'CreateTransitionRouteGroupRequest', + ['parent'] + ); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -507,16 +530,13 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; - const expectedHeaderRequestParams = 'transition_route_group.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; + const expectedHeaderRequestParams = `transition_route_group.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() ); @@ -524,11 +544,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.updateTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTransitionRouteGroup without error using callback', async () => { @@ -541,16 +564,13 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; - const expectedHeaderRequestParams = 'transition_route_group.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; + const expectedHeaderRequestParams = `transition_route_group.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() ); @@ -573,11 +593,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTransitionRouteGroup with error', async () => { @@ -590,16 +613,13 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; - const expectedHeaderRequestParams = 'transition_route_group.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; + const expectedHeaderRequestParams = `transition_route_group.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateTransitionRouteGroup = stubSimpleCall( undefined, @@ -609,11 +629,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { client.updateTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.updateTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateTransitionRouteGroup with closed client', async () => { @@ -626,8 +649,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateTransitionRouteGroupRequest() ); - request.transitionRouteGroup = {}; - request.transitionRouteGroup.name = ''; + request.transitionRouteGroup ??= {}; + const defaultValue1 = getTypeDefaultValue( + 'UpdateTransitionRouteGroupRequest', + ['transitionRouteGroup', 'name'] + ); + request.transitionRouteGroup.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -648,15 +675,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -664,11 +688,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.deleteTransitionRouteGroup(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteTransitionRouteGroup without error using callback', async () => { @@ -681,15 +708,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -712,11 +736,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteTransitionRouteGroup with error', async () => { @@ -729,15 +756,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteTransitionRouteGroupRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteTransitionRouteGroup = stubSimpleCall( undefined, @@ -747,11 +771,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { client.deleteTransitionRouteGroup(request), expectedError ); - assert( - (client.innerApiCalls.deleteTransitionRouteGroup as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteTransitionRouteGroup as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteTransitionRouteGroup with closed client', async () => { @@ -764,7 +791,11 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteTransitionRouteGroupRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue( + 'DeleteTransitionRouteGroupRequest', + ['name'] + ); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects( @@ -785,15 +816,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() @@ -809,11 +837,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { stubSimpleCall(expectedResponse); const [response] = await client.listTransitionRouteGroups(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTransitionRouteGroups as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTransitionRouteGroups without error using callback', async () => { @@ -826,15 +857,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() @@ -867,11 +895,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listTransitionRouteGroups as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTransitionRouteGroups with error', async () => { @@ -884,15 +915,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listTransitionRouteGroups = stubSimpleCall( undefined, @@ -902,11 +930,14 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { client.listTransitionRouteGroups(request), expectedError ); - assert( - (client.innerApiCalls.listTransitionRouteGroups as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listTransitionRouteGroups as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listTransitionRouteGroupsStream without error', async () => { @@ -919,8 +950,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() @@ -963,12 +998,15 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTransitionRouteGroups, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -982,8 +1020,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTransitionRouteGroups.createStream = stubPageStreamingCall(undefined, expectedError); @@ -1015,12 +1057,15 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listTransitionRouteGroups, request) ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1034,8 +1079,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.TransitionRouteGroup() @@ -1063,12 +1112,15 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1082,8 +1134,12 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListTransitionRouteGroupsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue( + 'ListTransitionRouteGroupsRequest', + ['parent'] + ); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listTransitionRouteGroups.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1102,12 +1158,15 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.descriptors.page.listTransitionRouteGroups .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1262,12 +1321,15 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1299,12 +1361,15 @@ describe('v3beta1.TransitionRouteGroupsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_versions_v3.ts b/test/gapic_versions_v3.ts index babf1600..b61f0173 100644 --- a/test/gapic_versions_v3.ts +++ b/test/gapic_versions_v3.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,26 +272,23 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() ); client.innerApiCalls.getVersion = stubSimpleCall(expectedResponse); const [response] = await client.getVersion(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVersion without error using callback', async () => { @@ -288,15 +300,9 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() ); @@ -319,11 +325,14 @@ describe('v3.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVersion with error', async () => { @@ -335,26 +344,23 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getVersion = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getVersion(request), expectedError); - assert( - (client.innerApiCalls.getVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVersion with closed client', async () => { @@ -366,7 +372,8 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetVersionRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getVersion(request), expectedError); @@ -383,27 +390,27 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; - const expectedHeaderRequestParams = 'version.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; + const expectedHeaderRequestParams = `version.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() ); client.innerApiCalls.updateVersion = stubSimpleCall(expectedResponse); const [response] = await client.updateVersion(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateVersion without error using callback', async () => { @@ -415,16 +422,13 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; - const expectedHeaderRequestParams = 'version.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; + const expectedHeaderRequestParams = `version.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() ); @@ -447,11 +451,14 @@ describe('v3.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateVersion with error', async () => { @@ -463,27 +470,27 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; - const expectedHeaderRequestParams = 'version.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; + const expectedHeaderRequestParams = `version.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateVersion = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateVersion(request), expectedError); - assert( - (client.innerApiCalls.updateVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateVersion with closed client', async () => { @@ -495,8 +502,12 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateVersion(request), expectedError); @@ -513,26 +524,25 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteVersion = stubSimpleCall(expectedResponse); const [response] = await client.deleteVersion(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteVersion without error using callback', async () => { @@ -544,15 +554,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -575,11 +581,14 @@ describe('v3.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteVersion with error', async () => { @@ -591,26 +600,25 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteVersion = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteVersion(request), expectedError); - assert( - (client.innerApiCalls.deleteVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteVersion with closed client', async () => { @@ -622,7 +630,10 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteVersionRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteVersion(request), expectedError); @@ -639,26 +650,25 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CompareVersionsRequest() ); - request.baseVersion = ''; - const expectedHeaderRequestParams = 'base_version='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; + const expectedHeaderRequestParams = `base_version=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CompareVersionsResponse() ); client.innerApiCalls.compareVersions = stubSimpleCall(expectedResponse); const [response] = await client.compareVersions(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.compareVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes compareVersions without error using callback', async () => { @@ -670,15 +680,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CompareVersionsRequest() ); - request.baseVersion = ''; - const expectedHeaderRequestParams = 'base_version='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; + const expectedHeaderRequestParams = `base_version=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CompareVersionsResponse() ); @@ -701,11 +707,14 @@ describe('v3.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.compareVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes compareVersions with error', async () => { @@ -717,26 +726,25 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CompareVersionsRequest() ); - request.baseVersion = ''; - const expectedHeaderRequestParams = 'base_version='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; + const expectedHeaderRequestParams = `base_version=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.compareVersions = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.compareVersions(request), expectedError); - assert( - (client.innerApiCalls.compareVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes compareVersions with closed client', async () => { @@ -748,7 +756,10 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CompareVersionsRequest() ); - request.baseVersion = ''; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.compareVersions(request), expectedError); @@ -765,15 +776,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -782,11 +789,14 @@ describe('v3.VersionsClient', () => { const [operation] = await client.createVersion(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createVersion without error using callback', async () => { @@ -798,15 +808,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -836,11 +842,14 @@ describe('v3.VersionsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createVersion with call error', async () => { @@ -852,26 +861,25 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createVersion = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createVersion(request), expectedError); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createVersion with LRO error', async () => { @@ -883,15 +891,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createVersion = stubLongRunningCall( undefined, @@ -900,11 +904,14 @@ describe('v3.VersionsClient', () => { ); const [operation] = await client.createVersion(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateVersionProgress without error', async () => { @@ -959,15 +966,9 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -975,11 +976,14 @@ describe('v3.VersionsClient', () => { const [operation] = await client.loadVersion(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes loadVersion without error using callback', async () => { @@ -991,15 +995,9 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1029,11 +1027,14 @@ describe('v3.VersionsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes loadVersion with call error', async () => { @@ -1045,26 +1046,23 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.loadVersion = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.loadVersion(request), expectedError); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes loadVersion with LRO error', async () => { @@ -1076,15 +1074,9 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.loadVersion = stubLongRunningCall( undefined, @@ -1093,11 +1085,14 @@ describe('v3.VersionsClient', () => { ); const [operation] = await client.loadVersion(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkLoadVersionProgress without error', async () => { @@ -1149,15 +1144,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() @@ -1172,11 +1163,14 @@ describe('v3.VersionsClient', () => { client.innerApiCalls.listVersions = stubSimpleCall(expectedResponse); const [response] = await client.listVersions(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listVersions without error using callback', async () => { @@ -1188,15 +1182,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() @@ -1227,11 +1217,14 @@ describe('v3.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listVersions with error', async () => { @@ -1243,26 +1236,25 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listVersions = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listVersions(request), expectedError); - assert( - (client.innerApiCalls.listVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listVersionsStream without error', async () => { @@ -1274,8 +1266,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() @@ -1312,11 +1307,12 @@ describe('v3.VersionsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listVersions, request) ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1329,8 +1325,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listVersions.createStream = stubPageStreamingCall( undefined, @@ -1358,11 +1357,12 @@ describe('v3.VersionsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listVersions, request) ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1375,8 +1375,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Version() @@ -1402,11 +1405,12 @@ describe('v3.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1419,8 +1423,11 @@ describe('v3.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listVersions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1437,11 +1444,12 @@ describe('v3.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1592,12 +1600,15 @@ describe('v3.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1628,12 +1639,15 @@ describe('v3.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_versions_v3beta1.ts b/test/gapic_versions_v3beta1.ts index bf158d22..862aebcc 100644 --- a/test/gapic_versions_v3beta1.ts +++ b/test/gapic_versions_v3beta1.ts @@ -32,6 +32,21 @@ import { LocationProtos, } 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 @@ -257,26 +272,23 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() ); client.innerApiCalls.getVersion = stubSimpleCall(expectedResponse); const [response] = await client.getVersion(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVersion without error using callback', async () => { @@ -288,15 +300,9 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() ); @@ -319,11 +325,14 @@ describe('v3beta1.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVersion with error', async () => { @@ -335,26 +344,23 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getVersion = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getVersion(request), expectedError); - assert( - (client.innerApiCalls.getVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getVersion with closed client', async () => { @@ -366,7 +372,8 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetVersionRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetVersionRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getVersion(request), expectedError); @@ -383,27 +390,27 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; - const expectedHeaderRequestParams = 'version.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; + const expectedHeaderRequestParams = `version.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() ); client.innerApiCalls.updateVersion = stubSimpleCall(expectedResponse); const [response] = await client.updateVersion(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateVersion without error using callback', async () => { @@ -415,16 +422,13 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; - const expectedHeaderRequestParams = 'version.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; + const expectedHeaderRequestParams = `version.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() ); @@ -447,11 +451,14 @@ describe('v3beta1.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateVersion with error', async () => { @@ -463,27 +470,27 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; - const expectedHeaderRequestParams = 'version.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; + const expectedHeaderRequestParams = `version.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateVersion = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateVersion(request), expectedError); - assert( - (client.innerApiCalls.updateVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateVersion with closed client', async () => { @@ -495,8 +502,12 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateVersionRequest() ); - request.version = {}; - request.version.name = ''; + request.version ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateVersionRequest', [ + 'version', + 'name', + ]); + request.version.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateVersion(request), expectedError); @@ -513,26 +524,25 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteVersion = stubSimpleCall(expectedResponse); const [response] = await client.deleteVersion(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteVersion without error using callback', async () => { @@ -544,15 +554,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -575,11 +581,14 @@ describe('v3beta1.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteVersion with error', async () => { @@ -591,26 +600,25 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteVersion = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteVersion(request), expectedError); - assert( - (client.innerApiCalls.deleteVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteVersion with closed client', async () => { @@ -622,7 +630,10 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteVersionRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteVersionRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteVersion(request), expectedError); @@ -639,26 +650,25 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CompareVersionsRequest() ); - request.baseVersion = ''; - const expectedHeaderRequestParams = 'base_version='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; + const expectedHeaderRequestParams = `base_version=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CompareVersionsResponse() ); client.innerApiCalls.compareVersions = stubSimpleCall(expectedResponse); const [response] = await client.compareVersions(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.compareVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes compareVersions without error using callback', async () => { @@ -670,15 +680,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CompareVersionsRequest() ); - request.baseVersion = ''; - const expectedHeaderRequestParams = 'base_version='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; + const expectedHeaderRequestParams = `base_version=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CompareVersionsResponse() ); @@ -701,11 +707,14 @@ describe('v3beta1.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.compareVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes compareVersions with error', async () => { @@ -717,26 +726,25 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CompareVersionsRequest() ); - request.baseVersion = ''; - const expectedHeaderRequestParams = 'base_version='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; + const expectedHeaderRequestParams = `base_version=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.compareVersions = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.compareVersions(request), expectedError); - assert( - (client.innerApiCalls.compareVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.compareVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes compareVersions with closed client', async () => { @@ -748,7 +756,10 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CompareVersionsRequest() ); - request.baseVersion = ''; + const defaultValue1 = getTypeDefaultValue('CompareVersionsRequest', [ + 'baseVersion', + ]); + request.baseVersion = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.compareVersions(request), expectedError); @@ -765,15 +776,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -782,11 +789,14 @@ describe('v3beta1.VersionsClient', () => { const [operation] = await client.createVersion(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createVersion without error using callback', async () => { @@ -798,15 +808,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -836,11 +842,14 @@ describe('v3beta1.VersionsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createVersion with call error', async () => { @@ -852,26 +861,25 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createVersion = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.createVersion(request), expectedError); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createVersion with LRO error', async () => { @@ -883,15 +891,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateVersionRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateVersionRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createVersion = stubLongRunningCall( undefined, @@ -900,11 +904,14 @@ describe('v3beta1.VersionsClient', () => { ); const [operation] = await client.createVersion(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.createVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkCreateVersionProgress without error', async () => { @@ -959,15 +966,9 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -975,11 +976,14 @@ describe('v3beta1.VersionsClient', () => { const [operation] = await client.loadVersion(request); const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes loadVersion without error using callback', async () => { @@ -991,15 +995,9 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.longrunning.Operation() ); @@ -1029,11 +1027,14 @@ describe('v3beta1.VersionsClient', () => { >; const [response] = await operation.promise(); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes loadVersion with call error', async () => { @@ -1045,26 +1046,23 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.loadVersion = stubLongRunningCall( undefined, expectedError ); await assert.rejects(client.loadVersion(request), expectedError); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes loadVersion with LRO error', async () => { @@ -1076,15 +1074,9 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.LoadVersionRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('LoadVersionRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.loadVersion = stubLongRunningCall( undefined, @@ -1093,11 +1085,14 @@ describe('v3beta1.VersionsClient', () => { ); const [operation] = await client.loadVersion(request); await assert.rejects(operation.promise(), expectedError); - assert( - (client.innerApiCalls.loadVersion as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.loadVersion as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes checkLoadVersionProgress without error', async () => { @@ -1149,15 +1144,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() @@ -1172,11 +1163,14 @@ describe('v3beta1.VersionsClient', () => { client.innerApiCalls.listVersions = stubSimpleCall(expectedResponse); const [response] = await client.listVersions(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listVersions without error using callback', async () => { @@ -1188,15 +1182,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() @@ -1227,11 +1217,14 @@ describe('v3beta1.VersionsClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listVersions with error', async () => { @@ -1243,26 +1236,25 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listVersions = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listVersions(request), expectedError); - assert( - (client.innerApiCalls.listVersions as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listVersions as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listVersionsStream without error', async () => { @@ -1274,8 +1266,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() @@ -1313,11 +1308,12 @@ describe('v3beta1.VersionsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listVersions, request) ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1330,8 +1326,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listVersions.createStream = stubPageStreamingCall( undefined, @@ -1360,11 +1359,12 @@ describe('v3beta1.VersionsClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listVersions, request) ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1377,8 +1377,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Version() @@ -1405,11 +1408,12 @@ describe('v3beta1.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1422,8 +1426,11 @@ describe('v3beta1.VersionsClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListVersionsRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListVersionsRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listVersions.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1441,11 +1448,12 @@ describe('v3beta1.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listVersions.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listVersions.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1596,12 +1604,15 @@ describe('v3beta1.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1632,12 +1643,15 @@ describe('v3beta1.VersionsClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_webhooks_v3.ts b/test/gapic_webhooks_v3.ts index bfd99703..b079b20c 100644 --- a/test/gapic_webhooks_v3.ts +++ b/test/gapic_webhooks_v3.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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,23 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() ); client.innerApiCalls.getWebhook = stubSimpleCall(expectedResponse); const [response] = await client.getWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWebhook without error using callback', async () => { @@ -251,15 +263,9 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() ); @@ -282,11 +288,14 @@ describe('v3.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWebhook with error', async () => { @@ -298,26 +307,23 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getWebhook(request), expectedError); - assert( - (client.innerApiCalls.getWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWebhook with closed client', async () => { @@ -329,7 +335,8 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.GetWebhookRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getWebhook(request), expectedError); @@ -346,26 +353,25 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateWebhookRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() ); client.innerApiCalls.createWebhook = stubSimpleCall(expectedResponse); const [response] = await client.createWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWebhook without error using callback', async () => { @@ -377,15 +383,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateWebhookRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() ); @@ -408,11 +410,14 @@ describe('v3.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWebhook with error', async () => { @@ -424,26 +429,25 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateWebhookRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createWebhook(request), expectedError); - assert( - (client.innerApiCalls.createWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWebhook with closed client', async () => { @@ -455,7 +459,10 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.CreateWebhookRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createWebhook(request), expectedError); @@ -472,27 +479,27 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; - const expectedHeaderRequestParams = 'webhook.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; + const expectedHeaderRequestParams = `webhook.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() ); client.innerApiCalls.updateWebhook = stubSimpleCall(expectedResponse); const [response] = await client.updateWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWebhook without error using callback', async () => { @@ -504,16 +511,13 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; - const expectedHeaderRequestParams = 'webhook.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; + const expectedHeaderRequestParams = `webhook.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() ); @@ -536,11 +540,14 @@ describe('v3.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWebhook with error', async () => { @@ -552,27 +559,27 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; - const expectedHeaderRequestParams = 'webhook.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; + const expectedHeaderRequestParams = `webhook.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateWebhook(request), expectedError); - assert( - (client.innerApiCalls.updateWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWebhook with closed client', async () => { @@ -584,8 +591,12 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateWebhook(request), expectedError); @@ -602,26 +613,25 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteWebhook = stubSimpleCall(expectedResponse); const [response] = await client.deleteWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWebhook without error using callback', async () => { @@ -633,15 +643,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -664,11 +670,14 @@ describe('v3.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWebhook with error', async () => { @@ -680,26 +689,25 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteWebhook(request), expectedError); - assert( - (client.innerApiCalls.deleteWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWebhook with closed client', async () => { @@ -711,7 +719,10 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.DeleteWebhookRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteWebhook(request), expectedError); @@ -728,15 +739,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() @@ -751,11 +758,14 @@ describe('v3.WebhooksClient', () => { client.innerApiCalls.listWebhooks = stubSimpleCall(expectedResponse); const [response] = await client.listWebhooks(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listWebhooks as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWebhooks without error using callback', async () => { @@ -767,15 +777,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() @@ -806,11 +812,14 @@ describe('v3.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listWebhooks as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWebhooks with error', async () => { @@ -822,26 +831,25 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listWebhooks = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listWebhooks(request), expectedError); - assert( - (client.innerApiCalls.listWebhooks as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWebhooksStream without error', async () => { @@ -853,8 +861,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() @@ -891,11 +902,12 @@ describe('v3.WebhooksClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listWebhooks, request) ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -908,8 +920,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listWebhooks.createStream = stubPageStreamingCall( undefined, @@ -937,11 +952,12 @@ describe('v3.WebhooksClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listWebhooks, request) ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -954,8 +970,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.Webhook() @@ -981,11 +1000,12 @@ describe('v3.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -998,8 +1018,11 @@ describe('v3.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listWebhooks.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1016,11 +1039,12 @@ describe('v3.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1171,12 +1195,15 @@ describe('v3.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1207,12 +1234,15 @@ describe('v3.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); diff --git a/test/gapic_webhooks_v3beta1.ts b/test/gapic_webhooks_v3beta1.ts index e9d1f7a1..f60ee570 100644 --- a/test/gapic_webhooks_v3beta1.ts +++ b/test/gapic_webhooks_v3beta1.ts @@ -27,6 +27,21 @@ import {PassThrough} from 'stream'; import {protobuf, operationsProtos, LocationProtos} 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,23 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() ); client.innerApiCalls.getWebhook = stubSimpleCall(expectedResponse); const [response] = await client.getWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWebhook without error using callback', async () => { @@ -251,15 +263,9 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() ); @@ -282,11 +288,14 @@ describe('v3beta1.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.getWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWebhook with error', async () => { @@ -298,26 +307,23 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.getWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.getWebhook(request), expectedError); - assert( - (client.innerApiCalls.getWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.getWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes getWebhook with closed client', async () => { @@ -329,7 +335,8 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.GetWebhookRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('GetWebhookRequest', ['name']); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.getWebhook(request), expectedError); @@ -346,26 +353,25 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateWebhookRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() ); client.innerApiCalls.createWebhook = stubSimpleCall(expectedResponse); const [response] = await client.createWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWebhook without error using callback', async () => { @@ -377,15 +383,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateWebhookRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() ); @@ -408,11 +410,14 @@ describe('v3beta1.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.createWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWebhook with error', async () => { @@ -424,26 +429,25 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateWebhookRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.createWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.createWebhook(request), expectedError); - assert( - (client.innerApiCalls.createWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.createWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes createWebhook with closed client', async () => { @@ -455,7 +459,10 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.CreateWebhookRequest() ); - request.parent = ''; + const defaultValue1 = getTypeDefaultValue('CreateWebhookRequest', [ + 'parent', + ]); + request.parent = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.createWebhook(request), expectedError); @@ -472,27 +479,27 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; - const expectedHeaderRequestParams = 'webhook.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; + const expectedHeaderRequestParams = `webhook.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() ); client.innerApiCalls.updateWebhook = stubSimpleCall(expectedResponse); const [response] = await client.updateWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWebhook without error using callback', async () => { @@ -504,16 +511,13 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; - const expectedHeaderRequestParams = 'webhook.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; + const expectedHeaderRequestParams = `webhook.name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() ); @@ -536,11 +540,14 @@ describe('v3beta1.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.updateWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWebhook with error', async () => { @@ -552,27 +559,27 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; - const expectedHeaderRequestParams = 'webhook.name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; + const expectedHeaderRequestParams = `webhook.name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.updateWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.updateWebhook(request), expectedError); - assert( - (client.innerApiCalls.updateWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.updateWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes updateWebhook with closed client', async () => { @@ -584,8 +591,12 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.UpdateWebhookRequest() ); - request.webhook = {}; - request.webhook.name = ''; + request.webhook ??= {}; + const defaultValue1 = getTypeDefaultValue('UpdateWebhookRequest', [ + 'webhook', + 'name', + ]); + request.webhook.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.updateWebhook(request), expectedError); @@ -602,26 +613,25 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); client.innerApiCalls.deleteWebhook = stubSimpleCall(expectedResponse); const [response] = await client.deleteWebhook(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWebhook without error using callback', async () => { @@ -633,15 +643,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); @@ -664,11 +670,14 @@ describe('v3beta1.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.deleteWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWebhook with error', async () => { @@ -680,26 +689,25 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteWebhookRequest() ); - request.name = ''; - const expectedHeaderRequestParams = 'name='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.deleteWebhook = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.deleteWebhook(request), expectedError); - assert( - (client.innerApiCalls.deleteWebhook as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.deleteWebhook as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes deleteWebhook with closed client', async () => { @@ -711,7 +719,10 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.DeleteWebhookRequest() ); - request.name = ''; + const defaultValue1 = getTypeDefaultValue('DeleteWebhookRequest', [ + 'name', + ]); + request.name = defaultValue1; const expectedError = new Error('The client has already been closed.'); client.close(); await assert.rejects(client.deleteWebhook(request), expectedError); @@ -728,15 +739,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() @@ -751,11 +758,14 @@ describe('v3beta1.WebhooksClient', () => { client.innerApiCalls.listWebhooks = stubSimpleCall(expectedResponse); const [response] = await client.listWebhooks(request); assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listWebhooks as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWebhooks without error using callback', async () => { @@ -767,15 +777,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() @@ -806,11 +812,14 @@ describe('v3beta1.WebhooksClient', () => { }); const response = await promise; assert.deepStrictEqual(response, expectedResponse); - assert( - (client.innerApiCalls.listWebhooks as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions /*, callback defined above */) - ); + const actualRequest = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWebhooks with error', async () => { @@ -822,26 +831,25 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.innerApiCalls.listWebhooks = stubSimpleCall( undefined, expectedError ); await assert.rejects(client.listWebhooks(request), expectedError); - assert( - (client.innerApiCalls.listWebhooks as SinonStub) - .getCall(0) - .calledWith(request, expectedOptions, undefined) - ); + const actualRequest = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.listWebhooks as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); }); it('invokes listWebhooksStream without error', async () => { @@ -853,8 +861,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() @@ -892,11 +903,12 @@ describe('v3beta1.WebhooksClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listWebhooks, request) ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -909,8 +921,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listWebhooks.createStream = stubPageStreamingCall( undefined, @@ -939,11 +954,12 @@ describe('v3beta1.WebhooksClient', () => { .getCall(0) .calledWith(client.innerApiCalls.listWebhooks, request) ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.createStream as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.createStream as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -956,8 +972,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedResponse = [ generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.Webhook() @@ -984,11 +1003,12 @@ describe('v3beta1.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); @@ -1001,8 +1021,11 @@ describe('v3beta1.WebhooksClient', () => { const request = generateSampleMessage( new protos.google.cloud.dialogflow.cx.v3beta1.ListWebhooksRequest() ); - request.parent = ''; - const expectedHeaderRequestParams = 'parent='; + const defaultValue1 = getTypeDefaultValue('ListWebhooksRequest', [ + 'parent', + ]); + request.parent = defaultValue1; + const expectedHeaderRequestParams = `parent=${defaultValue1}`; const expectedError = new Error('expected'); client.descriptors.page.listWebhooks.asyncIterate = stubAsyncIterationCall(undefined, expectedError); @@ -1020,11 +1043,12 @@ describe('v3beta1.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( - ( - client.descriptors.page.listWebhooks.asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + assert( + (client.descriptors.page.listWebhooks.asyncIterate as SinonStub) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); }); @@ -1175,12 +1199,15 @@ describe('v3beta1.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); it('uses async iteration with listLocations with error', async () => { @@ -1211,12 +1238,15 @@ describe('v3beta1.WebhooksClient', () => { ).getCall(0).args[1], request ); - assert.strictEqual( + assert( ( client.locationsClient.descriptors.page.listLocations .asyncIterate as SinonStub - ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams + ) + .getCall(0) + .args[2].otherArgs.headers['x-goog-request-params'].includes( + expectedHeaderRequestParams + ) ); }); });