Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Feb 24, 2023
1 parent 1e582e7 commit 4da86ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
"acquit": "1.0.0",
"acquit-ignore": "0.0.3",
"acquit-markdown": "0.1.0",
"co": "4.6.0",
"co-mocha": "1.2.2",
"eslint": "7.32.0",
"mocha": "5.1.1",
"mongoose": "7.0.0-rc0",
Expand Down
27 changes: 12 additions & 15 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

const assert = require('assert');
const autopopulate = require('../');
const co = require('co');
const mongoose = require('mongoose');

const Schema = mongoose.Schema;
const ObjectId = mongoose.Schema.Types.ObjectId;

require('co-mocha')(require('mocha'));

describe('mongoose-autopopulate plugin', function() {
let Band;
let Person;
Expand Down Expand Up @@ -88,13 +85,13 @@ describe('mongoose-autopopulate plugin', function() {
lead: { type: ObjectId, ref: 'people', autopopulate: true }
});
bandSchema.plugin(autopopulate);

const Band = mongoose.model('band3', bandSchema, 'bands');
const doc = await Band.findOne({ name: 'Guns N\' Roses' });
assert.equal('Axl Rose', doc.lead.name);
assert.equal('William Bruce Rose, Jr.', doc.lead.birthName);
});


/**
* `mongoose-autopopulate` also works on arrays.
Expand All @@ -105,13 +102,13 @@ describe('mongoose-autopopulate plugin', function() {
members: [{ type: ObjectId, ref: 'people', autopopulate: true }]
});
bandSchema.plugin(autopopulate);

const Band = mongoose.model('band4', bandSchema, 'bands');
const doc = await Band.findOne({ name: 'Guns N\' Roses' });
assert.equal('Axl Rose', doc.members[0].name);
assert.equal('William Bruce Rose, Jr.', doc.members[0].birthName);
});

/**
* By default, Mongoose 5.x automatically projects in populated properties.
* That means you need a little extra work to exclude autopopulated fields.
Expand Down Expand Up @@ -150,7 +147,7 @@ describe('mongoose-autopopulate plugin', function() {
lead: { type: ObjectId, ref: 'people', autopopulate: { select: 'name' } }
});
bandSchema.plugin(autopopulate);

const Band = mongoose.model('band5', bandSchema, 'bands');
const doc = await Band.findOne({ name: 'Guns N\' Roses' });
assert.equal('Axl Rose', doc.lead.name);
Expand All @@ -164,46 +161,46 @@ describe('mongoose-autopopulate plugin', function() {
* The below `populate()` uses the same options as the previous
* example.
*/
it('can specify a function that returns options', async () => {
it('can specify a function that returns options', async() => {
let numCalls = 0;
const optionsFunction = function() {
++numCalls;
return { select: 'name' };
};

const bandSchema = new Schema({
name: String,
lead: { type: ObjectId, ref: 'people', autopopulate: optionsFunction }
});
bandSchema.plugin(autopopulate);

const Band = mongoose.model('band6', bandSchema, 'bands');
const docs = await Band.find({ name: 'Guns N\' Roses' });
assert.equal(1, docs.length);
assert.equal(1, numCalls);
const doc = docs[0];
assert.equal('Axl Rose', doc.lead.name);
assert.ok(!doc.lead.birthName);
});
});

/**
* If you set the `autopopulate` option to `false` on a query, autopopulate
* will be disabled. This is handy if you want to autopopulate by default,
* but opt-out for special cases.
*/
it('can disable autopopulate for individual queries', async () => {
it('can disable autopopulate for individual queries', async() => {
const bandSchema = new Schema({
name: String,
lead: { type: ObjectId, ref: 'people', autopopulate: true }
});
bandSchema.plugin(autopopulate);

const Band = mongoose.model('band7', bandSchema, 'bands');
const doc = await Band.findOne({ name: 'Guns N\' Roses' }, {}, { autopopulate: false });
assert.ok(doc.lead instanceof mongoose.Types.ObjectId);
assert.ok(!doc.populated('lead'));
});


/**
* Say you have a model `User` that has the autopopulate plugin and you're
Expand Down

0 comments on commit 4da86ce

Please sign in to comment.