@@ -63,9 +63,42 @@ describe('UUID', () => {
63
63
expect ( ( ) => new UUID ( { } ) ) . to . throw ( BSONError ) ;
64
64
} ) ;
65
65
66
- it ( 'should correctly check if a buffer isValid' , ( ) => {
67
- const validBuffer = Buffer . from ( UPPERCASE_VALUES_ONLY_UUID_STRING , 'hex' ) ;
68
- expect ( UUID . isValid ( validBuffer ) ) . to . be . true ;
66
+ context ( 'isValid()' , ( ) => {
67
+ it ( 'returns true for hex string with dashes' , ( ) => {
68
+ expect ( UUID . isValid ( UPPERCASE_VALUES_ONLY_UUID_STRING ) ) . to . be . true ;
69
+ } ) ;
70
+
71
+ it ( 'returns true for hex string without dashes' , ( ) => {
72
+ expect ( UUID . isValid ( LOWERCASE_VALUES_ONLY_UUID_STRING ) ) . to . be . true ;
73
+ } ) ;
74
+
75
+ it ( 'returns true for hex string that is not uuid v4' , ( ) => {
76
+ expect ( UUID . isValid ( '00' . repeat ( 16 ) ) ) . to . be . true ;
77
+ } ) ;
78
+
79
+ it ( 'returns true for buffer of length 16' , ( ) => {
80
+ expect ( UUID . isValid ( Buffer . alloc ( 16 ) ) ) . to . be . true ;
81
+ } ) ;
82
+
83
+ it ( 'returns false for buffer not of length 16' , ( ) => {
84
+ expect ( UUID . isValid ( Buffer . alloc ( 10 ) ) ) . to . be . false ;
85
+ } ) ;
86
+
87
+ it ( 'returns false for falsy inputs' , ( ) => {
88
+ expect ( UUID . isValid ( ) ) . to . be . false ;
89
+ expect ( UUID . isValid ( null ) ) . to . be . false ;
90
+ expect ( UUID . isValid ( false ) ) . to . be . false ;
91
+ expect ( UUID . isValid ( '' ) ) . to . be . false ;
92
+ } ) ;
93
+
94
+ it ( 'returns true for Binary instances of UUID' , ( ) => {
95
+ expect ( UUID . isValid ( new UUID ( ) ) ) . to . be . true ;
96
+ expect ( UUID . isValid ( Binary . createFromHexString ( '00' . repeat ( 16 ) , 4 ) ) ) . to . be . true ;
97
+ } ) ;
98
+
99
+ it ( 'returns false for Binary instance of the wrong length' , ( ) => {
100
+ expect ( UUID . isValid ( Binary . createFromHexString ( '00' , 4 ) ) ) . to . be . false ;
101
+ } ) ;
69
102
} ) ;
70
103
71
104
it ( 'should correctly convert to and from a Binary instance' , ( ) => {
0 commit comments