@@ -152,18 +152,47 @@ Query.prototype.testKindlessQuery = function(callback) {
152152} ;
153153
154154Query . prototype . testRunQueryProjection = function ( callback ) {
155+ var self = this ;
155156 var query = this . projectionQuery ;
156157
157- // jshint unused:false
158+ // Overwrite the mock to actually run the query.
159+ datastore . runQuery = function ( query , queryCallback ) {
160+ // Restore the mock.
161+ datastore . runQuery = function ( ) { } ;
162+
163+ self . datastore . runQuery ( query , function ( err ) {
164+ if ( err ) {
165+ callback ( err ) ;
166+ return ;
167+ }
168+
169+ queryCallback . apply ( null , arguments ) ;
170+
171+ if ( priorities . length === 0 || percentCompletes . length === 0 ) {
172+ callback ( new Error ( 'Projection lists did not build up.' ) ) ;
173+ } else {
174+ callback ( ) ;
175+ }
176+ } ) ;
177+ } ;
178+
179+ // jshint unused:false, camelcase:false
158180 // [START run_query_projection]
159- datastore . runQuery ( query , function ( err , entities ) {
160- if ( ! err ) {
161- // Entities found.
181+ var priorities = [ ] ;
182+ var percentCompletes = [ ] ;
183+
184+ datastore . runQuery ( query , function ( err , tasks ) {
185+ if ( err ) {
186+ // An error occurred while running the query.
187+ return ;
162188 }
189+
190+ tasks . forEach ( function ( task ) {
191+ priorities . push ( task . data . priority ) ;
192+ percentCompletes . push ( task . data . percent_complete ) ;
193+ } ) ;
163194 } ) ;
164195 // [END run_query_projection]
165-
166- this . datastore . runQuery ( query , callback ) ;
167196} ;
168197
169198Query . prototype . testKeysOnlyQuery = function ( callback ) {
0 commit comments