Skip to content

Commit

Permalink
refactor(test): move strictQuery tests to query.test.js since they do…
Browse files Browse the repository at this point in the history
… not use findOneAndUpdate()

Re: #7178
  • Loading branch information
vkarpov15 committed Oct 31, 2018
1 parent 4121629 commit 5ba13a7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
40 changes: 0 additions & 40 deletions test/model.findOneAndUpdate.test.js
Expand Up @@ -1655,46 +1655,6 @@ describe('model: findOneAndUpdate:', function() {
});
});

it('strictQuery option (gh-4136) (gh-7178)', function() {
const modelSchema = new Schema({
field: Number,
nested: { path: String }
}, { strictQuery: 'throw' });

const Model = db.model('gh4136', modelSchema);

return co(function*() {
// `find()` on a top-level path not in the schema
let err = yield Model.find({ notInschema: 1 }).then(() => null, e => e);
assert.ok(err);
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);

// Shouldn't throw on nested path re: gh-7178
yield Model.create({ nested: { path: 'a' } });
const doc = yield Model.findOne({ nested: { path: 'a' } });
assert.ok(doc);

// `find()` on a nested path not in the schema
err = yield Model.find({ 'nested.bad': 'foo' }).then(() => null, e => e);
assert.ok(err);
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);
});
});

it('strictQuery = true (gh-6032)', function() {
const modelSchema = new Schema({ field: Number }, { strictQuery: true });

return co(function*() {
const Model = db.model('gh6032', modelSchema);

yield Model.create({ field: 1 });

const docs = yield Model.find({ nonexistingField: 1 });

assert.equal(docs.length, 1);
});
});

it('strict option (gh-5108)', function(done) {
const modelSchema = new Schema({ field: Number }, { strict: 'throw' });

Expand Down
40 changes: 40 additions & 0 deletions test/query.test.js
Expand Up @@ -3157,4 +3157,44 @@ describe('Query', function() {
});
});
});

it('strictQuery option (gh-4136) (gh-7178)', function() {
const modelSchema = new Schema({
field: Number,
nested: { path: String }
}, { strictQuery: 'throw' });

const Model = db.model('gh4136', modelSchema);

return co(function*() {
// `find()` on a top-level path not in the schema
let err = yield Model.find({ notInschema: 1 }).then(() => null, e => e);
assert.ok(err);
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);

// Shouldn't throw on nested path re: gh-7178
yield Model.create({ nested: { path: 'a' } });
const doc = yield Model.findOne({ nested: { path: 'a' } });
assert.ok(doc);

// `find()` on a nested path not in the schema
err = yield Model.find({ 'nested.bad': 'foo' }).then(() => null, e => e);
assert.ok(err);
assert.ok(err.message.indexOf('strictQuery') !== -1, err.message);
});
});

it('strictQuery = true (gh-6032)', function() {
const modelSchema = new Schema({ field: Number }, { strictQuery: true });

return co(function*() {
const Model = db.model('gh6032', modelSchema);

yield Model.create({ field: 1 });

const docs = yield Model.find({ nonexistingField: 1 });

assert.equal(docs.length, 1);
});
});
});

0 comments on commit 5ba13a7

Please sign in to comment.