Skip to content

Commit

Permalink
Add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christina Burger committed Mar 23, 2021
1 parent e5af1a3 commit c621707
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ Backend.prototype.fetch = function(agent, index, id, options, callback) {
collection: collection,
id: id
};
var snapshotOptions = options && options.snapshotOptions || {};
var snapshotOptions = (options && options.snapshotOptions) || {};
if (agent) snapshotOptions.custom = agent.custom;
backend.db.getSnapshot(collection, id, fields, snapshotOptions, function(err, snapshot) {
if (err) return callback(err);
Expand Down Expand Up @@ -439,7 +439,7 @@ Backend.prototype.fetchBulk = function(agent, index, ids, options, callback) {
collection: collection,
ids: ids
};
var snapshotOptions = options && options.snapshotOptions;
var snapshotOptions = (options && options.snapshotOptions) || {};
if (agent) snapshotOptions.custom = agent.custom;
backend.db.getSnapshotBulk(collection, ids, fields, snapshotOptions, function(err, snapshotMap) {
if (err) return callback(err);
Expand Down
16 changes: 16 additions & 0 deletions test/client/submit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var async = require('async');
var expect = require('chai').expect;
var sinon = require('sinon');
var types = require('../../lib/types');
var deserializedType = require('./deserialized-type');
var numberType = require('./number-type');
Expand Down Expand Up @@ -44,6 +45,21 @@ module.exports = function() {
});
});

it('can create a new doc and pass options to getSnapshot', function(done) {
var connection = this.backend.connect();
connection.agent.custom = {
foo: 'bar'
};
var getSnapshotSpy = sinon.spy(this.backend.db, 'getSnapshot');
connection.get('dogs', 'fido').create({age: 3}, function(err) {
if (err) return done(err);
expect(getSnapshotSpy.args[0][3]).to.deep.equal({
custom: {foo: 'bar'}
});
done();
});
});

it('can create then delete then create a doc', function(done) {
var doc = this.backend.connect().get('dogs', 'fido');
doc.create({age: 3}, function(err) {
Expand Down

0 comments on commit c621707

Please sign in to comment.