|
1 | 1 | var expect = require('chai').expect; |
| 2 | +var Backend = require('../lib/backend'); |
2 | 3 | var DB = require('../lib/db'); |
3 | 4 | var BasicQueryableMemoryDB = require('./BasicQueryableMemoryDB'); |
| 5 | +var async = require('async'); |
4 | 6 |
|
5 | 7 | describe('DB base class', function() { |
6 | 8 | it('can call db.close() without callback', function() { |
@@ -54,17 +56,83 @@ describe('DB base class', function() { |
54 | 56 | }); |
55 | 57 | }); |
56 | 58 |
|
57 | | -// Run all the DB-based tests against the BasicQueryableMemoryDB. |
58 | | -require('./db')({ |
59 | | - create: function(options, callback) { |
60 | | - if (typeof options === 'function') { |
61 | | - callback = options; |
62 | | - options = null; |
| 59 | +describe('MemoryDB', function() { |
| 60 | + // Run all the DB-based tests against the BasicQueryableMemoryDB. |
| 61 | + require('./db')({ |
| 62 | + create: function(options, callback) { |
| 63 | + if (typeof options === 'function') { |
| 64 | + callback = options; |
| 65 | + options = null; |
| 66 | + } |
| 67 | + var db = new BasicQueryableMemoryDB(options); |
| 68 | + callback(null, db); |
| 69 | + }, |
| 70 | + getQuery: function(options) { |
| 71 | + return {filter: options.query, sort: options.sort}; |
63 | 72 | } |
64 | | - var db = new BasicQueryableMemoryDB(options); |
65 | | - callback(null, db); |
66 | | - }, |
67 | | - getQuery: function(options) { |
68 | | - return {filter: options.query, sort: options.sort}; |
69 | | - } |
| 73 | + }); |
| 74 | + |
| 75 | + describe('deleteOps', function() { |
| 76 | + describe('with some ops', function() { |
| 77 | + var backend; |
| 78 | + var db; |
| 79 | + var connection; |
| 80 | + var doc; |
| 81 | + |
| 82 | + beforeEach(function(done) { |
| 83 | + backend = new Backend(); |
| 84 | + db = backend.db; |
| 85 | + connection = backend.connect(); |
| 86 | + doc = connection.get('dogs', 'fido'); |
| 87 | + |
| 88 | + async.waterfall([ |
| 89 | + doc.create.bind(doc, {name: 'Fido'}), |
| 90 | + doc.submitOp.bind(doc, [{p: ['tricks'], oi: ['fetch']}]), |
| 91 | + db.getOps.bind(db, 'dogs', 'fido', null, null, null), |
| 92 | + function(ops, next) { |
| 93 | + expect(ops).to.have.length(2); |
| 94 | + next(); |
| 95 | + } |
| 96 | + ], done); |
| 97 | + }); |
| 98 | + |
| 99 | + it('deletes all ops', function(done) { |
| 100 | + async.waterfall([ |
| 101 | + db.deleteOps.bind(db, 'dogs', 'fido', null, null, null), |
| 102 | + function(next) { |
| 103 | + db.getOps('dogs', 'fido', null, null, null, function(error) { |
| 104 | + expect(error.message).to.equal('Missing ops'); |
| 105 | + next(); |
| 106 | + }); |
| 107 | + } |
| 108 | + ], done); |
| 109 | + }); |
| 110 | + |
| 111 | + it('deletes some ops', function(done) { |
| 112 | + async.waterfall([ |
| 113 | + db.deleteOps.bind(db, 'dogs', 'fido', 0, 1, null), |
| 114 | + db.getOps.bind(db, 'dogs', 'fido', 1, 2, null), |
| 115 | + function(ops, next) { |
| 116 | + expect(ops).to.have.length(1); |
| 117 | + expect(ops[0].op).to.eql([{p: ['tricks'], oi: ['fetch']}]); |
| 118 | + db.getOps('dogs', 'fido', 0, 1, null, function(error) { |
| 119 | + expect(error.message).to.equal('Missing ops'); |
| 120 | + next(); |
| 121 | + }); |
| 122 | + } |
| 123 | + ], done); |
| 124 | + }); |
| 125 | + |
| 126 | + it('submits more ops after deleting ops', function(done) { |
| 127 | + async.series([ |
| 128 | + db.deleteOps.bind(db, 'dogs', 'fido', null, null, null), |
| 129 | + doc.submitOp.bind(doc, [{p: ['tricks', 1], li: 'sit'}]), |
| 130 | + function(next) { |
| 131 | + expect(doc.data.tricks).to.eql(['fetch', 'sit']); |
| 132 | + next(); |
| 133 | + } |
| 134 | + ], done); |
| 135 | + }); |
| 136 | + }); |
| 137 | + }); |
70 | 138 | }); |
0 commit comments