Skip to content

Commit

Permalink
Add tests for passing along snapshot options
Browse files Browse the repository at this point in the history
  • Loading branch information
Christina Burger committed Mar 22, 2021
1 parent 4532a6b commit e5af1a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ Backend.prototype.fetchBulk = function(agent, index, ids, options, callback) {
ids: ids
};
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);
var snapshotProjection = backend._getSnapshotProjection(backend.db, projection);
Expand Down
37 changes: 37 additions & 0 deletions test/backend.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
var Backend = require('../lib/backend');
var expect = require('chai').expect;
var sinon = require('sinon');

describe('Backend', function() {
var backend;
var agent = {
custom: {
foo: 'bar'
}
};
var fetchOptions = {
snapshotOptions: {
fizz: 'buzz'
}
};

beforeEach(function() {
backend = new Backend();
Expand Down Expand Up @@ -68,6 +79,32 @@ describe('Backend', function() {
done();
});
});

it('passes agent.custom and snapshot options to db', function(done) {
var getSnapshotSpy = sinon.spy(backend.db, 'getSnapshot');
backend.fetch(agent, 'books', '1984', fetchOptions, function(error) {
if (error) return done(error);
expect(getSnapshotSpy.args[0][3]).to.deep.equal({
custom: agent.custom,
fizz: 'buzz'
});
done();
});
});
});

describe('fetchBulk', function() {
it('passes agent.custom and snapshot options to db', function(done) {
var getSnapshotBulk = sinon.spy(backend.db, 'getSnapshotBulk');
backend.fetchBulk(agent, 'books', ['1984'], fetchOptions, function(error) {
if (error) return done(error);
expect(getSnapshotBulk.args[0][3]).to.deep.equal({
custom: agent.custom,
fizz: 'buzz'
});
done();
});
});
});

describe('subscribe', function() {
Expand Down

0 comments on commit e5af1a3

Please sign in to comment.