Skip to content

Commit

Permalink
noImplicitAny for IAM test file
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen Kumar Singh committed Mar 1, 2019
1 parent cbb60c9 commit d55fd72
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions test/iam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,29 @@ import * as promisify from '@google-cloud/promisify';
import * as assert from 'assert';
import * as proxyquire from 'proxyquire';

import {PubSub, RequestConfig} from '../src';
import * as iamTypes from '../src/iam';
import * as util from '../src/util';

let promisified = false;
const fakePromisify = Object.assign({}, promisify, {
// tslint:disable-next-line variable-name
promisifyAll(Class) {
promisifyAll(Class: typeof iamTypes.IAM) {
if (Class.name === 'IAM') {
promisified = true;
}
},
});

describe('IAM', () => {
let IAM;
let iam;
let IAM: typeof iamTypes.IAM;
let iam: iamTypes.IAM;

const PUBSUB = {
options: {},
Promise: {},
request: util.noop,
};
} as {} as PubSub;
const ID = 'id';

before(() => {
Expand All @@ -64,12 +66,12 @@ describe('IAM', () => {
const fakeRequest = () => {};
const fakePubsub = {
request: {
bind(context) {
bind(context: PubSub) {
assert.strictEqual(context, fakePubsub);
return fakeRequest;
},
},
};
} as {} as PubSub;
const iam = new IAM(fakePubsub, ID);

assert.strictEqual(iam.request, fakeRequest);
Expand All @@ -87,9 +89,10 @@ describe('IAM', () => {
describe('getPolicy', () => {
it('should make the correct API request', done => {
iam.request = (config, callback) => {
const reqOpts = {resource: iam.id};
assert.strictEqual(config.client, 'SubscriberClient');
assert.strictEqual(config.method, 'getIamPolicy');
assert.strictEqual(config.reqOpts.resource, iam.id);
assert.deepStrictEqual(config.reqOpts, reqOpts);

callback(); // done()
};
Expand All @@ -110,20 +113,21 @@ describe('IAM', () => {
});

describe('setPolicy', () => {
const policy = {etag: 'ACAB'};
const policy = {etag: 'ACAB', bindings: []} as iamTypes.Policy;

it('should throw an error if a policy is not supplied', () => {
assert.throws(() => {
iam.setPolicy(util.noop);
// tslint:disable-next-line no-any
(iam as any).setPolicy(util.noop);
}, /A policy object is required\./);
});

it('should make the correct API request', done => {
iam.request = (config, callback) => {
const reqOpts = {resource: iam.id, policy};
assert.strictEqual(config.client, 'SubscriberClient');
assert.strictEqual(config.method, 'setIamPolicy');
assert.strictEqual(config.reqOpts.resource, iam.id);
assert.strictEqual(config.reqOpts.policy, policy);
assert.deepStrictEqual(config.reqOpts, reqOpts);

callback(); // done()
};
Expand All @@ -134,7 +138,7 @@ describe('IAM', () => {
it('should accept gax options', done => {
const gaxOpts = {};

iam.request = config => {
iam.request = (config: RequestConfig) => {
assert.strictEqual(config.gaxOpts, gaxOpts);
done();
};
Expand All @@ -146,18 +150,19 @@ describe('IAM', () => {
describe('testPermissions', () => {
it('should throw an error if permissions are missing', () => {
assert.throws(() => {
iam.testPermissions(util.noop);
// tslint:disable-next-line no-any
(iam as any).testPermissions(util.noop);
}, /Permissions are required\./);
});

it('should make the correct API request', done => {
const permissions = 'storage.bucket.list';
const reqOpts = {resource: iam.id, permissions: [permissions]};

iam.request = config => {
assert.strictEqual(config.client, 'SubscriberClient');
assert.strictEqual(config.method, 'testIamPermissions');
assert.strictEqual(config.reqOpts.resource, iam.id);
assert.deepStrictEqual(config.reqOpts.permissions, [permissions]);
assert.deepStrictEqual(config.reqOpts, reqOpts);

done();
};
Expand All @@ -182,7 +187,7 @@ describe('IAM', () => {
const error = new Error('Error.');
const apiResponse = {};

iam.request = (config, callback) => {
iam.request = (config, callback: Function) => {
callback(error, apiResponse);
};

Expand All @@ -200,7 +205,7 @@ describe('IAM', () => {
permissions: ['storage.bucket.consume'],
};

iam.request = (config, callback) => {
iam.request = (config, callback: Function) => {
callback(null, apiResponse);
};

Expand Down

0 comments on commit d55fd72

Please sign in to comment.