Skip to content

Commit

Permalink
Merge b539608 into 3cdecf4
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgibson committed Jun 11, 2024
2 parents 3cdecf4 + b539608 commit 39e8721
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/submit-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ SubmitRequest.prototype.submit = function(callback) {
// must get the past ops and check their src and seq values to
// differentiate.
request._fetchCreateOpVersion(function(error, version) {
if (err) return callback(err);
if (error) return callback(error);
if (version == null) {
callback(request.alreadyCreatedError());
} else {
Expand Down
26 changes: 23 additions & 3 deletions test/client/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var deserializedType = require('./deserialized-type');
var numberType = require('./number-type');
var errorHandler = require('../util').errorHandler;
var richText = require('rich-text');
var MemoryDB = require('../../lib/db/memory');
types.register(deserializedType.type);
types.register(deserializedType.type2);
types.register(numberType.type);
Expand Down Expand Up @@ -215,8 +214,8 @@ module.exports = function() {

describe('no snapshot metadata available', function() {
beforeEach(function() {
var getSnapshot = MemoryDB.prototype.getSnapshot;
sinon.stub(MemoryDB.prototype, 'getSnapshot')
var getSnapshot = this.backend.db.getSnapshot;
sinon.stub(this.backend.db, 'getSnapshot')
.callsFake(function() {
var args = Array.from(arguments);
var callback = args.pop();
Expand All @@ -233,6 +232,27 @@ module.exports = function() {
});

runCreateTests();

it('returns errors if the database cannot get committed op version', function(done) {
sinon.stub(this.backend.db, 'getCommittedOpVersion')
.callsFake(function() {
var args = Array.from(arguments);
var callback = args.pop();
callback(new Error('uh-oh'));
});

var doc1 = this.backend.connect().get('dogs', 'fido');
var doc2 = this.backend.connect().get('dogs', 'fido');
async.series([
doc1.create.bind(doc1, {age: 3}),
function(next) {
doc2.create({name: 'Fido'}, function(error) {
expect(error.message).to.equal('uh-oh');
next();
});
}
], done);
});
});

function runCreateTests() {
Expand Down

0 comments on commit 39e8721

Please sign in to comment.