Skip to content

Commit

Permalink
test: fix tests re: #8725
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 28, 2020
1 parent c41c638 commit 486c020
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion lib/cast/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const assert = require('assert');
*/

module.exports = function castNumber(val) {

if (val == null) {
return val;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,8 @@ Query.prototype._findOne = wrapThunk(function(callback) {
*/

Query.prototype.findOne = function(conditions, projection, options, callback) {
this.op = 'findOne';

if (typeof conditions === 'function') {
callback = conditions;
conditions = null;
Expand All @@ -2191,8 +2193,6 @@ Query.prototype.findOne = function(conditions, projection, options, callback) {
// make sure we don't send in the whole Document to merge()
conditions = utils.toObject(conditions);

this.op = 'findOne';

if (options) {
this.setOptions(options);
}
Expand Down Expand Up @@ -2498,6 +2498,7 @@ Query.prototype.__distinct = wrapThunk(function __distinct(callback) {
*/

Query.prototype.distinct = function(field, conditions, callback) {
this.op = 'distinct';
if (!callback) {
if (typeof conditions === 'function') {
callback = conditions;
Expand All @@ -2522,7 +2523,6 @@ Query.prototype.distinct = function(field, conditions, callback) {
if (field != null) {
this._distinct = field;
}
this.op = 'distinct';

if (callback != null) {
this.exec(callback);
Expand Down
6 changes: 6 additions & 0 deletions lib/schema/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ SchemaArray.prototype.cast = function(value, doc, init) {
if (this.caster && this.casterConstructor !== Mixed) {
try {
for (i = 0, l = value.length; i < l; i++) {
// Special case: number arrays disallow undefined.
// Re: gh-840
// See commit 1298fe92d2c790a90594bd08199e45a4a09162a6
if (this.caster.instance === 'Number' && value[i] === void 0) {
throw new MongooseError('Mongoose number arrays disallow storing undefined');
}
value[i] = this.caster.cast(value[i], doc, init);
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion test/types.array.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1769,7 +1769,7 @@ describe('types array', function() {

describe('of number', function() {
it('allows nulls', function(done) {
const schema = new Schema({ x: [Number] }, { collection: 'nullsareallowed' + random() });
const schema = new Schema({ x: [Number] });
const M = db.model('Test', schema);
let m;

Expand Down
12 changes: 0 additions & 12 deletions test/types.number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ describe('types.number', function() {
done();
});

it('undefined throws number cast error', function(done) {
const n = new SchemaNumber();
let err;
try {
n.cast(undefined);
} catch (e) {
err = e;
}
assert.strictEqual(true, !!err);
done();
});

it('array throws cast number error', function(done) {
const n = new SchemaNumber();
let err;
Expand Down

0 comments on commit 486c020

Please sign in to comment.