diff --git a/lib/bigquery/dataset.js b/lib/bigquery/dataset.js index 87adffc797c..80d8ce9fde6 100644 --- a/lib/bigquery/dataset.js +++ b/lib/bigquery/dataset.js @@ -159,7 +159,7 @@ Dataset.prototype.delete = function(options, callback) { * * @param {function} callback - The callback function. * @param {?error} callback.err - An error returned while making this request - * @param {object} callback.metadata - The Dataset metadata + * @param {object} callback.metadata - The dataset's metadata. * @param {object} callback.apiResponse - The full API response. * * @example @@ -284,28 +284,27 @@ Dataset.prototype.query = function(options, callback) { * @param {object} metadata - Metadata to save on the Dataset. * @param {function} callback - The callback function. * @param {?error} callback.err - An error returned while making this request - * @param {object} callback.metadata - The metadata of the Dataset object. - * @param {object} callback.apiResponse - The full API response. + * @param {object} callback.apiResponse - The full API response. * * @example * var metadata = { * description: 'Information for every institution in the 2013 IPEDS universe' * }; * - * dataset.setMetadata(metadata, function(err, metadata, apiResponse) {}); + * dataset.setMetadata(metadata, function(err, apiResponse) {}); */ Dataset.prototype.setMetadata = function(metadata, callback) { var that = this; this.makeReq_('PATCH', '', null, metadata, function(err, resp) { if (err) { - callback(err, null, resp); + callback(err, resp); return; } that.metadata = resp; - callback(null, that.metadata, resp); + callback(null, resp); }); }; diff --git a/lib/bigquery/table.js b/lib/bigquery/table.js index c0a21e95026..2d4d9fc77d9 100644 --- a/lib/bigquery/table.js +++ b/lib/bigquery/table.js @@ -587,9 +587,9 @@ Table.prototype.getRows = function(options, callback) { if (resp.rows && resp.rows.length > 0 && !that.metadata.schema) { // We don't know the schema for this table yet. Do a quick stat. - that.getMetadata(function(err) { + that.getMetadata(function(err, metadata, apiResponse) { if (err) { - onComplete(err); + onComplete(err, null, null, apiResponse); return; } @@ -867,8 +867,7 @@ Table.prototype.query = function(query, callback) { * a [Table resource](http://goo.gl/sl8Dmg) for more detailed information. * @param {function} callback - The callback function. * @param {?error} callback.err - An error returned while making this request. - * @param {object} callback.metadata - The metadata of the Table. - * @param {object} callback.apiResponse - The full API response. + * @param {object} callback.apiResponse - The full API response. * * @example * var metadata = { @@ -892,13 +891,13 @@ Table.prototype.setMetadata = function(metadata, callback) { this.makeReq_('PUT', '', null, metadata, function(err, resp) { if (err) { - callback(err, null, resp); + callback(err, resp); return; } that.metadata = resp; - callback(null, that.metadata, resp); + callback(null, resp); }); }; diff --git a/lib/compute/firewall.js b/lib/compute/firewall.js index fc734fa52bc..f36fb33f6b1 100644 --- a/lib/compute/firewall.js +++ b/lib/compute/firewall.js @@ -103,7 +103,7 @@ Firewall.prototype.delete = function(callback) { * * @param {function=} callback - The callback function. * @param {?error} callback.err - An error returned while making this request - * @param {object} callback.metadata - The network's metadata. + * @param {object} callback.metadata - The firewall's metadata. * @param {object} callback.apiResponse - The full API response. * * @example diff --git a/lib/compute/snapshot.js b/lib/compute/snapshot.js index 256c1192afb..03119618960 100644 --- a/lib/compute/snapshot.js +++ b/lib/compute/snapshot.js @@ -100,7 +100,7 @@ Snapshot.prototype.delete = function(callback) { * * @param {function=} callback - The callback function. * @param {?error} callback.err - An error returned while making this request - * @param {object} callback.metadata - The zone's metadata. + * @param {object} callback.metadata - The snapshot's metadata. * @param {object} callback.apiResponse - The full API response. * * @example diff --git a/lib/datastore/dataset.js b/lib/datastore/dataset.js index c22296e4ee4..f149f740528 100644 --- a/lib/datastore/dataset.js +++ b/lib/datastore/dataset.js @@ -244,14 +244,14 @@ Dataset.prototype.createQuery = function(namespace, kind) { * * done(); * }); - * }, function(err) {}); + * }, function(err, apiResponse) {}); */ Dataset.prototype.runInTransaction = function(fn, callback) { var newTransaction = this.createTransaction_(); - newTransaction.begin_(function(err) { + newTransaction.begin_(function(err, resp) { if (err) { - callback(err); + callback(err, resp); return; } diff --git a/lib/datastore/transaction.js b/lib/datastore/transaction.js index 29a40e91ac8..cdf73daf6fa 100644 --- a/lib/datastore/transaction.js +++ b/lib/datastore/transaction.js @@ -383,15 +383,4 @@ Transaction.prototype.save = function(entities) { }); }; -/** - * mapQuery - * - * @todo Implement. - * - * @private - */ -Transaction.prototype.mapQuery = function() { - throw new Error('not yet implemented'); -}; - module.exports = Transaction; diff --git a/lib/search/index.js b/lib/search/index.js index b5caa7275eb..20ea50212eb 100644 --- a/lib/search/index.js +++ b/lib/search/index.js @@ -197,8 +197,8 @@ Search.prototype.getIndexes = function(query, callback) { var indexes = (resp.indexes || []).map(function(indexObject) { var index = self.index(indexObject.indexId); - if (is.object(resp.indexedField)) { - index.fields = resp.indexedField; + if (is.object(indexObject.indexedField)) { + index.fields = indexObject.indexedField; } return index; diff --git a/lib/storage/bucket.js b/lib/storage/bucket.js index 0a046a7e9ed..c10ed8b9d54 100644 --- a/lib/storage/bucket.js +++ b/lib/storage/bucket.js @@ -824,7 +824,6 @@ Bucket.prototype.makePublic = function(options, callback) { * @param {object} metadata - The metadata you wish to set. * @param {function=} callback - The callback function. * @param {?error} callback.err - An error returned while making this request - * @param {object} callback.metadata - The bucket's metadata. * @param {object} callback.apiResponse - The full API response. * * @example @@ -836,7 +835,7 @@ Bucket.prototype.makePublic = function(options, callback) { * mainPageSuffix: 'http://example.com', * notFoundPage: 'http://example.com/404.html' * } - * }, function(err, metadata, apiResponse) {}); + * }, function(err, apiResponse) {}); * * //- * // Enable versioning for your bucket. @@ -845,7 +844,7 @@ Bucket.prototype.makePublic = function(options, callback) { * versioning: { * enabled: true * } - * }, function(err, metadata, apiResponse) {}); + * }, function(err, apiResponse) {}); */ Bucket.prototype.setMetadata = function(metadata, callback) { var that = this; @@ -853,13 +852,13 @@ Bucket.prototype.setMetadata = function(metadata, callback) { this.makeReq_('PATCH', '', null, metadata, function(err, resp) { if (err) { - callback(err, null, resp); + callback(err, resp); return; } that.metadata = resp; - callback(null, that.metadata, resp); + callback(null, resp); }); }; diff --git a/lib/storage/file.js b/lib/storage/file.js index 3c041836460..b2cbf2aa43c 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -1264,7 +1264,6 @@ File.prototype.getSignedUrl = function(options, callback) { * @param {object} metadata - The metadata you wish to update. * @param {function=} callback - The callback function. * @param {?error} callback.err - An error returned while making this request - * @param {object} callback.metadata - The File's metadata. * @param {object} callback.apiResponse - The full API response. * * @example @@ -1274,7 +1273,7 @@ File.prototype.getSignedUrl = function(options, callback) { * my: 'custom', * properties: 'go here' * } - * }, function(err, metadata, apiResponse) {}); + * }, function(err, apiResponse) {}); * * // Assuming current metadata = { hello: 'world', unsetMe: 'will do' } * file.setMetadata({ @@ -1283,7 +1282,7 @@ File.prototype.getSignedUrl = function(options, callback) { * unsetMe: null, // will be unset (deleted). * hello: 'goodbye' // will be updated from 'hello' to 'goodbye'. * } - * }, function(err, metadata, apiResponse) { + * }, function(err, apiResponse) { * // metadata should now be { abc: '123', hello: 'goodbye' } * }); */ @@ -1300,13 +1299,13 @@ File.prototype.setMetadata = function(metadata, callback) { this.makeReq_('PATCH', path, query, metadata, function(err, resp) { if (err) { - callback(err, null, resp); + callback(err, resp); return; } that.metadata = resp; - callback(null, that.metadata, resp); + callback(null, resp); }); }; @@ -1351,13 +1350,13 @@ File.prototype.makePrivate = function(options, callback) { this.makeReq_('PATCH', path, query, metadata, function(err, resp) { if (err) { - callback(err); + callback(err, resp); return; } that.metadata = resp; - callback(null); + callback(null, resp); }); }; diff --git a/system-test/bigquery.js b/system-test/bigquery.js index e1dc45e1599..bb0594cf268 100644 --- a/system-test/bigquery.js +++ b/system-test/bigquery.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, before, after */ - 'use strict'; var assert = require('assert'); diff --git a/system-test/compute.js b/system-test/compute.js index edd2ab07031..607336bd7a9 100644 --- a/system-test/compute.js +++ b/system-test/compute.js @@ -1,3 +1,19 @@ +/** + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + 'use strict'; var assert = require('assert'); diff --git a/system-test/datastore.js b/system-test/datastore.js index 2203990b74e..d7e7fd3e649 100644 --- a/system-test/datastore.js +++ b/system-test/datastore.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, after, before */ - 'use strict'; var env = require('./env.js'); diff --git a/test/bigquery/dataset.js b/test/bigquery/dataset.js index 067893e4b91..fc7746a8c91 100644 --- a/test/bigquery/dataset.js +++ b/test/bigquery/dataset.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach */ - 'use strict'; var arrify = require('arrify'); @@ -441,13 +439,17 @@ describe('BigQuery/Dataset', function() { ds.setMetadata(METADATA, assert.ifError); }); - it('should execute callback with error', function(done) { + it('should execute callback with error & API response', function(done) { var error = new Error('Error.'); + var apiResponse = {}; + ds.makeReq_ = function(method, path, query, body, callback) { - callback(error); + callback(error, apiResponse); }; - ds.setMetadata(METADATA, function(err) { - assert.equal(err, error); + + ds.setMetadata(METADATA, function(err, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(apiResponse_, apiResponse); done(); }); }); @@ -467,16 +469,8 @@ describe('BigQuery/Dataset', function() { }); }); - it('should execute callback with metadata', function(done) { - ds.setMetadata(METADATA, function(err, metadata) { - assert.ifError(err); - assert.deepEqual(metadata, METADATA); - done(); - }); - }); - it('should execute callback with apiResponse', function(done) { - ds.setMetadata(METADATA, function(err, metadata, apiResponse) { + ds.setMetadata(METADATA, function(err, apiResponse) { assert.ifError(err); assert.deepEqual(apiResponse, METADATA); done(); diff --git a/test/bigquery/job.js b/test/bigquery/job.js index fb95520266b..1d02ca47485 100644 --- a/test/bigquery/job.js +++ b/test/bigquery/job.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach */ - 'use strict'; var assert = require('assert'); diff --git a/test/bigquery/table.js b/test/bigquery/table.js index abd58e45a94..397e415488b 100644 --- a/test/bigquery/table.js +++ b/test/bigquery/table.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach, before, after */ - 'use strict'; var arrify = require('arrify'); @@ -78,6 +76,7 @@ describe('BigQuery/Table', function() { var Table; var TABLE_ID = 'kittens'; var table; + var tableOverrides = {}; before(function() { mockery.registerMock('../storage/file', FakeFile); @@ -87,7 +86,23 @@ describe('BigQuery/Table', function() { useCleanCache: true, warnOnUnregistered: false }); + Table = require('../../lib/bigquery/table'); + + var tableCached = extend(true, {}, Table); + + // Override all util methods, allowing them to be mocked. Overrides are + // removed before each test. + Object.keys(Table).forEach(function(tableMethod) { + if (typeof Table[tableMethod] !== 'function') { + return; + } + + Table[tableMethod] = function() { + return (tableOverrides[tableMethod] || tableCached[tableMethod]) + .apply(this, arguments); + }; + }); }); after(function() { @@ -97,6 +112,7 @@ describe('BigQuery/Table', function() { beforeEach(function() { makeWritableStreamOverride = null; + tableOverrides = {}; table = new Table(DATASET, TABLE_ID); }); @@ -281,6 +297,23 @@ describe('BigQuery/Table', function() { table.createWriteStream(fileType).emit('writing'); }); + it('should format a schema', function(done) { + var expectedSchema = {}; + + tableOverrides.createSchemaFromString_ = function(string) { + assert.strictEqual(string, SCHEMA_STRING); + return expectedSchema; + }; + + makeWritableStreamOverride = function(stream, options) { + var load = options.metadata.configuration.load; + assert.deepEqual(load.schema, expectedSchema); + done(); + }; + + table.createWriteStream({ schema: SCHEMA_STRING }).emit('writing'); + }); + it('should throw if a given source format is not recognized', function() { assert.throws(function() { table.createWriteStream('zip'); @@ -620,31 +653,76 @@ describe('BigQuery/Table', function() { table.getRows(options, done); }); - it('should refresh metadata if it does not have a schema', function(done) { - // Step 0: use "Stephen" so you know who to blame for this test. - var rows = [{ f: [{ v: 'stephen' }] }]; - var schema = { fields: [{ name: 'name', type: 'string' }] }; + it('should execute callback with error & API response', function(done) { + var apiResponse = {}; + var error = new Error('Error.'); - // Step 1: makes the request. table.makeReq_ = function(method, path, query, body, callback) { - // Respond with a row, so it grabs the schema. - // Use setImmediate to let our getMetadata overwrite process. - setImmediate(callback, null, { rows: rows }); + callback(error, apiResponse); }; - table.getRows(responseHandler); - // Step 2: refreshes the metadata to pull down the schema. - table.getMetadata = function(callback) { - table.metadata = { schema: schema }; - callback(); - }; + table.getRows(function(err, rows, nextQuery, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(rows, null); + assert.strictEqual(nextQuery, null); + assert.strictEqual(apiResponse_, apiResponse); - // Step 3: execute original complete handler with schema-merged rows. - function responseHandler(err, rows) { - assert.ifError(err); - assert.deepEqual(rows, [{ name: 'stephen' }]); done(); - } + }); + }); + + describe('refreshing metadata', function() { + // Using "Stephen" so you know who to blame for these tests. + var rows = [{ f: [{ v: 'stephen' }] }]; + var schema = { fields: [{ name: 'name', type: 'string' }] }; + + beforeEach(function() { + table.makeReq_ = function(method, path, query, body, callback) { + // Respond with a row, so it grabs the schema. + // Use setImmediate to let our getMetadata overwrite process. + setImmediate(callback, null, { rows: rows }); + }; + }); + + it('should refresh', function(done) { + // Step 1: makes the request. + table.getRows(responseHandler); + + // Step 2: refreshes the metadata to pull down the schema. + table.getMetadata = function(callback) { + table.metadata = { schema: schema }; + callback(); + }; + + // Step 3: execute original complete handler with schema-merged rows. + function responseHandler(err, rows) { + assert.ifError(err); + assert.deepEqual(rows, [{ name: 'stephen' }]); + done(); + } + }); + + it('should execute callback from refreshing metadata', function(done) { + var apiResponse = {}; + var error = new Error('Error.'); + + // Step 1: makes the request. + table.getRows(responseHandler); + + // Step 2: refreshes the metadata to pull down the schema. + table.getMetadata = function(callback) { + callback(error, {}, apiResponse); + }; + + // Step 3: execute original complete handler with schema-merged rows. + function responseHandler(err, rows, nextQuery, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(rows, null); + assert.strictEqual(nextQuery, null); + assert.strictEqual(apiResponse_, apiResponse); + done(); + } + }); }); it('should return schema-merged rows', function(done) { @@ -872,31 +950,38 @@ describe('BigQuery/Table', function() { table.insert(data, done); }); - it('should execute callback', function(done) { + it('should execute callback with API response', function(done) { + var apiResponse = { insertErrors: [] }; + table.makeReq_ = function(method, path, query, body, callback) { - callback(null, { insertErrors: [] }); + callback(null, apiResponse); }; - table.insert(data, function(err, insertErrors) { + table.insert(data, function(err, insertErrors, apiResponse_) { assert.ifError(err); assert.deepEqual(insertErrors, []); + assert.strictEqual(apiResponse_, apiResponse); done(); }); }); - it('should execute callback with apiResponse', function(done) { + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + table.makeReq_ = function(method, path, query, body, callback) { - callback(null, { insertErrors: [] }); + callback(error, apiResponse); }; - table.insert(data, function(err, insertErrors, apiResponse) { - assert.ifError(err); - assert.deepEqual(apiResponse, { insertErrors: [] }); + table.insert(data, function(err, insertErrors, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(insertErrors, null); + assert.strictEqual(apiResponse_, apiResponse); done(); }); }); - it('should return errors to the callback', function(done) { + it('should return insert failures to the callback', function(done) { var row0Error = { message: 'Error.', reason: 'notFound' }; var row1Error = { message: 'Error.', reason: 'notFound' }; @@ -967,13 +1052,17 @@ describe('BigQuery/Table', function() { table.setMetadata({ schema: 'schema' }); }); - it('should execute callback with error', function(done) { + it('should execute callback with error & API response', function(done) { var error = new Error('Error.'); + var apiResponse = {}; + table.makeReq_ = function(method, path, query, body, callback) { - callback(error); + callback(error, apiResponse); }; - table.setMetadata(METADATA, function(err) { - assert.equal(err, error); + + table.setMetadata(METADATA, function(err, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(apiResponse_, apiResponse); done(); }); }); @@ -994,15 +1083,15 @@ describe('BigQuery/Table', function() { }); it('should execute callback with metadata', function(done) { - table.setMetadata(METADATA, function(err, metadata) { + table.setMetadata(METADATA, function(err, apiResponse) { assert.ifError(err); - assert.deepEqual(metadata, METADATA); + assert.deepEqual(apiResponse, METADATA); done(); }); }); it('should execute callback with apiResponse', function(done) { - table.setMetadata(METADATA, function(err, metadata, apiResponse) { + table.setMetadata(METADATA, function(err, apiResponse) { assert.ifError(err); assert.deepEqual(apiResponse, METADATA); done(); diff --git a/test/common/util.js b/test/common/util.js index e8be83bbaac..8bb83c4a933 100644 --- a/test/common/util.js +++ b/test/common/util.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach, before, after */ - 'use strict'; var assert = require('assert'); diff --git a/test/datastore/dataset.js b/test/datastore/dataset.js index 09e3f7f4e23..cbda6413d89 100644 --- a/test/datastore/dataset.js +++ b/test/datastore/dataset.js @@ -105,6 +105,25 @@ describe('Dataset', function() { ds.runInTransaction(); }); + it('should execute callback with error if one occurred', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + ds.createTransaction_ = function() { + return { + begin_: function(callback) { + callback(error, apiResponse); + } + }; + }; + + ds.runInTransaction(util.noop, function(err, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(apiResponse_, apiResponse); + done(); + }); + }); + it('should return transaction object to the callback', function(done) { var transaction = { begin_: function(callback) { diff --git a/test/datastore/entity.js b/test/datastore/entity.js index 9a73825a595..151ad57f9e8 100644 --- a/test/datastore/entity.js +++ b/test/datastore/entity.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it */ - 'use strict'; var assert = require('assert'); @@ -109,6 +107,7 @@ var queryFilterProto = { operator: 'AND' } }, + end_cursor: new Buffer('end', 'base64'), order: [], group_by: [] }; @@ -262,6 +261,12 @@ describe('isKeyComplete', function() { assert.strictEqual(entity.isKeyComplete(test.key), test.expected); }); }); + + it('should return false if there is no kind', function() { + var key = new entity.Key({ path: [ '' ] }); + + assert.strictEqual(entity.isKeyComplete(key), false); + }); }); describe('entityFromEntityProto', function() { @@ -303,6 +308,7 @@ describe('queryToQueryProto', function() { var ds = datastore.dataset({ projectId: 'project-id' }); var q = ds.createQuery('Kind1') .filter('name =', 'John') + .end('end') .hasAncestor(new entity.Key({ path: [ 'Kind2', 'somename' ] })); var proto = entity.queryToQueryProto(q); assert.deepEqual(proto, queryFilterProto); diff --git a/test/datastore/index.js b/test/datastore/index.js index e15fedb0683..be9a0541a00 100644 --- a/test/datastore/index.js +++ b/test/datastore/index.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, before, after */ - 'use strict'; var entity = { diff --git a/test/datastore/query.js b/test/datastore/query.js index 304c29ce36c..4b95f5beec2 100644 --- a/test/datastore/query.js +++ b/test/datastore/query.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it */ - 'use strict'; var assert = require('assert'); diff --git a/test/datastore/request.js b/test/datastore/request.js index 54466c768fa..cb73e7b0cc5 100644 --- a/test/datastore/request.js +++ b/test/datastore/request.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach, before, after */ - 'use strict'; var arrify = require('arrify'); @@ -424,19 +422,36 @@ describe('Request', function() { it('should save with specific method', function(done) { request.makeReq_ = function(method, req, callback) { assert.equal(method, 'commit'); + assert.equal(req.mutation.insert.length, 1); assert.equal(req.mutation.update.length, 1); - assert.equal(req.mutation.insert[0].property[0].name, 'k'); - assert.equal( - req.mutation.insert[0].property[0].value.string_value, 'v'); - assert.equal(req.mutation.update[0].property[0].name, 'k2'); - assert.equal( - req.mutation.update[0].property[0].value.string_value, 'v2'); + assert.equal(req.mutation.upsert.length, 1); + assert.equal(req.mutation.insert_auto_id.length, 1); + + var insert = req.mutation.insert[0]; + assert.strictEqual(insert.property[0].name, 'k'); + assert.strictEqual(insert.property[0].value.string_value, 'v'); + + var update = req.mutation.update[0]; + assert.strictEqual(update.property[0].name, 'k2'); + assert.strictEqual(update.property[0].value.string_value, 'v2'); + + var upsert = req.mutation.upsert[0]; + assert.strictEqual(upsert.property[0].name, 'k3'); + assert.strictEqual(upsert.property[0].value.string_value, 'v3'); + + var insertAutoId = req.mutation.insert_auto_id[0]; + assert.strictEqual(insertAutoId.property[0].name, 'k4'); + assert.strictEqual(insertAutoId.property[0].value.string_value, 'v4'); + callback(); }; + request.save([ { key: key, method: 'insert', data: { k: 'v' } }, - { key: key, method: 'update', data: { k2: 'v2' } } + { key: key, method: 'update', data: { k2: 'v2' } }, + { key: key, method: 'upsert', data: { k3: 'v3' } }, + { key: key, method: 'insert_auto_id', data: { k4: 'v4' } } ], done); }); @@ -601,7 +616,7 @@ describe('Request', function() { }; beforeEach(function() { - query = new Query(['Kind']); + query = new Query('namespace', ['Kind']); }); describe('errors', function() { @@ -672,6 +687,17 @@ describe('Request', function() { done(); }); }); + + it('should set a partition_id from a namespace', function(done) { + var namespace = 'namespace'; + + request.makeReq_ = function(method, req) { + assert.strictEqual(req.partition_id.namespace, namespace); + done(); + }; + + request.runQuery(query, assert.ifError); + }); }); describe('update', function() { @@ -715,17 +741,25 @@ describe('Request', function() { }); describe('allocateIds', function() { + var incompleteKey; + var apiResponse = { + key: [ + { path_element: [{ kind: 'Kind', id: 123 }] } + ] + }; + + beforeEach(function() { + incompleteKey = new entity.Key({ namespace: null, path: ['Kind'] }); + }); + it('should produce proper allocate IDs req protos', function(done) { request.makeReq_ = function(method, req, callback) { assert.equal(method, 'allocateIds'); assert.equal(req.key.length, 1); - callback(null, { - key: [ - { path_element: [{ kind: 'Kind', id: 123 }] } - ] - }); + + callback(null, apiResponse); }; - var incompleteKey = new entity.Key({ namespace: null, path: ['Kind'] }); + request.allocateIds(incompleteKey, 1, function(err, keys) { assert.ifError(err); var generatedKey = keys[0]; @@ -734,19 +768,29 @@ describe('Request', function() { }); }); - it('should return apiResponse in callback', function(done) { - var resp = { - key: [ - { path_element: [{ kind: 'Kind', id: 123 }] } - ] + it('should exec callback with error & API response', function(done) { + var error = new Error('Error.'); + + request.makeReq_ = function(method, req, callback) { + callback(error, apiResponse); }; + + request.allocateIds(incompleteKey, 1, function(err, keys, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(keys, null); + assert.strictEqual(apiResponse_, apiResponse); + done(); + }); + }); + + it('should return apiResponse in callback', function(done) { request.makeReq_ = function(method, req, callback) { - callback(null, resp); + callback(null, apiResponse); }; - var incompleteKey = new entity.Key({ namespace: null, path: ['Kind'] }); - request.allocateIds(incompleteKey, 1, function(err, keys, apiResponse) { + + request.allocateIds(incompleteKey, 1, function(err, keys, apiResponse_) { assert.ifError(err); - assert.deepEqual(resp, apiResponse); + assert.strictEqual(apiResponse_, apiResponse); done(); }); }); @@ -799,6 +843,19 @@ describe('Request', function() { request.makeReq_('commit', {}, util.noop); }); + it('should execute onAuthenticated with error', function(done) { + var error = new Error('Error.'); + + request.makeAuthenticatedRequest_ = function(opts, callback) { + (callback.onAuthenticated || callback)(error); + }; + + request.makeReq_('commit', {}, function(err) { + assert.strictEqual(err, error); + done(); + }); + }); + it('should send protobuf request', function(done) { var requestOptions = { mode: 'NON_TRANSACTIONAL' }; var decoded = new pb.CommitRequest(requestOptions).toBuffer(); diff --git a/test/datastore/transaction.js b/test/datastore/transaction.js index 22d3dc6c644..5a1a205a0f1 100644 --- a/test/datastore/transaction.js +++ b/test/datastore/transaction.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach, before, after */ - 'use strict'; var arrify = require('arrify'); @@ -221,6 +219,15 @@ describe('Transaction', function() { transaction.commit_(); }); + it('should skip the commit', function(done) { + transaction.skipCommit = true; + + // If called, the test will blow up. + transaction.makeReq_ = done; + + transaction.commit_(done); + }); + it('should pass error to callback', function(done) { var error = new Error('Error.'); transaction.makeReq_ = function(method, req, callback) { diff --git a/test/dns/zone.js b/test/dns/zone.js index c636f9c9d9c..be12e2036c5 100644 --- a/test/dns/zone.js +++ b/test/dns/zone.js @@ -681,6 +681,13 @@ describe('Zone', function() { done(); }); }); + + it('should not require a query', function(done) { + zone.getRecords(function(err) { + assert.strictEqual(err, error); + done(); + }); + }); }); describe('success', function() { @@ -732,6 +739,10 @@ describe('Zone', function() { done(); }); + + it('should not require a query', function(done) { + zone.getRecords(done); + }); }); describe('filtering', function() { diff --git a/test/pubsub/subscription.js b/test/pubsub/subscription.js index 32bc7b64738..9da29ab0113 100644 --- a/test/pubsub/subscription.js +++ b/test/pubsub/subscription.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach, afterEach */ - 'use strict'; var assert = require('assert'); @@ -801,19 +799,22 @@ describe('Subscription', function() { it('should decode stringified JSON to object', function() { var obj = { hi: 'there' }; var stringified = new Buffer(JSON.stringify(obj)).toString('base64'); + var attributes = {}; var msg = Subscription.formatMessage_({ ackId: 3, message: { data: stringified, - messageId: 7 + messageId: 7, + attributes: attributes } }); assert.deepEqual(msg, { ackId: 3, id: 7, - data: obj + data: obj, + attributes: attributes }); }); diff --git a/test/search/index.js b/test/search/index.js index 91200610e83..1e0cc9f7d1b 100644 --- a/test/search/index.js +++ b/test/search/index.js @@ -223,7 +223,12 @@ describe('Search', function() { }); it('should assign fields property on new Index', function(done) { - var indexObjects = [{ indexId: 'a', indexedField: 'b' }]; + var indexObjects = [ + { + indexId: 'a', + indexedField: {} + } + ]; var apiResponse = { indexes: indexObjects }; @@ -237,7 +242,7 @@ describe('Search', function() { search.getIndexes({}, function(err, indexes) { assert.ifError(err); - assert.equal(indexes[0].fields, indexObjects.indexedField); + assert.strictEqual(indexes[0].fields, indexObjects[0].indexedField); done(); }); }); diff --git a/test/storage/acl.js b/test/storage/acl.js index 7b19b60d287..43a62c1cfe2 100644 --- a/test/storage/acl.js +++ b/test/storage/acl.js @@ -14,8 +14,6 @@ * limitations under the License. */ -/*global describe, it, beforeEach */ - 'use strict'; var Acl = require('../../lib/storage/acl.js'); @@ -427,7 +425,7 @@ describe('storage/AclRoleAccessorMethods', function() { aclEntity.delete = function(options, callback) { assert.deepEqual(options, { - entity: 'user-' + userName, + entity: 'allUsers', role: role }); @@ -442,7 +440,7 @@ describe('storage/AclRoleAccessorMethods', function() { aclEntity.fakeroles.addUser(userName, next); }, function(next) { - aclEntity.fakeroles.deleteUser(userName, next); + aclEntity.fakeroles.deleteAllUsers(next); } ], done); }); diff --git a/test/storage/bucket.js b/test/storage/bucket.js index f5f44494602..bf72eb23b74 100644 --- a/test/storage/bucket.js +++ b/test/storage/bucket.js @@ -571,6 +571,24 @@ describe('Bucket', function() { }); }); + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + bucket.makeReq_ = function(method, path, query, body, callback) { + callback(error, apiResponse); + }; + + bucket.getFiles(function(err, files, nextQuery, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(files, null); + assert.strictEqual(nextQuery, null); + assert.strictEqual(apiResponse_, apiResponse); + + done(); + }); + }); + it('should populate returned File object with metadata', function(done) { var fileMetadata = { name: 'filename', @@ -642,6 +660,23 @@ describe('Bucket', function() { done(); }); }); + + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + bucket.makeReq_ = function(method, path, query, body, callback) { + callback(error, apiResponse); + }; + + bucket.getMetadata(function(err, metadata, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(metadata, null); + assert.strictEqual(apiResponse_, apiResponse); + + done(); + }); + }); }); describe('makePublic', function() { @@ -807,6 +842,22 @@ describe('Bucket', function() { }); }); + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + bucket.makeReq_ = function(method, path, query, body, callback) { + callback(error, apiResponse); + }; + + bucket.setMetadata(metadata, function(err, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(apiResponse_, apiResponse); + + done(); + }); + }); + it('should update internal metadata property', function() { bucket.makeReq_ = function(method, path, query, body, callback) { callback(null, metadata); diff --git a/test/storage/file.js b/test/storage/file.js index e30852ace40..2e36b832f7e 100644 --- a/test/storage/file.js +++ b/test/storage/file.js @@ -166,6 +166,25 @@ describe('File', function() { directoryFile.copy(newFile); }); + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + var newFile = new File(bucket, 'new-file'); + + file.makeReq_ = function(method, path, query, body, callback) { + callback(error, apiResponse); + }; + + file.copy(newFile, function(err, file, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(file, null); + assert.strictEqual(apiResponse_, apiResponse); + + done(); + }); + }); + it('should send query.sourceGeneration if File has one', function(done) { var versionedFile = new File(bucket, 'name', { generation: 1 }); var newFile = new File(bucket, 'new-file'); @@ -222,6 +241,12 @@ describe('File', function() { assertPathEquals(file, expectedPath, done); file.copy(newFile); }); + + it('should throw if a destination cannot be parsed', function() { + assert.throws(function() { + file.copy(function() {}); + }, /should have a name/); + }); }); describe('returned File object', function() { @@ -1162,6 +1187,22 @@ describe('File', function() { file.delete(); }); + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + file.makeReq_ = function(method, path, query, body, callback) { + callback(error, apiResponse); + }; + + file.delete(function(err, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(apiResponse_, apiResponse); + + done(); + }); + }); + it('should URI encode file names', function(done) { directoryFile.makeReq_ = function(method, path) { assert.equal(path, '/o/' + encodeURIComponent(directoryFile.name)); @@ -1489,6 +1530,42 @@ describe('File', function() { }); }); + it('should add success redirect', function(done) { + var redirectUrl = 'http://redirect'; + + file.getSignedPolicy({ + expires: Date.now() + 5, + successRedirect: redirectUrl + }, function(err, signedPolicy) { + assert.ifError(err); + + var policy = JSON.parse(signedPolicy.string); + assert(policy.conditions.some(function(condition) { + return condition.success_action_redirect === redirectUrl; + })); + + done(); + }); + }); + + it('should add success status', function(done) { + var successStatus = '200'; + + file.getSignedPolicy({ + expires: Date.now() + 5, + successStatus: successStatus + }, function(err, signedPolicy) { + assert.ifError(err); + + var policy = JSON.parse(signedPolicy.string); + assert(policy.conditions.some(function(condition) { + return condition.success_action_status === successStatus; + })); + + done(); + }); + }); + describe('expires', function() { it('should accept Date objects', function(done) { var expires = new Date(Date.now() + 1000 * 60); @@ -1885,6 +1962,21 @@ describe('File', function() { file.setMetadata(metadata, done); }); + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + file.makeReq_ = function(method, path, query, body, callback) { + callback(error, apiResponse); + }; + + file.setMetadata(metadata, function(err, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(apiResponse_, apiResponse); + done(); + }); + }); + it('should execute callback with apiResponse', function(done) { var resp = { success: true }; file.makeReq_ = function(method, path, query, body, callback) { @@ -1926,12 +2018,35 @@ describe('File', function() { }); describe('makePrivate', function() { - it('should execute callback', function(done) { + it('should execute callback with API response', function(done) { + var apiResponse = {}; + file.makeReq_ = function(method, path, query, body, callback) { - callback(); + callback(null, apiResponse); }; - file.makePrivate(done); + file.makePrivate(function(err, apiResponse_) { + assert.ifError(err); + assert.strictEqual(apiResponse_, apiResponse); + + done(); + }); + }); + + it('should execute callback with error & API response', function(done) { + var error = new Error('Error.'); + var apiResponse = {}; + + file.makeReq_ = function(method, path, query, body, callback) { + callback(error, apiResponse); + }; + + file.makePrivate(function(err, apiResponse_) { + assert.strictEqual(err, error); + assert.strictEqual(apiResponse_, apiResponse); + + done(); + }); }); it('should make the file private to project by default', function(done) {