import { expect } from 'chai' ; import { WebCryptoCachingMaterialsManager } from '../src/index' ; import { } from '@aws-crypto/cache-material' ; import { KeyringWebCrypto , WebCryptoDefaultCryptographicMaterialsManager , WebCryptoEncryptionMaterial , WebCryptoDecryptionMaterial , } from '@aws-crypto/material-management-browser' ; describe ( 'WebCryptoCachingMaterialsManager' , ( ) => { it ( 'constructor will decorate' , ( ) => { class TestKeyring extends KeyringWebCrypto { async _onEncrypt ( ) { throw new Error ( 'never' ) ; } async _onDecrypt ( ) { throw new Error ( 'never' ) ; } } const keyring = new TestKeyring ( ) ; const cache = 'cache' as any ; const partition = 'partition' ; const maxAge = 10 ; const maxBytesEncrypted = 11 ; const maxMessagesEncrypted = 12 ; const test = new WebCryptoCachingMaterialsManager ( { backingMaterials : keyring , cache , partition , maxAge , maxBytesEncrypted , maxMessagesEncrypted , } ) ; expect ( test . _backingMaterialsManager ) . to . be . instanceOf ( WebCryptoDefaultCryptographicMaterialsManager ) ; expect ( test ) . to . haveOwnPropertyDescriptor ( '_cache' , { value : cache , writable : false , enumerable : true , configurable : false , } ) ; expect ( test ) . to . haveOwnPropertyDescriptor ( '_partition' , { value : partition , writable : false , enumerable : true , configurable : false , } ) ; expect ( test ) . to . haveOwnPropertyDescriptor ( '_maxAge' , { value : maxAge , writable : false , enumerable : true , configurable : false , } ) ; expect ( test ) . to . haveOwnPropertyDescriptor ( '_maxBytesEncrypted' , { value : maxBytesEncrypted , writable : false , enumerable : true , configurable : false , } ) ; expect ( test ) . to . haveOwnPropertyDescriptor ( '_maxMessagesEncrypted' , { value : maxMessagesEncrypted , writable : false , enumerable : true , configurable : false , } ) ; } ) ; it ( 'Precondition: A partition value must exist for WebCryptoCachingMaterialsManager.' , ( ) => { class TestKeyring extends KeyringWebCrypto { async _onEncrypt ( ) { throw new Error ( 'never' ) ; } async _onDecrypt ( ) { throw new Error ( 'never' ) ; } } const keyring = new TestKeyring ( ) ; const cache = 'cache' as any ; const maxAge = 10 ; const test = new WebCryptoCachingMaterialsManager ( { backingMaterials : keyring , cache , maxAge , } ) ; expect ( test . _partition ) . to . be . a ( 'string' ) . and . to . have . lengthOf ( 88 ) ; } ) ; } ) ;