Skip to content

Commit

Permalink
mongoose 7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Feb 23, 2023
1 parent 1f2f801 commit 0fc2ab1
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 183 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"co-mocha": "1.2.2",
"eslint": "7.32.0",
"mocha": "5.1.1",
"mongoose": "6.x",
"mongoose": "7.0.0-rc0",
"nyc": "11.7.3"
},
"peerDependencies": {
"mongoose": "6.x"
"mongoose": "6.x || 7.0.0-rc0"
},
"types": "./index.d.ts",
"author": "Valeri Karpov <[email protected]>",
Expand Down
40 changes: 13 additions & 27 deletions test/bugs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ describe('bug fixes', function() {
let db;

before(function() {
db = mongoose.createConnection('mongodb://localhost:27017/autopopulate', {
useUnifiedTopology: true,
useNewUrlParser: true
});
db = mongoose.createConnection('mongodb://localhost:27017/autopopulate');
});

after(function(done) {
db.close(done);
after(async function() {
await db.close();
});

beforeEach(function() {
Expand All @@ -30,7 +27,7 @@ describe('bug fixes', function() {
return Promise.all(promises);
});

it('gh-15', function(done) {
it('gh-15', async function() {
const opts = {
timestamps: { createdAt: 'createdAt' },
collection: 'collections',
Expand All @@ -56,26 +53,15 @@ describe('bug fixes', function() {
inheritSchema.plugin(autopopulate);
const Inherit = Root.discriminator('inherit', inheritSchema);

Tag.create([{ name: 'cool' }, { name: 'sweet' }], function(error, docs) {
assert.ifError(error);
const doc = {
name: 'Test',
customTags: [{ item: docs[0]._id }, { item: docs[1]._id }]
};
Inherit.create(doc, function(error, doc) {
assert.ifError(error);
test(doc._id);
});
});

function test(id) {
Inherit.findById(id).exec(function(error, doc) {
assert.ifError(error);
assert.equal(doc.customTags[0].item.name, 'cool');
assert.equal(doc.customTags[1].item.name, 'sweet');
done();
});
}
const docs = await Tag.create([{ name: 'cool' }, { name: 'sweet' }]);
let doc = {
name: 'Test',
customTags: [{ item: docs[0]._id }, { item: docs[1]._id }]
};
doc = await Inherit.create(doc);
doc = await Inherit.findById(doc);
assert.equal(doc.customTags[0].item.name, 'cool');
assert.equal(doc.customTags[1].item.name, 'sweet');
});

it('findOneAndUpdate (gh-6641)', function() {
Expand Down
Loading

0 comments on commit 0fc2ab1

Please sign in to comment.