@@ -200,4 +200,43 @@ describe('UUID', () => {
200200 expect ( deserializedUUID ) . to . deep . equal ( expectedResult ) ;
201201 } ) ;
202202 } ) ;
203+
204+ context ( 'createFromHexString()' , ( ) => {
205+ context ( 'when called with a hex sequence' , ( ) => {
206+ it ( 'returns a UUID instance with the decoded bytes' , ( ) => {
207+ const bytes = Buffer . from ( UPPERCASE_VALUES_ONLY_UUID_STRING , 'hex' ) ;
208+
209+ const uuidDashed = UUID . createFromHexString ( UPPERCASE_DASH_SEPARATED_UUID_STRING ) ;
210+ expect ( uuidDashed ) . to . have . deep . property ( 'buffer' , bytes ) ;
211+ expect ( uuidDashed ) . to . be . instanceOf ( UUID ) ;
212+
213+ const uuidNoDashed = UUID . createFromHexString ( UPPERCASE_VALUES_ONLY_UUID_STRING ) ;
214+ expect ( uuidNoDashed ) . to . have . deep . property ( 'buffer' , bytes ) ;
215+ expect ( uuidNoDashed ) . to . be . instanceOf ( UUID ) ;
216+ } ) ;
217+ } ) ;
218+
219+ context ( 'when called with an incorrect length string' , ( ) => {
220+ it ( 'throws an error indicating the expected length of 32 or 36 characters' , ( ) => {
221+ expect ( ( ) => UUID . createFromHexString ( '' ) ) . to . throw ( / 3 2 o r 3 6 c h a r a c t e r / ) ;
222+ } ) ;
223+ } ) ;
224+ } ) ;
225+
226+ context ( 'createFromBase64()' , ( ) => {
227+ context ( 'when called with a base64 sequence' , ( ) => {
228+ it ( 'returns a UUID instance with the decoded bytes' , ( ) => {
229+ const bytes = Buffer . from ( UPPERCASE_VALUES_ONLY_UUID_STRING , 'hex' ) ;
230+ const uuid = UUID . createFromBase64 ( bytes . toString ( 'base64' ) ) ;
231+ expect ( uuid ) . to . have . deep . property ( 'buffer' , bytes ) ;
232+ expect ( uuid ) . to . be . instanceOf ( UUID ) ;
233+ } ) ;
234+ } ) ;
235+
236+ context ( 'when called with an incorrect length string' , ( ) => {
237+ it ( 'throws an error indicating the expected length of 16 byte Buffer' , ( ) => {
238+ expect ( ( ) => UUID . createFromBase64 ( '' ) ) . to . throw ( / 1 6 b y t e B u f f e r / ) ;
239+ } ) ;
240+ } ) ;
241+ } ) ;
203242} ) ;
0 commit comments