Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Nov 8, 2024
1 parent 021f84b commit 538629c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/schematypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion lib/cast/int32.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/browser/int32.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

'use strict';

module.exports = require('bson').Int32;
module.exports = require('bson').Int32;
4 changes: 1 addition & 3 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion lib/types/int32.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

'use strict';

module.exports = require('bson').Int32;
module.exports = require('bson').Int32;
8 changes: 7 additions & 1 deletion test/types/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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<typeof TestSchema>;
Expand Down

0 comments on commit 538629c

Please sign in to comment.