import { hash as hashFunction } from '../src/hash' ; import { expect } from 'chai' ; describe ( 'hash' , ( ) => { const defaultText = 'text123*' ; let arrayToHash ; let defaultHash ; beforeEach ( ( ) => { defaultHash = Buffer . from ( '7607d6792843d6003c12495b54e34517a508d2a8622526aff1884422c5478971' , 'hex' ) ; arrayToHash = [ 1 , 2 , 3 ] ; return Promise . resolve ( ) ; } ) ; it ( 'should generate a sha256 hash from a Buffer' , ( ) => { const testBuffer = Buffer . from ( defaultText ) ; const hash = hashFunction ( testBuffer ) ; return expect ( hash ) . to . be . eql ( defaultHash ) ; } ) ; it ( 'should generate a sha256 hash from a utf8 string' , ( ) => { const hash = hashFunction ( defaultText , 'utf8' ) ; return expect ( hash ) . to . be . eql ( defaultHash ) ; } ) ; it ( 'should generate a sha256 hash from a hex string' , ( ) => { const testHex = Buffer . from ( defaultText ) . toString ( 'hex' ) ; const hash = hashFunction ( testHex , 'hex' ) ; return expect ( hash ) . to . be . eql ( defaultHash ) ; } ) ; it ( 'should throw on unknown format when trying a string with format "utf32"' , ( ) => { return expect ( hashFunction . bind ( null , defaultText , 'utf32' ) ) . to . throw ( 'Unsupported string format. Currently only `hex` and `utf8` are supported.' ) ; } ) ; it ( 'should throw on unknown format when using an array' , ( ) => { return expect ( hashFunction . bind ( null , arrayToHash ) ) . to . throw ( 'Unsupported data format. Currently only Buffers or `hex` and `utf8` strings are supported.' ) ; } ) ; } ) ;