From 538629c3c8b6c38beec8f49181839d73bdb6397a Mon Sep 17 00:00:00 2001 From: Aditi Khare Date: Fri, 8 Nov 2024 15:43:13 -0500 Subject: [PATCH] fix failing tests --- docs/schematypes.md | 2 +- lib/cast/int32.js | 2 +- lib/drivers/browser/int32.js | 2 +- lib/schema.js | 4 +--- lib/types/index.js | 2 +- lib/types/int32.js | 2 +- test/types/schema.test.ts | 8 +++++++- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/schematypes.md b/docs/schematypes.md index 106cb2adce..cd4e4ce49e 100644 --- a/docs/schematypes.md +++ b/docs/schematypes.md @@ -69,7 +69,7 @@ const schema = new Schema({ mixed: Schema.Types.Mixed, _someId: Schema.Types.ObjectId, decimal: Schema.Types.Decimal128, - 32bitInt: Schema.Types.Int32, + int32bit: Schema.Types.Int32, array: [], ofString: [String], ofNumber: [Number], diff --git a/lib/cast/int32.js b/lib/cast/int32.js index 9ab76ca195..73ade6147a 100644 --- a/lib/cast/int32.js +++ b/lib/cast/int32.js @@ -27,7 +27,7 @@ module.exports = function castInt32(val) { const _val = Number(val); - if (_val !== _val | 0 && _val > INT32_MIN && _val < INT32_MAX) { + if (_val === (_val | 0) && _val > INT32_MIN && _val < INT32_MAX) { return _val; } assert.ok(false); diff --git a/lib/drivers/browser/int32.js b/lib/drivers/browser/int32.js index b56a43f6ce..0fc444a5d9 100644 --- a/lib/drivers/browser/int32.js +++ b/lib/drivers/browser/int32.js @@ -4,4 +4,4 @@ 'use strict'; -module.exports = require('bson').Int32; \ No newline at end of file +module.exports = require('bson').Int32; diff --git a/lib/schema.js b/lib/schema.js index 63b2c45f2c..3e9c95d24f 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -1494,8 +1494,6 @@ Schema.prototype.interpretAsType = function(path, obj, options) { name = 'ObjectId'; } else if (type === Types.Decimal128) { name = 'Decimal128'; - } else if (type === Types.Int32) { - name = 'Int32'; } else { name = type == null ? '' + type : type.toString(); } @@ -2850,7 +2848,7 @@ module.exports = exports = Schema; * - [Mixed](https://mongoosejs.com/docs/schematypes.html#mixed) * - [UUID](https://mongoosejs.com/docs/schematypes.html#uuid) * - [BigInt](https://mongoosejs.com/docs/schematypes.html#bigint) - * - Int32 + * - [Int32](https://mongoosejs.com/docs/schematypes.html#int32) * * Using this exposed access to the `Mixed` SchemaType, we can use them in our schema. * diff --git a/lib/types/index.js b/lib/types/index.js index 4369bf1ccf..0a365aea23 100644 --- a/lib/types/index.js +++ b/lib/types/index.js @@ -14,7 +14,7 @@ exports.Embedded = require('./arraySubdocument'); exports.DocumentArray = require('./documentArray'); exports.Decimal128 = require('./decimal128'); exports.ObjectId = require('./objectid'); -exports.ObjectId = require('./int32'); +exports.Int32 = require('./int32'); exports.Map = require('./map'); diff --git a/lib/types/int32.js b/lib/types/int32.js index 2ea4042faf..f4684f2db8 100644 --- a/lib/types/int32.js +++ b/lib/types/int32.js @@ -10,4 +10,4 @@ 'use strict'; -module.exports = require('bson').Int32; \ No newline at end of file +module.exports = require('bson').Int32; diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index 82988a05b1..6d8cc2dc24 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -425,6 +425,9 @@ export function autoTypedSchema() { decimal1?: Types.Decimal128 | null; decimal2?: Types.Decimal128 | null; decimal3?: Types.Decimal128 | null; + int32_1?: Types.Int32 | null; + int32_2?: Types.Int32 | null; + int32_3?: Types.Int32 | null; }; const TestSchema = new Schema({ @@ -471,7 +474,10 @@ export function autoTypedSchema() { array8: { type: [String], default: () => undefined }, decimal1: Schema.Types.Decimal128, decimal2: 'Decimal128', - decimal3: 'decimal128' + decimal3: 'decimal128', + int32_1: Schema.Types.Int32, + int32_2: 'Int32', + int32_3: 'int32' }); type InferredTestSchemaType = InferSchemaType;