From d78ee9042faceba76712dee8d0e94a98a6e03c7f Mon Sep 17 00:00:00 2001 From: haad Date: Sun, 3 Jun 2018 07:44:58 +0200 Subject: [PATCH] Test that document store can return the full op data --- test/docstore.test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/docstore.test.js b/test/docstore.test.js index 16fbd13..836df80 100644 --- a/test/docstore.test.js +++ b/test/docstore.test.js @@ -135,6 +135,37 @@ Object.keys(testAPIs).forEach(API => { assert.deepEqual(value1, [doc2, doc3]) assert.deepEqual(value2, [doc2]) }) + + it('query returns full op', async () => { + const doc1 = { _id: 'hello world', doc: 'all the things', views: 17} + const doc2 = { _id: 'sup world', doc: 'some of the things', views: 10} + + const expectedOperation = { + op: 'PUT', + key: 'sup world', + value: { + _id: 'sup world', + doc: 'some of the things', + views: 10 + }, + } + + await db.put(doc1) + await db.put(doc2) + + const res = db.query(e => e.payload.value.views < 17, { fullOp: true })[0] + assert.notEqual(res, undefined) + assert.notEqual(res.hash, undefined) + assert.notEqual(res.id, undefined) + assert.deepEqual(res.payload, expectedOperation) + assert.notEqual(res.next, undefined) + assert.equal(res.next.length, 1) + assert.equal(res.v, 0) + assert.notEqual(res.clock, undefined) + assert.equal(res.clock.time, 2) + assert.notEqual(res.key, undefined) + assert.notEqual(res.sig, undefined) + }) }) describe('Specified index', function() {