99 PropertyType ,
1010 getDefaultValues ,
1111 ObjectIdConstructorParameter ,
12+ GetIdsOptions ,
1213} from '../utils' ;
1314
1415describe ( 'utils' , ( ) => {
@@ -379,44 +380,78 @@ describe('utils', () => {
379380 } ) ;
380381
381382 describe ( 'getIds' , ( ) => {
382- // prettier-ignore
383- test . each < [ string , readonly ObjectIdConstructorParameter [ ] , readonly ObjectId [ ] ] > ( [
383+ test . each <
384+ [
385+ string ,
386+ {
387+ input : readonly ObjectIdConstructorParameter [ ] ;
388+ options ?: GetIdsOptions ;
389+ expected : readonly ObjectId [ ] ;
390+ } ,
391+ ]
392+ > ( [
384393 [
385394 'strings' ,
386- [ '123456789012345678900001' , '123456789012345678900002' ] ,
387- [ new ObjectId ( '123456789012345678900001' ) , new ObjectId ( '123456789012345678900002' ) ] ,
395+ {
396+ input : [ '123456789012345678900001' , '123456789012345678900002' ] ,
397+ expected : [
398+ new ObjectId ( '123456789012345678900001' ) ,
399+ new ObjectId ( '123456789012345678900002' ) ,
400+ ] ,
401+ } ,
388402 ] ,
389403 [
390- 'objectIds' ,
391- [ new ObjectId ( '123456789012345678900099' ) , new ObjectId ( '123456789012345678900022' ) ] ,
392- [ new ObjectId ( '123456789012345678900099' ) , new ObjectId ( '123456789012345678900022' ) ] ,
404+ 'ObjectIds' ,
405+ {
406+ input : [
407+ new ObjectId ( '123456789012345678900099' ) ,
408+ new ObjectId ( '123456789012345678900022' ) ,
409+ ] ,
410+ expected : [
411+ new ObjectId ( '123456789012345678900099' ) ,
412+ new ObjectId ( '123456789012345678900022' ) ,
413+ ] ,
414+ } ,
393415 ] ,
394416 [
395- 'Uint8Array' ,
396- [
397- new Uint8Array ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] ) ,
398- new Uint8Array ( [ 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ] )
399- ] ,
400- [ new ObjectId ( '0102030405060708090a0b0c' ) , new ObjectId ( '0d0e0f101112131415161718' ) ] ,
417+ 'Uint8Arrays' ,
418+ {
419+ input : [
420+ new Uint8Array ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] ) ,
421+ new Uint8Array ( [ 13 , 14 , 15 , 16 , 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ] ) ,
422+ ] ,
423+ expected : [
424+ new ObjectId ( '0102030405060708090a0b0c' ) ,
425+ new ObjectId ( '0d0e0f101112131415161718' ) ,
426+ ] ,
427+ } ,
401428 ] ,
402429 [
403430 'mixed' ,
404- [ '123456789012345678900014' , new ObjectId ( '123456789012345678900088' ) ] ,
405- [ new ObjectId ( '123456789012345678900014' ) , new ObjectId ( '123456789012345678900088' ) ] ,
431+ {
432+ input : [ '123456789012345678900014' , new ObjectId ( '123456789012345678900088' ) ] ,
433+ expected : [
434+ new ObjectId ( '123456789012345678900014' ) ,
435+ new ObjectId ( '123456789012345678900088' ) ,
436+ ] ,
437+ } ,
406438 ] ,
407439 [
408- 'invalid' ,
409- [ '123' , '123456789012345678900021' ] ,
410- [ new ObjectId ( '123456789012345678900021' ) ]
440+ 'invalid values, when filterInvalid is true' ,
441+ {
442+ input : [ '123' , '123456789012345678900021' ] ,
443+ options : { filterInvalid : true } ,
444+ expected : [ new ObjectId ( '123456789012345678900021' ) ] ,
445+ } ,
411446 ] ,
412- ] ) ( '%s' , ( _name , input , expected ) => {
447+ ] ) ( 'should return ObjectIds from %s' , ( _name , { input, options , expected } ) => {
413448 expect . assertions ( 4 ) ;
414449
415450 // Given
416451 expect ( expected . length ) . toBeLessThanOrEqual ( input . length ) ;
417452
418453 // When
419- const actual = getIds ( input ) ;
454+ const actual = getIds ( input , options ) ;
420455
421456 // Then
422457 expect ( actual ) . toEqual ( expected ) ;
@@ -429,5 +464,17 @@ describe('utils', () => {
429464 ) ;
430465 expect ( isEveryHexEquivalent ) . toBeTruthy ( ) ;
431466 } ) ;
467+
468+ test ( 'should throw on invalid values, when filterInvalid is unspecified' , ( ) => {
469+ expect . assertions ( 1 ) ;
470+
471+ // Given
472+ const input = [ '123' , '123456789012345678900021' ] ;
473+
474+ // When/Then
475+ expect ( ( ) => getIds ( input ) ) . toThrowErrorMatchingInlineSnapshot (
476+ '"input must be a 24 character hex string, 12 byte Uint8Array, or an integer"'
477+ ) ;
478+ } ) ;
432479 } ) ;
433480} ) ;
0 commit comments