11'use strict' ;
22
33const Buffer = require ( 'buffer' ) . Buffer ;
4- const BSON = require ( '../register-bson' ) ;
5- const EJSON = BSON . EJSON ;
6- const BSONTypeError = BSON . BSONTypeError ;
7- const ObjectId = BSON . ObjectId ;
4+ const { BSON , BSONError, EJSON , ObjectId } = require ( '../register-bson' ) ;
85const util = require ( 'util' ) ;
96const { expect } = require ( 'chai' ) ;
107const { bufferFromHexArray } = require ( './tools/utils' ) ;
@@ -103,7 +100,7 @@ describe('ObjectId', function () {
103100
104101 for ( const { input, description } of invalidInputs ) {
105102 it ( `should throw error if ${ description } is passed in` , function ( ) {
106- expect ( ( ) => new ObjectId ( input ) ) . to . throw ( BSONTypeError ) ;
103+ expect ( ( ) => new ObjectId ( input ) ) . to . throw ( BSONError ) ;
107104 } ) ;
108105 }
109106
@@ -114,7 +111,7 @@ describe('ObjectId', function () {
114111 return noArgObjID . toHexString ( ) ;
115112 }
116113 } ;
117- expect ( ( ) => new ObjectId ( objectIdLike ) ) . to . throw ( BSONTypeError ) ;
114+ expect ( ( ) => new ObjectId ( objectIdLike ) ) . to . throw ( BSONError ) ;
118115 } ) ;
119116
120117 it ( 'should correctly create ObjectId from object with valid string id' , function ( ) {
@@ -186,15 +183,15 @@ describe('ObjectId', function () {
186183 const objectNullId = {
187184 id : null
188185 } ;
189- expect ( ( ) => new ObjectId ( objectNumId ) ) . to . throw ( BSONTypeError ) ;
190- expect ( ( ) => new ObjectId ( objectNullId ) ) . to . throw ( BSONTypeError ) ;
186+ expect ( ( ) => new ObjectId ( objectNumId ) ) . to . throw ( BSONError ) ;
187+ expect ( ( ) => new ObjectId ( objectNullId ) ) . to . throw ( BSONError ) ;
191188 } ) ;
192189
193190 it ( 'should throw an error if object with invalid string id is passed in' , function ( ) {
194191 const objectInvalid24HexStr = {
195192 id : 'FFFFFFFFFFFFFFFFFFFFFFFG'
196193 } ;
197- expect ( ( ) => new ObjectId ( objectInvalid24HexStr ) ) . to . throw ( BSONTypeError ) ;
194+ expect ( ( ) => new ObjectId ( objectInvalid24HexStr ) ) . to . throw ( BSONError ) ;
198195 } ) ;
199196
200197 it ( 'should correctly create ObjectId from object with invalid string id and toHexString method' , function ( ) {
@@ -213,7 +210,7 @@ describe('ObjectId', function () {
213210 const objectInvalidBuffer = {
214211 id : Buffer . from ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] )
215212 } ;
216- expect ( ( ) => new ObjectId ( objectInvalidBuffer ) ) . to . throw ( BSONTypeError ) ;
213+ expect ( ( ) => new ObjectId ( objectInvalidBuffer ) ) . to . throw ( BSONError ) ;
217214 } ) ;
218215
219216 it ( 'should correctly create ObjectId from object with invalid Buffer id and toHexString method' , function ( ) {
@@ -270,11 +267,11 @@ describe('ObjectId', function () {
270267 } ) ;
271268
272269 it ( 'should throw error if non-12 byte non-24 hex string passed in' , function ( ) {
273- expect ( ( ) => new ObjectId ( 'FFFFFFFFFFFFFFFFFFFFFFFG' ) ) . to . throw ( BSONTypeError ) ;
274- expect ( ( ) => new ObjectId ( 'thisstringisdefinitelytoolong' ) ) . to . throw ( BSONTypeError ) ;
275- expect ( ( ) => new ObjectId ( 'tooshort' ) ) . to . throw ( BSONTypeError ) ;
276- expect ( ( ) => new ObjectId ( '101010' ) ) . to . throw ( BSONTypeError ) ;
277- expect ( ( ) => new ObjectId ( '' ) ) . to . throw ( BSONTypeError ) ;
270+ expect ( ( ) => new ObjectId ( 'FFFFFFFFFFFFFFFFFFFFFFFG' ) ) . to . throw ( BSONError ) ;
271+ expect ( ( ) => new ObjectId ( 'thisstringisdefinitelytoolong' ) ) . to . throw ( BSONError ) ;
272+ expect ( ( ) => new ObjectId ( 'tooshort' ) ) . to . throw ( BSONError ) ;
273+ expect ( ( ) => new ObjectId ( '101010' ) ) . to . throw ( BSONError ) ;
274+ expect ( ( ) => new ObjectId ( '' ) ) . to . throw ( BSONError ) ;
278275 } ) ;
279276
280277 it ( 'should correctly create ObjectId from 24 hex string' , function ( ) {
@@ -319,7 +316,7 @@ describe('ObjectId', function () {
319316
320317 it ( 'should throw an error if invalid Buffer passed in' , function ( ) {
321318 const a = Buffer . from ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] ) ;
322- expect ( ( ) => new ObjectId ( a ) ) . to . throw ( BSONTypeError ) ;
319+ expect ( ( ) => new ObjectId ( a ) ) . to . throw ( BSONError ) ;
323320 } ) ;
324321
325322 it ( 'should correctly allow for node.js inspect to work with ObjectId' , function ( done ) {
@@ -345,11 +342,11 @@ describe('ObjectId', function () {
345342 const characterCodesLargerThan256 = 'abcdefŽhijkl' ;
346343 const length12Not12Bytes = '🐶🐶🐶🐶🐶🐶' ;
347344 expect ( ( ) => new ObjectId ( characterCodesLargerThan256 ) . toHexString ( ) ) . to . throw (
348- BSONTypeError ,
345+ BSONError ,
349346 'Argument passed in must be a string of 12 bytes'
350347 ) ;
351348 expect ( ( ) => new ObjectId ( length12Not12Bytes ) . id ) . to . throw (
352- BSONTypeError ,
349+ BSONError ,
353350 'Argument passed in must be a string of 12 bytes'
354351 ) ;
355352 } ) ;
0 commit comments