Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed May 12, 2016
1 parent 19e8e81 commit 7528e09
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 141 deletions.
6 changes: 3 additions & 3 deletions lib/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ var util = require('../common/util.js');
* var query = datastore.createQuery('Contacts')
* .limit(NUM_RESULTS_PER_PAGE);
*
* if (req.query.startCursor) {
* query.start(req.query.startCursor);
* if (req.query.nextPageCursor) {
* query.start(req.query.nextPageCursor);
* }
*
* datastore.runQuery(query, function(err, entities, info) {
Expand All @@ -222,7 +222,7 @@ var util = require('../common/util.js');
* };
*
* if (info.moreResults !== 'NO_MORE_RESULTS') {
* frontEndResponse.startCursor = info.endCursor;
* frontEndResponse.nextPageCursor = info.endCursor;
* }
*
* res.render('contacts', frontEndResponse);
Expand Down
4 changes: 1 addition & 3 deletions lib/datastore/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,9 @@ Query.prototype.offset = function(n) {
* - `MORE_RESULTS_AFTER_CURSOR`: There *may* be more results after the
* specified end cursor.
* - `NO_MORE_RESULTS`: There are no more results.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* query.run(function(err, entities, info, apiResponse) {});
* query.run(function(err, entities, info) {});
*
* //-
* // If you omit the callback, you will get the matching entities in a readable
Expand All @@ -309,7 +308,6 @@ Query.prototype.offset = function(n) {
* .on('error', console.error)
* .on('data', function (entity) {})
* .on('info', function(info) {})
* .on('response', function(apiResponse) {})
* .on('end', function() {
* // All entities retrieved.
* });
Expand Down
15 changes: 4 additions & 11 deletions lib/datastore/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ DatastoreRequest.prototype.insert = function(entities, callback) {
* - `MORE_RESULTS_AFTER_CURSOR`: There *may* be more results after the
* specified end cursor.
* - `NO_MORE_RESULTS`: There are no more results.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* //-
Expand All @@ -401,7 +400,7 @@ DatastoreRequest.prototype.insert = function(entities, callback) {
* //-
* var query = datastore.createQuery('Lion');
*
* datastore.runQuery(query, function(err, entities, info, apiResponse) {});
* datastore.runQuery(query, function(err, entities, info) {});
*
* //-
* // Or, if you're using a transaction object.
Expand All @@ -420,7 +419,6 @@ DatastoreRequest.prototype.insert = function(entities, callback) {
* .on('error', console.error)
* .on('data', function (entity) {})
* .on('info', function(info) {})
* .on('response', function(apiResponse) {})
* .on('end', function() {
* // All entities retrieved.
* });
Expand Down Expand Up @@ -453,21 +451,17 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {

options = options || {};

var apiResponse;
var info;

if (is.fn(callback)) {
// Run this method in stream mode and send the results back to the callback.
this.runQuery(query, options)
.on('error', callback)
.on('response', function(apiResponse_) {
apiResponse = apiResponse_;
})
.on('info', function(info_) {
info = info_;
})
.pipe(concat(function(results) {
callback(null, results, info, apiResponse);
callback(null, results, info);
}));
return;
}
Expand Down Expand Up @@ -496,6 +490,8 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {
};
}

this.request_(protoOpts, reqOpts, onResponse);

function onResponse(err, resp) {
if (err) {
stream.destroy(err);
Expand Down Expand Up @@ -523,7 +519,6 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {
}

if (resp.batch.moreResults !== 'NOT_FINISHED') {
stream.emit('response', resp);
stream.emit('info', info);
stream.push(null);
return;
Expand All @@ -546,8 +541,6 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {
});
}

this.request_(protoOpts, reqOpts, onResponse);

return stream;
};

Expand Down
2 changes: 1 addition & 1 deletion system-test/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var env = require('./env.js');
var Datastore = require('../lib/datastore/index.js');
var entity = require('../lib/datastore/entity.js');

describe.only('Datastore', function() {
describe('Datastore', function() {
var testKinds = [];
var datastore = new Datastore(env);

Expand Down
14 changes: 0 additions & 14 deletions test/common/stream-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,6 @@ describe('streamRouter', function() {
assert.strictEqual(parsedArguments.maxResults, args[0].maxResults);
});

it('should set maxResults from query.limitVal', function() {
var args = [ { limitVal: 10 } ];
var parsedArguments = streamRouter.parseArguments_(args);

assert.strictEqual(parsedArguments.maxResults, args[0].limitVal);
});

it('should set maxResults from query.pageSize', function() {
var args = [ { pageSize: 10 } ];
var parsedArguments = streamRouter.parseArguments_(args);
Expand All @@ -213,13 +206,6 @@ describe('streamRouter', function() {

assert.strictEqual(parsedArguments.autoPaginate, false);
});

it('should set autoPaginate: false with query.autoPaginateVal', function() {
var args = [ { autoPaginateVal: false }, util.noop ];
var parsedArguments = streamRouter.parseArguments_(args);

assert.strictEqual(parsedArguments.autoPaginate, false);
});
});

describe('router_', function() {
Expand Down
31 changes: 0 additions & 31 deletions test/datastore/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,6 @@ describe('Query', function() {
assert.strictEqual(query.namespace, null);
});
});

it('should enable auto pagination by default', function() {
assert.strictEqual(query.autoPaginateVal, true);
});
});

describe('autoPaginate', function() {
it('should enable auto pagination', function() {
var query = new Query(['kind1']).autoPaginate();

assert.strictEqual(query.autoPaginateVal, true);
});

it('should disable auto pagination when false is passed in', function() {
var query = new Query(['kind1']).autoPaginate(false);

assert.strictEqual(query.autoPaginateVal, false);
});

it('should not disable auto pagination with falsy values', function() {
var query = new Query(['kind1']).autoPaginate(null);

assert.strictEqual(query.autoPaginateVal, true);
});

it('should return the query instance', function() {
var query = new Query(['kind1']);
var nextQuery = query.autoPaginate(false);

assert.strictEqual(query, nextQuery);
});
});

describe('filter', function() {
Expand Down
Loading

0 comments on commit 7528e09

Please sign in to comment.