import { DecryptableKey, OrganizationPrivateKey, NotDecryptableKey, SubKey } from './keys.data';
import { prepareKeys } from '../../lib/keys/keys';

describe('keys', () => {
    it('should prepare keys', async () => {
        const preparedKeys = await prepareKeys({
            Keys: [DecryptableKey, NotDecryptableKey],
            keyPassword: '123'
        });

        expect(preparedKeys)
            .toEqual([
                {
                    Key: DecryptableKey,
                    privateKey: jasmine.any(Object)
                },
                {
                    Key: NotDecryptableKey,
                    privateKey: jasmine.any(Object)
                }
            ]);

        expect(preparedKeys[0].privateKey.isDecrypted()).toBeTruthy();
        expect(preparedKeys[1].privateKey.isDecrypted()).toBeFalsy();
    });

    it('should prepare the keys if a subuser', async () => {
        const preparedKeys = await prepareKeys({
            Keys: [SubKey],
            keyPassword: '123',
            OrganizationPrivateKey
        });

        expect(preparedKeys)
            .toEqual([{
                Key: SubKey,
                privateKey: jasmine.any(Object)
            }]);

        expect(preparedKeys[0].privateKey.isDecrypted()).toBeTruthy();
    });
});

@@ -1,16 +1,63 @@
+import %7B decryptPrivateKey %7D from 'pmcrypto';%0A%0A
 import %7B Decrypt
@@ -157,16 +157,35 @@
 pareKeys
+, prepareMemberKeys
  %7D from 
@@ -324,36 +324,16 @@
 areKeys(
-%7B%0A            Keys: 
 %5BDecrypt
@@ -364,49 +364,14 @@
 ey%5D,
-%0A            keyPassword: '123'%0A        %7D
+ '123'
 );%0A%0A
@@ -394,37 +394,24 @@
 reparedKeys)
-%0A            
 .toEqual(%5B%0A 
@@ -413,36 +413,32 @@
 l(%5B%0A            
-    
 %7B%0A              
@@ -435,28 +435,24 @@
             
- 
-   
 Key: Decrypt
@@ -452,36 +452,32 @@
 DecryptableKey,%0A
-    
                 
@@ -520,20 +520,16 @@
         
-   
- 
 %7D,%0A     
@@ -531,34 +531,26 @@
             
-    %7B%0A    
+%7B%0A
             
@@ -585,36 +585,32 @@
                 
-  
-  
 privateKey: jasm
@@ -641,18 +641,10 @@
     
-    %7D%0A    
+%7D%0A
     
@@ -873,36 +873,30 @@
       const 
-prepared
+org
 Key
-s
  = await pre
@@ -896,40 +896,111 @@
 ait 
-prepareKeys(%7B%0A            
+decryptPrivateKey(OrganizationPrivateKey, '123');%0A        const preparedKeys = await prepareMember
 Keys
-: 
+(
 %5BSub
@@ -1008,85 +1008,15 @@
 ey%5D,
-%0A            keyPassword: '123',%0A            OrganizationPrivateKey%0A        %7D
+ orgKey
 );%0A%0A
@@ -1043,16 +1043,26 @@
 redKeys)
+.toEqual(%5B
 %0A       
@@ -1066,26 +1066,16 @@
         
-.toEqual(%5B
 %7B%0A      
@@ -1158,16 +1158,25 @@
        %7D
+%0A        
 %5D);%0A%0A   

Fix test