diff --git a/datastore/query.js b/datastore/query.js index eb4769c7a96..ddaedfe8e36 100644 --- a/datastore/query.js +++ b/datastore/query.js @@ -152,18 +152,47 @@ Query.prototype.testKindlessQuery = function(callback) { }; Query.prototype.testRunQueryProjection = function(callback) { + var self = this; var query = this.projectionQuery; - // jshint unused:false + // Overwrite the mock to actually run the query. + datastore.runQuery = function(query, queryCallback) { + // Restore the mock. + datastore.runQuery = function() {}; + + self.datastore.runQuery(query, function(err) { + if (err) { + callback(err); + return; + } + + queryCallback.apply(null, arguments); + + if (priorities.length === 0 || percentCompletes.length === 0) { + callback(new Error('Projection lists did not build up.')); + } else { + callback(); + } + }); + }; + + // jshint unused:false, camelcase:false // [START run_query_projection] - datastore.runQuery(query, function(err, entities) { - if (!err) { - // Entities found. + var priorities = []; + var percentCompletes = []; + + datastore.runQuery(query, function(err, tasks) { + if (err) { + // An error occurred while running the query. + return; } + + tasks.forEach(function(task) { + priorities.push(task.data.priority); + percentCompletes.push(task.data.percent_complete); + }); }); // [END run_query_projection] - - this.datastore.runQuery(query, callback); }; Query.prototype.testKeysOnlyQuery = function(callback) {