Skip to content

Commit

Permalink
datastore: clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Dec 12, 2014
1 parent 196b3bf commit c2b94e9
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions regression/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
var env = require('./env.js');

var assert = require('assert');
var async = require('async');
var datastore = require('../lib/datastore');
var ds = datastore.dataset(env);
var entity = require('../lib/datastore/entity.js');
Expand Down Expand Up @@ -431,16 +432,11 @@ describe('datastore', function() {
};

ds.runInTransaction(function(t, tDone) {
t.get(key, function(err, entity) {
t.get(key, function(err) {
assert.ifError(err);

if (entity) {
tDone();
return;
} else {
t.save({ key: key, data: obj });
tDone();
}
t.save({ key: key, data: obj });
tDone();
});
}, function(err) {
assert.ifError(err);
Expand All @@ -456,11 +452,12 @@ describe('datastore', function() {
});

it('should commit all saves and deletes at the end', function(done) {
var incompleteKey = ds.key('Company');
var deleteKey = ds.key(['Company', 'Subway']);
var key = ds.key(['Company', 'Google']);
var incompleteKey = ds.key('Company');

ds.runInTransaction(function(t, tDone) {
t.delete(key);
t.delete(deleteKey);

t.save([
{
Expand All @@ -477,15 +474,28 @@ describe('datastore', function() {
}, function(err) {
assert.ifError(err);

// Should return a populated result because the last operation wins.
ds.get(key, function(err, entity) {
assert.ifError(err);
assert.equal(typeof entity, 'object');
// Incomplete key should have been given an ID.
assert.equal(incompleteKey.path.length, 2);

async.parallel([
// The key queued for deletion should have been deleted.
function(done) {
ds.get(deleteKey, function(err, entity) {
assert.ifError(err);
assert.equal(typeof entity, 'undefined');
done();
});
},

// Incomplete key should have been given an id.
assert.equal(incompleteKey.path.length, 2);
done();
});
// Data should have been updated on the key.
function(done) {
ds.get(key, function(err, entity) {
assert.ifError(err);
assert.equal(entity.data.rating, 10);
done();
});
}
], done);
});
});

Expand Down

0 comments on commit c2b94e9

Please sign in to comment.