Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('array of ids', function () {
assert.deepEqual(getArrayPaths({ arr: [BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c30'), BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c32')] }), ['arr'])
})
it('object with mixed', function () {
it('object with mixed', function () {
assert.deepEqual(describeTypes({ a: '123', id2: BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c30') }), { id2: 'ObjectID'})
})
})
it('array of ids', function () {
assert.deepEqual(describeTypes({ arr: [BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c30'), BSON.ObjectID('5b1e1a6fa00fd75c4e6c4c32')] }), { arr: ['ObjectID'] })
})
it('object with mixed', function () {
const convertToBSON = function(doc) {
if (doc && doc._id && doc._id.length === 24) {
doc._id = BSON.ObjectID(doc._id)
}
return doc
}
const BSON = require('bson-ext')
const Long = BSON.Long
const _ = require('lodash')
exports.describeTypes = function (doc) {
if (doc._bsontype) {
return doc._bsontype
} else if (Array.isArray(doc)) {
const types = doc.map(exports.describeTypes)
const uniqueTypes = _.uniqWith(types, _.isEqual)
if (uniqueTypes.length > 1) {
//throw new Error('arrays containing multiple data types are not allowed')
}
if (_.isUndefined(uniqueTypes[0])) {
return []
}
return uniqueTypes
} else if (typeof doc === 'object') {