Skip to content

Commit

Permalink
Support new readSnapshots context info in fetchSnapshotByTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyhwang committed Feb 7, 2019
1 parent 15a438f commit 7e12683
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Backend.prototype.READ_SNAPSHOTS_METHODS = {
fetch: 'fetch',
fetchBulk: 'fetchBulk',
fetchSnapshot: 'fetchSnapshot',
fetchSnapshotByTimestamp: 'fetchSnapshotByTimestamp',
queryFetch: 'queryFetch',
querySubscribe: 'querySubscribe'
};
Expand Down Expand Up @@ -718,8 +719,16 @@ Backend.prototype.fetchSnapshotByTimestamp = function (agent, index, id, timesta
if (error) return callback(error);
var snapshotProjection = backend._getSnapshotProjection(backend.db, projection);
var snapshots = [snapshot];
var snapshotType = backend.SNAPSHOT_TYPES.byTimestamp;
backend._sanitizeSnapshots(agent, snapshotProjection, collection, snapshots, snapshotType, function (error) {
var requestContext = new ReadSnapshotsContext(
backend.READ_SNAPSHOTS_METHODS.fetchSnapshotByTimestamp,
{
index: index,
id: id,
timestamp: timestamp,
},
backend.SNAPSHOT_TYPES.byTimestamp
);
backend._sanitizeSnapshots(agent, snapshotProjection, collection, snapshots, requestContext, function (error) {
if (error) return callback(error);
backend.emit('timing', 'fetchSnapshot', Date.now() - start, request);
callback(null, snapshot);
Expand Down
2 changes: 2 additions & 0 deletions test/client/snapshot-timestamp-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ describe('SnapshotTimestampRequest', function () {
it('triggers the middleware', function (done) {
backend.use(backend.MIDDLEWARE_ACTIONS.readSnapshots,
function (request) {
expect(request.method).to.eql(backend.READ_SNAPSHOTS_METHODS.fetchSnapshotByTimestamp);
expect(request.parameters).to.eql({index: 'books', id: 'time-machine', timestamp: day3});
expect(request.snapshots[0]).to.eql(v3);
expect(request.snapshotType).to.be(backend.SNAPSHOT_TYPES.byTimestamp);
done();
Expand Down

0 comments on commit 7e12683

Please sign in to comment.