Skip to content

Commit

Permalink
use Mongoose 8 in test, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Sep 3, 2024
1 parent c03e481 commit ef2d6c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"eslint": "7.x",
"istanbul": "0.4.5",
"mocha": "5.2.x",
"mongoose": "7.0.0-rc0"
"mongoose": "8.x"
},
"peerDependencies": {
"mongoose": ">=5.11.10"
Expand Down
22 changes: 2 additions & 20 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@ const Schema = mongoose.Schema;

let baseDocId;
let baseDocIdToDelete;
let baseDocIdToRemove;
let baseModel;
let baseObj;
let baseSchema;

const createRemovableDocs = async () => {
const baseDocToDelete = await baseModel.create(baseObj);
const baseDocToRemove = await baseModel.create(baseObj);
baseDocIdToDelete = baseDocToDelete._id;
baseDocIdToRemove = baseDocToRemove._id;
};

const getDocIdBySupportedOp = (op) => {
if (op === 'findOneAndDelete') {
return baseDocIdToDelete;
} else if (op === 'findOneAndRemove') {
return baseDocIdToRemove;
} else {
return baseDocId;
}
Expand Down Expand Up @@ -96,10 +91,6 @@ const supportedOps = {
leanOptions = leanOptions || defaultLeanOptions;
return model.findOneAndUpdate({}, {}).lean(leanOptions).exec();
},
'findOneAndRemove': function(model, docId, leanOptions) {
leanOptions = leanOptions || defaultLeanOptions;
return model.findOneAndRemove({ _id: docId }).lean(leanOptions).exec();
},
'findOneAndDelete': function(model, docId, leanOptions) {
leanOptions = leanOptions || defaultLeanOptions;
return model.findOneAndDelete({ _id: docId }).lean(leanOptions).exec();
Expand Down Expand Up @@ -183,10 +174,8 @@ describe('Virtuals work with cursor', function() {
});
});

// Skipping for now since this doesn't work.
describe('Nested schema virtuals work', function() {
let parentBaseDocId;
let parentDocIdToRemove;
let parentDocIdToDelete;
let parentModel;

Expand All @@ -202,25 +191,17 @@ describe('Nested schema virtuals work', function() {
nested: baseObj,
arr: [baseObj, baseObj],
});
const parentDocToRemove = await parentModel.create({
nested: baseObj,
arr: [baseObj, baseObj],
});
const parentDocToDelete = await parentModel.create({
nested: baseObj,
arr: [baseObj, baseObj],
});
parentBaseDocId = parentDoc._id;
parentDocIdToRemove = parentDocToRemove._id;
parentDocIdToDelete = parentDocToDelete._id;
});

supportedOpsKeys.forEach(key => {
it(`with ${key}`, async function() {
let parentDocId = parentBaseDocId;
if (key === 'findOneAndRemove') {
parentDocId = parentDocIdToRemove;
}
if (key === 'findOneAndDelete') {
parentDocId = parentDocIdToDelete;
}
Expand Down Expand Up @@ -430,6 +411,7 @@ describe('Discriminators work', () => {
});

childModel = baseModel.discriminator('childModel', childSchema);
await childModel.deleteMany({});

const childDoc = await childModel.create({
name: 'Val',
Expand All @@ -448,7 +430,7 @@ describe('Discriminators work', () => {
});

it('with find', async function() {
const docs = await childModel.find();
const docs = await childModel.find().lean({ virtuals: true });
assert.ok(docs);
docs.forEach((doc) => {
assert.equal(doc.name, 'Val');
Expand Down

0 comments on commit ef2d6c6

Please sign in to comment.