Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- 5.0
- 6.0
- 7.0
- 8.0
services:
mongodb:
image: mongo:${{ matrix.mongodb }}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "MongoDB database adapter for ShareDB",
"main": "index.js",
"dependencies": {
"mongodb": "^3.1.13 || ^4.0.0 || ^5.0.0 || ^6.0.0",
"mongodb": "^3.1.13 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0",
"sharedb": "^1.9.1 || ^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0"
},
"devDependencies": {
Expand All @@ -18,6 +18,7 @@
"mongodb4": "npm:mongodb@^4.0.0",
"mongodb5": "npm:mongodb@^5.0.0",
"mongodb6": "npm:mongodb@^6.0.0",
"mongodb7": "npm:mongodb@^7.0.0",
"nyc": "^14.1.1",
"ot-json1": "^1.0.1",
"rich-text": "^4.1.0",
Expand All @@ -33,7 +34,8 @@
"test:mongodb4": "_SHAREDB_MONGODB_DRIVER=mongodb4 npm test",
"test:mongodb5": "_SHAREDB_MONGODB_DRIVER=mongodb5 npm test",
"test:mongodb6": "_SHAREDB_MONGODB_DRIVER=mongodb6 npm test",
"test:all": "npm run test:mongodb3 && npm run test:mongodb4 && npm run test:mongodb5 && npm run test:mongodb6",
"test:mongodb7": "_SHAREDB_MONGODB_DRIVER=mongodb7 npm test",
"test:all": "npm run test:mongodb3 && npm run test:mongodb4 && npm run test:mongodb5 && npm run test:mongodb6 && npm run test:mongodb7",
"test-cover": "nyc --temp-dir=coverage -r text -r lcov npm run test:all"
},
"repository": "git://github.com/share/sharedb-mongo.git",
Expand Down
18 changes: 15 additions & 3 deletions test/test_mongo_middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ describe('mongo db middleware', function() {

describe(BEFORE_EDIT, function() {
it('has the expected properties on the request object', function(done) {
var middlewareEntranceCount = 0;

db.use(BEFORE_EDIT, function(request, next) {
middlewareEntranceCount = middlewareEntranceCount + 1;
expect(request).to.have.all.keys([
'action',
'collectionName',
Expand All @@ -87,7 +90,6 @@ describe('mongo db middleware', function() {
expect(request.options.testOptions).to.equal('yes');
expect(request.query._id).to.equal('test1');
next();
done();
});

var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}};
Expand All @@ -98,6 +100,9 @@ describe('mongo db middleware', function() {
if (err) return done(err);
db.commit('testcollection', snapshot.id, editOp, newSnapshot, {testOptions: 'yes'}, function(err) {
if (err) return done(err);

expect(middlewareEntranceCount).to.equal(1);
done();
});
});
});
Expand Down Expand Up @@ -221,7 +226,10 @@ describe('mongo db middleware', function() {

describe(BEFORE_SNAPSHOT_LOOKUP, function() {
it('has the expected properties on the request object before getting a single snapshot', function(done) {
var middlewareEntranceCount = 0;

db.use(BEFORE_SNAPSHOT_LOOKUP, function(request, next) {
middlewareEntranceCount = middlewareEntranceCount + 1;
expect(request).to.have.all.keys([
'action',
'collectionName',
Expand All @@ -233,7 +241,6 @@ describe('mongo db middleware', function() {
expect(request.options.testOptions).to.equal('yes');
expect(request.query._id).to.equal('test1');
next();
done();
});

var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}};
Expand All @@ -242,6 +249,8 @@ describe('mongo db middleware', function() {
db.getSnapshot('testcollection', 'test1', null, {testOptions: 'yes'}, function(err, doc) {
if (err) return done(err);
expect(doc).to.exist;
expect(middlewareEntranceCount).to.equal(1);
done();
});
});
});
Expand Down Expand Up @@ -356,7 +365,9 @@ describe('mongo db middleware', function() {
});

it('has the expected properties on the request object before getting bulk snapshots', function(done) {
var middlewareEntranceCount = 0;
db.use(BEFORE_SNAPSHOT_LOOKUP, function(request, next) {
middlewareEntranceCount = middlewareEntranceCount + 1;
expect(request).to.have.all.keys([
'action',
'collectionName',
Expand All @@ -368,7 +379,6 @@ describe('mongo db middleware', function() {
expect(request.options.testOptions).to.equal('yes');
expect(request.query._id).to.deep.equal({$in: ['test1']});
next();
done();
});

var snapshot = {type: 'json0', id: 'test1', v: 1, data: {foo: 'bar'}};
Expand All @@ -377,6 +387,8 @@ describe('mongo db middleware', function() {
db.getSnapshotBulk('testcollection', ['test1'], null, {testOptions: 'yes'}, function(err, doc) {
if (err) return done(err);
expect(doc).to.exist;
expect(middlewareEntranceCount).to.equal(1);
done();
});
});
});
Expand Down