Skip to content

Commit e6175e0

Browse files
committed
Add unit tests
1 parent b3ee7c3 commit e6175e0

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

  • core/generator/gapic-generator-typescript/typescript/test/unit

core/generator/gapic-generator-typescript/typescript/test/unit/proto.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,52 @@ describe('src/schema/proto.ts', () => {
420420
assert.strictEqual(proto.services[fd.service[0].name].protoFile, fd.name);
421421
});
422422

423+
it('should calculate mixin flags accurately for duplicate methods', () => {
424+
const fd = {} as protos.google.protobuf.FileDescriptorProto;
425+
fd.service = [{} as protos.google.protobuf.ServiceDescriptorProto];
426+
fd.service[0].name = 'TestService';
427+
fd.service[0].method = [
428+
{name: 'GetIamPolicy'},
429+
{name: 'ListLocations'},
430+
] as protos.google.protobuf.MethodDescriptorProto[];
431+
432+
// Simulating mixins being enabled (non-zero value)
433+
(fd.service[0] as any).IAMPolicyMixin = 1;
434+
(fd.service[0] as any).LocationMixin = 1;
435+
436+
const options: Options = {
437+
grpcServiceConfig: {} as protos.grpc.service_config.ServiceConfig,
438+
};
439+
440+
const augmentedService = augmentService({
441+
allMessages: {},
442+
localMessages: {},
443+
packageName: 'google.showcase.v1beta1',
444+
service: fd.service[0],
445+
commentsMap: new CommentsMap([fd]),
446+
allResourceDatabase: new ResourceDatabase(),
447+
resourceDatabase: new ResourceDatabase(),
448+
options,
449+
protoFile: 'fd',
450+
});
451+
452+
assert.strictEqual(
453+
augmentedService.iamPolicyMixinFlags?.getIamPolicy,
454+
false
455+
); // Native GetIamPolicy exists
456+
assert.strictEqual(augmentedService.iamPolicyMixinFlags?.setIamPolicy, true);
457+
assert.strictEqual(
458+
augmentedService.iamPolicyMixinFlags?.testIamPermissions,
459+
true
460+
);
461+
462+
assert.strictEqual(augmentedService.locationMixinFlags?.getLocation, true);
463+
assert.strictEqual(
464+
augmentedService.locationMixinFlags?.listLocations,
465+
false
466+
); // Native ListLocations exists
467+
});
468+
423469
it('should return api version if it exists', () => {
424470
const fd = {} as protos.google.protobuf.FileDescriptorProto;
425471
fd.name = 'google/cloud/showcase/v1beta1/test.proto';

0 commit comments

Comments
 (0)