11import { generatePrivateKey , generatePublicKey , getPublicKey } from '../../../src/chat/keys'
22import { store } from 'solid-logic'
3- // import * as helpers from '../../../src/utils/cryptoKeyHelpers'
3+ import { NamedNode } from 'rdflib'
4+ import * as helpers from '../../../src/utils/keyHelpers/accessData'
45const PRIV_KEY = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
56const PUB_KEY = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
67
7- // jest.mock('../../../src/utils/cryptoKeyHelpers ')
8+ jest . mock ( '../../../src/utils/keyHelpers/accessData ' )
89store . fetcher . load = jest . fn ( ) . mockImplementation ( ( ) => { } )
9-
10- // @ts -ignore
11- // jest.spyOn('helpers', 'pubKeyUrl').mockImplementation(() => 'test')
10+ store . any = jest . fn ( )
1211
1312describe ( 'generate key pair' , ( ) => {
1413 // console.log('alain')
@@ -24,10 +23,24 @@ describe('generate key pair', () => {
2423} )
2524
2625describe ( 'getPublicKey' , ( ) => {
26+ const webId = new NamedNode ( 'https://alice.solidcommunity.net/profile/card#me' )
2727 it ( 'should return the key' , async ( ) => {
28- expect ( await getPublicKey ( 'https://sstratsianis.solidcommunity.net/profile/card#me' ) ) . toThrowError ( )
28+ /* @ts -ignore */
29+ jest . spyOn ( helpers , 'pubKeyUrl' ) . mockResolvedValue ( 'https://alice.solidcommunity.net/profile/keys/publicKey.ttl' )
30+ /* @ts -ignore */
31+ store . any . mockReturnValue ( { value : PUB_KEY } )
32+ const webId = new NamedNode ( 'https://alice.solidcommunity.net/profile/card#me' )
33+ const result = await getPublicKey ( webId )
34+ expect ( result ) . toBe ( PUB_KEY )
2935 } )
30- it ( 'should return undefined if loading and retrieving key fails' , async ( ) => {
31- expect ( await getPublicKey ( 'https://sstratsianis.solidcommunity.net/profile/card#me' ) ) . toThrowError ( )
36+ it . skip ( 'should return undefined if loading and retrieving key fails' , async ( ) => {
37+ jest . spyOn ( helpers , 'pubKeyUrl' ) . mockResolvedValue ( 'https://alice.solidcommunity.net/profile/keys/publicKey.ttl' )
38+ /* @ts -ignore */
39+ store . any . mockRejectedValue ( )
40+ try {
41+ await getPublicKey ( webId )
42+ } catch ( err ) {
43+ expect ( err ) . toBe ( undefined )
44+ }
3245 } )
3346} )
0 commit comments