Skip to content

Commit

Permalink
feat: throw errors for missing resource ids (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop authored and JustinBeckwith committed Feb 5, 2019
1 parent 1da31b3 commit a1c9e3d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,8 @@ class Dataset extends ServiceObject {
/**
* Create a Table object.
*
* @throws {TypeError} if table ID is missing.
*
* @param {string} id The ID of the table.
* @param {object} [options] Table options.
* @param {string} [options.location] The geographic location of the table, by
Expand All @@ -639,6 +641,10 @@ class Dataset extends ServiceObject {
* const institutions = dataset.table('institution_data');
*/
table(id: string, options?: TableOptions) {
if (typeof id !== 'string') {
throw new TypeError('A table ID is required.');
}

options = extend(
{
location: this.location,
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,10 @@ export class BigQuery extends common.Service {
* const dataset = bigquery.dataset('higher_education');
*/
dataset(id: string, options?: DataSetOptions) {
if (typeof id !== 'string') {
throw new TypeError('A dataset ID is required.');
}

if (this.location) {
options = extend({location: this.location}, options);
}
Expand Down
5 changes: 5 additions & 0 deletions test/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,11 @@ describe('BigQuery/Dataset', () => {
});

describe('table', () => {
it('should throw an error if the id is missing', () => {
const expectedErr = /A table ID is required\./;
assert.throws(() => ds.table(), expectedErr);
});

it('should return a Table object', () => {
const tableId = 'tableId';
const table = ds.table(tableId);
Expand Down
5 changes: 5 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,11 @@ describe('BigQuery', () => {
describe('dataset', () => {
const DATASET_ID = 'dataset-id';

it('should throw an error if the id is missing', () => {
const expectedErr = /A dataset ID is required\./;
assert.throws(() => bq.dataset(), expectedErr);
});

it('returns a Dataset instance', () => {
const ds = bq.dataset(DATASET_ID);
assert(ds instanceof FakeDataset);
Expand Down

0 comments on commit a1c9e3d

Please sign in to comment.