From 50acfbaeaedb8ab94f07eb5eaf29af7a2961b476 Mon Sep 17 00:00:00 2001 From: Alec Gibson Date: Wed, 23 Sep 2020 17:00:07 +0100 Subject: [PATCH 1/2] Add `ot-json1` as a dev dependency Some of the new `sharedb` tests rely on `ot-json1` as a dependency. Without it, the tests fail to run. This change adds `ot-json1` as a `devDependency`. Note that we didn't need to do this for `ot-json0`, because `sharedb` ships with that as a `dependency`. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index c0f858e3..3f4003d9 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "eslint-config-google": "^0.13.0", "mocha": "^6.2.2", "nyc": "^14.1.1", + "ot-json1": "^1.0.1", "sharedb-mingo-memory": "^1.1.1", "sinon": "^6.1.5" }, From 6280fd509719366e93c676497ffdc33fdb9de47e Mon Sep 17 00:00:00 2001 From: Alec Gibson Date: Wed, 30 Sep 2020 17:34:20 +0100 Subject: [PATCH 2/2] Remove `sharedb-mingo-memory` tests This change reverts https://github.com/share/sharedb-mongo/commit/38d6f8a7130389208633007a92aa57c7a53e6e14 That change moved some tests from this library into `sharedb-mingo-memory` and then ran them in this library by requiring them from that one. While this de-duplicates code, it also introduces a surprising coupling between the tests of the two libraries. `sharedb-mingo-memory` can add arbitrary tests to the imported suite, which may not necessarily be applicable to `sharedb-mongo`, and even fail the `sharedb-mongo` build, as is happening now. This change removes that `require`, and just puts the original tests back (ignoring any other tests that have been added to that external suite since). --- test/test_mongo.js | 47 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/test/test_mongo.js b/test/test_mongo.js index 9299c58b..8f84c69a 100644 --- a/test/test_mongo.js +++ b/test/test_mongo.js @@ -1,6 +1,7 @@ var expect = require('chai').expect; var ShareDbMongo = require('..'); var getQuery = require('sharedb-mingo-memory/get-query'); +var async = require('async'); var mongoUrl = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'; @@ -77,8 +78,50 @@ describe('mongo db', function() { }); describe('query', function() { - // Run query tests for the types of queries supported by ShareDBMingo - require('sharedb-mingo-memory/test/query')(); + it('$count should count documents', function(done) { + var snapshots = [ + {type: 'json0', id: 'test1', v: 1, data: {x: 1, y: 1}}, + {type: 'json0', id: 'test2', v: 1, data: {x: 2, y: 2}}, + {type: 'json0', id: 'test3', v: 1, data: {x: 3, y: 2}} + ]; + var query = {$count: true, y: 2}; + + var db = this.db; + async.each(snapshots, function(snapshot, cb) { + db.commit('testcollection', snapshot.id, {v: 0, create: {}}, snapshot, null, cb); + }, function(err) { + if (err) return done(err); + db.query('testcollection', query, null, null, function(err, results, extra) { + if (err) return done(err); + + expect(results).eql([]); + expect(extra).eql(2); + done(); + }); + }); + }); + + it('$sort, $skip and $limit should order, skip and limit', function(done) { + var snapshots = [ + {type: 'json0', v: 1, data: {x: 1}, id: 'test1', m: null}, + {type: 'json0', v: 1, data: {x: 3}, id: 'test2', m: null}, // intentionally added out of sort order + {type: 'json0', v: 1, data: {x: 2}, id: 'test3', m: null} + ]; + var query = {$sort: {x: 1}, $skip: 1, $limit: 1}; + + var db = this.db; + async.each(snapshots, function(snapshot, cb) { + db.commit('testcollection', snapshot.id, {v: 0, create: {}}, snapshot, null, cb); + }, function(err) { + if (err) return done(err); + + db.query('testcollection', query, null, null, function(err, results) { + if (err) throw err; + expect(results).eql([snapshots[2]]); + done(); + }); + }); + }); it('does not allow $where queries', function(done) { this.db.query('testcollection', {$where: 'true'}, null, null, function(err) {