Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/v1alpha/alpha_analytics_data_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export class AlphaAnalyticsDataClient {
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
this._gaxModule.routingHeader.fromParams({
property: request.property || '',
property: request.property ?? '',
});
this.initialize();
return this.innerApiCalls.runFunnelReport(request, options, callback);
Expand Down
14 changes: 7 additions & 7 deletions src/v1beta/beta_analytics_data_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export class BetaAnalyticsDataClient {
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
this._gaxModule.routingHeader.fromParams({
property: request.property || '',
property: request.property ?? '',
});
this.initialize();
return this.innerApiCalls.runReport(request, options, callback);
Expand Down Expand Up @@ -613,7 +613,7 @@ export class BetaAnalyticsDataClient {
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
this._gaxModule.routingHeader.fromParams({
property: request.property || '',
property: request.property ?? '',
});
this.initialize();
return this.innerApiCalls.runPivotReport(request, options, callback);
Expand Down Expand Up @@ -716,7 +716,7 @@ export class BetaAnalyticsDataClient {
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
this._gaxModule.routingHeader.fromParams({
property: request.property || '',
property: request.property ?? '',
});
this.initialize();
return this.innerApiCalls.batchRunReports(request, options, callback);
Expand Down Expand Up @@ -825,7 +825,7 @@ export class BetaAnalyticsDataClient {
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
this._gaxModule.routingHeader.fromParams({
property: request.property || '',
property: request.property ?? '',
});
this.initialize();
return this.innerApiCalls.batchRunPivotReports(request, options, callback);
Expand Down Expand Up @@ -935,7 +935,7 @@ export class BetaAnalyticsDataClient {
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.getMetadata(request, options, callback);
Expand Down Expand Up @@ -1068,7 +1068,7 @@ export class BetaAnalyticsDataClient {
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
this._gaxModule.routingHeader.fromParams({
property: request.property || '',
property: request.property ?? '',
});
this.initialize();
return this.innerApiCalls.runRealtimeReport(request, options, callback);
Expand Down Expand Up @@ -1199,7 +1199,7 @@ export class BetaAnalyticsDataClient {
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers['x-goog-request-params'] =
this._gaxModule.routingHeader.fromParams({
property: request.property || '',
property: request.property ?? '',
});
this.initialize();
return this.innerApiCalls.checkCompatibility(request, options, callback);
Expand Down
101 changes: 58 additions & 43 deletions test/gapic_alpha_analytics_data_v1alpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ import * as alphaanalyticsdataModule from '../src';

import {protobuf} from 'google-gax';

// Dynamically loaded proto JSON is needed to get the type information
// to fill in default values for request objects
const root = protobuf.Root.fromJSON(
require('../protos/protos.json')
).resolveAll();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getTypeDefaultValue(typeName: string, fields: string[]) {
let type = root.lookupType(typeName) as protobuf.Type;
for (const field of fields.slice(0, -1)) {
type = type.fields[field]?.resolvedType as protobuf.Type;
}
return type.fields[fields[fields.length - 1]]?.defaultValue;
}

function generateSampleMessage<T extends object>(instance: T) {
const filledObject = (
instance.constructor as typeof protobuf.Message
Expand Down Expand Up @@ -168,26 +183,25 @@ describe('v1alpha.AlphaAnalyticsDataClient', () => {
const request = generateSampleMessage(
new protos.google.analytics.data.v1alpha.RunFunnelReportRequest()
);
request.property = '';
const expectedHeaderRequestParams = 'property=';
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const defaultValue1 = getTypeDefaultValue('RunFunnelReportRequest', [
'property',
]);
request.property = defaultValue1;
const expectedHeaderRequestParams = `property=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.analytics.data.v1alpha.RunFunnelReportResponse()
);
client.innerApiCalls.runFunnelReport = stubSimpleCall(expectedResponse);
const [response] = await client.runFunnelReport(request);
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.runFunnelReport as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
const actualRequest = (
client.innerApiCalls.runFunnelReport as SinonStub
).getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (
client.innerApiCalls.runFunnelReport as SinonStub
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes runFunnelReport without error using callback', async () => {
Expand All @@ -200,15 +214,11 @@ describe('v1alpha.AlphaAnalyticsDataClient', () => {
const request = generateSampleMessage(
new protos.google.analytics.data.v1alpha.RunFunnelReportRequest()
);
request.property = '';
const expectedHeaderRequestParams = 'property=';
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const defaultValue1 = getTypeDefaultValue('RunFunnelReportRequest', [
'property',
]);
request.property = defaultValue1;
const expectedHeaderRequestParams = `property=${defaultValue1}`;
const expectedResponse = generateSampleMessage(
new protos.google.analytics.data.v1alpha.RunFunnelReportResponse()
);
Expand All @@ -231,11 +241,14 @@ describe('v1alpha.AlphaAnalyticsDataClient', () => {
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert(
(client.innerApiCalls.runFunnelReport as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions /*, callback defined above */)
);
const actualRequest = (
client.innerApiCalls.runFunnelReport as SinonStub
).getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (
client.innerApiCalls.runFunnelReport as SinonStub
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes runFunnelReport with error', async () => {
Expand All @@ -248,26 +261,25 @@ describe('v1alpha.AlphaAnalyticsDataClient', () => {
const request = generateSampleMessage(
new protos.google.analytics.data.v1alpha.RunFunnelReportRequest()
);
request.property = '';
const expectedHeaderRequestParams = 'property=';
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const defaultValue1 = getTypeDefaultValue('RunFunnelReportRequest', [
'property',
]);
request.property = defaultValue1;
const expectedHeaderRequestParams = `property=${defaultValue1}`;
const expectedError = new Error('expected');
client.innerApiCalls.runFunnelReport = stubSimpleCall(
undefined,
expectedError
);
await assert.rejects(client.runFunnelReport(request), expectedError);
assert(
(client.innerApiCalls.runFunnelReport as SinonStub)
.getCall(0)
.calledWith(request, expectedOptions, undefined)
);
const actualRequest = (
client.innerApiCalls.runFunnelReport as SinonStub
).getCall(0).args[0];
assert.deepStrictEqual(actualRequest, request);
const actualHeaderRequestParams = (
client.innerApiCalls.runFunnelReport as SinonStub
).getCall(0).args[1].otherArgs.headers['x-goog-request-params'];
assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams));
});

it('invokes runFunnelReport with closed client', async () => {
Expand All @@ -280,7 +292,10 @@ describe('v1alpha.AlphaAnalyticsDataClient', () => {
const request = generateSampleMessage(
new protos.google.analytics.data.v1alpha.RunFunnelReportRequest()
);
request.property = '';
const defaultValue1 = getTypeDefaultValue('RunFunnelReportRequest', [
'property',
]);
request.property = defaultValue1;
const expectedError = new Error('The client has already been closed.');
client.close();
await assert.rejects(client.runFunnelReport(request), expectedError);
Expand Down
Loading