@@ -71,6 +71,12 @@ describe("ElectronSafeStorage", () => {
7171 safeStorage . getSelectedStorageBackend . mockReturnValue ( "basic_text" ) ;
7272 safeStorage . isAsyncEncryptionAvailable . mockResolvedValue ( true ) ;
7373 safeStorage . isEncryptionAvailable . mockReturnValue ( false ) ;
74+ safeStorage . encryptString . mockImplementation ( ( ) => {
75+ throw new Error ( "Encryption is not available." ) ;
76+ } ) ;
77+ safeStorage . decryptString . mockImplementation ( ( ) => {
78+ throw new Error ( "Decryption is not available." ) ;
79+ } ) ;
7480 safeStorage . encryptStringAsync . mockResolvedValue ( Buffer . from ( "ciphertext" ) ) ;
7581 safeStorage . decryptStringAsync . mockResolvedValue ( {
7682 result : "secret" ,
@@ -79,8 +85,20 @@ describe("ElectronSafeStorage", () => {
7985 const storage = yield * ElectronSafeStorage . make ;
8086 assert . isFalse ( yield * storage . isEncryptionAvailable ) ;
8187
82- yield * Effect . exit ( storage . encryptString ( "secret" ) ) ;
83- yield * Effect . exit ( storage . decryptString ( Buffer . from ( "ciphertext" ) ) ) ;
88+ const encryptExit = yield * Effect . exit ( storage . encryptString ( "secret" ) ) ;
89+ const decryptExit = yield * Effect . exit ( storage . decryptString ( Buffer . from ( "ciphertext" ) ) ) ;
90+ assert . isTrue ( Exit . isFailure ( encryptExit ) ) ;
91+ assert . isTrue ( Exit . isFailure ( decryptExit ) ) ;
92+ if ( Exit . isFailure ( encryptExit ) && Exit . isFailure ( decryptExit ) ) {
93+ assert . instanceOf (
94+ Option . getOrThrow ( Cause . findErrorOption ( encryptExit . cause ) ) ,
95+ ElectronSafeStorage . ElectronSafeStorageEncryptError ,
96+ ) ;
97+ assert . instanceOf (
98+ Option . getOrThrow ( Cause . findErrorOption ( decryptExit . cause ) ) ,
99+ ElectronSafeStorage . ElectronSafeStorageDecryptError ,
100+ ) ;
101+ }
84102 assert . equal ( safeStorage . encryptStringAsync . mock . calls . length , 0 ) ;
85103 assert . equal ( safeStorage . decryptStringAsync . mock . calls . length , 0 ) ;
86104 } ) . pipe ( Effect . provideService ( HostProcess . Platform , "linux" ) ) ,
0 commit comments