Skip to content

Commit

Permalink
chore: clean up the tests (#1229)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Jul 9, 2018
1 parent 2ed9ed1 commit 21e03c8
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -24,7 +24,7 @@ clean:
gts clean

coverage: build
nyc --cache mocha build/test -t 10000 -S -R spec --require intelli-espower-loader
nyc --cache mocha build/test -t 10000 -S -R spec
nyc report --reporter=html

docs:
Expand Down
111 changes: 80 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -105,13 +105,15 @@
"@types/tmp": "^0.0.33",
"@types/url-template": "^2.0.28",
"@types/uuid": "^3.4.3",
"assert-rejects": "^0.1.1",
"axios": "^0.18.0",
"clang-format": "^1.2.3",
"codecov": "^3.0.2",
"copyfiles": "^2.0.0",
"express": "^4.16.3",
"gh-pages": "^1.1.0",
"gts": "^0.7.1",
"hard-rejection": "^1.0.0",
"intelli-espower-loader": "^1.0.1",
"js-green-licenses": "^0.5.0",
"minimist": "^1.2.0",
Expand Down
4 changes: 4 additions & 0 deletions test/mocha.opts
@@ -0,0 +1,4 @@
--require hard-rejection/register
--require intelli-espower-loader
--require source-map-support/register
--timeout 10000
1 change: 0 additions & 1 deletion test/test.apikey.ts
Expand Up @@ -16,7 +16,6 @@ import {OAuth2Client} from 'google-auth-library';
import nock from 'nock';

import {drive_v2, GoogleApis, urlshortener_v1} from '../src';
import {google} from '../src';
import {APIEndpoint} from '../src/shared/src/api';

import {Utils} from './utils';
Expand Down
28 changes: 12 additions & 16 deletions test/test.auth.ts
Expand Up @@ -18,6 +18,8 @@ import {GoogleApis} from '../src';
import {APIEndpoint} from '../src/shared/src/api';
import {Utils} from './utils';

assert.rejects = require('assert-rejects');

const googleapis = new GoogleApis();

describe('JWT client', () => {
Expand Down Expand Up @@ -59,14 +61,10 @@ describe('Compute client', () => {
});
});

async function testNoTokens(
urlshortener: APIEndpoint, oauth2client: OAuth2Client) {
try {
await urlshortener.url.get({shortUrl: '123', auth: oauth2client});
assert.fail('expected to throw');
} catch (e) {
assert.equal(e.message, 'No access, refresh token or API key is set.');
}
async function testNoTokens(urlshortener: APIEndpoint, client: OAuth2Client) {
await assert.rejects(
urlshortener.url.get({shortUrl: '123', auth: client}),
/No access, refresh token or API key is set./);
}

async function testNoBearer(
Expand Down Expand Up @@ -258,22 +256,20 @@ describe('OAuth2 client', () => {
new googleapis.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
oauth2client.credentials = {access_token: 'abc', refresh_token: 'abc'};
const res = await oauth2client.revokeCredentials();
scope.done();
assert.equal(res.data.success, true);
assert.equal(JSON.stringify(oauth2client.credentials), '{}');
assert.deepEqual(oauth2client.credentials, {});
});

it('should clear credentials and return error if no access token to revoke',
async () => {
const oauth2client =
new googleapis.auth.OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
oauth2client.credentials = {refresh_token: 'abc'};
try {
const res = await oauth2client.revokeCredentials();
assert.fail('Expected to throw');
} catch (e) {
assert.equal(e, 'Error: No access token to revoke.');
}
assert.equal(JSON.stringify(oauth2client.credentials), '{}');
await assert.rejects(
oauth2client.revokeCredentials(),
/Error: No access token to revoke./);
assert.deepEqual(oauth2client.credentials, {});
});
});

Expand Down
8 changes: 2 additions & 6 deletions test/test.clients.ts
Expand Up @@ -12,19 +12,15 @@
// limitations under the License.

import assert from 'assert';
import * as fs from 'fs';
import nock from 'nock';
import * as path from 'path';
import * as url from 'url';

import {datastore_v1, GoogleApis} from '../src';
import {GoogleApis} from '../src';
import {APIEndpoint} from '../src/shared/src/api';

import {Utils} from './utils';

function createNock(qs?: string) {
const query = qs ? `?${qs}` : '';
nock('https://datastore.googleapis.com')
return nock('https://datastore.googleapis.com')
.post(`/v1/projects/test-project-id:lookup${query}`)
.reply(200);
}
Expand Down
1 change: 0 additions & 1 deletion test/test.discover.ts
Expand Up @@ -17,7 +17,6 @@ import * as path from 'path';

import {GoogleApis} from '../src';
import {APIS} from '../src/apis';
import {APIEndpoint} from '../src/shared/src/api';

describe('GoogleApis#discover', () => {
it('should get a list of supported apis', () => {
Expand Down
1 change: 0 additions & 1 deletion test/test.kitchen.ts
Expand Up @@ -15,7 +15,6 @@
*/

import * as cp from 'child_process';
import * as fs from 'fs';
import mv from 'mv';
import {ncp} from 'ncp';
import pify from 'pify';
Expand Down
4 changes: 2 additions & 2 deletions test/test.media.ts
Expand Up @@ -17,7 +17,7 @@ import nock from 'nock';
import * as path from 'path';
import pify from 'pify';

import {drive_v2, gmail_v1, GoogleApis, youtube_v3} from '../src';
import {drive_v2, gmail_v1, GoogleApis} from '../src';

import {Utils} from './utils';

Expand Down Expand Up @@ -102,7 +102,7 @@ describe('Media', () => {
const google = new GoogleApis();
const youtube = google.youtube('v3');
const progressEvents = new Array<number>();
const res = await youtube.videos.insert(
await youtube.videos.insert(
{
part: 'id,snippet',
notifySubscribers: false,
Expand Down
5 changes: 1 addition & 4 deletions test/test.options.ts
Expand Up @@ -12,11 +12,8 @@
// limitations under the License.

import assert from 'assert';
import {AxiosResponse} from 'axios';
import nock from 'nock';
import * as url from 'url';

import {drive_v2, drive_v3, GoogleApis} from '../src';
import {GoogleApis} from '../src';

import {Utils} from './utils';

Expand Down
1 change: 0 additions & 1 deletion test/test.urlshortener.v1.ts
Expand Up @@ -14,7 +14,6 @@
import assert from 'assert';
import nock from 'nock';
import * as path from 'path';
import * as url from 'url';

import {GoogleApis, urlshortener_v1} from '../src';

Expand Down
1 change: 0 additions & 1 deletion test/utils.ts
Expand Up @@ -14,7 +14,6 @@
import {AxiosResponse} from 'axios';
import * as url from 'url';
import {GoogleApis} from '../src';
import {Endpoint} from '../src/shared/src/endpoint';

export abstract class Utils {
static getQs(res: AxiosResponse) {
Expand Down

0 comments on commit 21e03c8

Please sign in to comment.