11import { store } from 'solid-logic'
2- import Fetcher from 'rdflib/lib/fetcher'
32import { getKeyIfExists , pubKeyUrl , privKeyUrl , getExistingPublicKey , getExistingPrivateKey } from '../../../../src/utils/keyHelpers/accessData'
43import { NamedNode } from 'rdflib'
54
@@ -13,64 +12,37 @@ store.fetcher.webOperation = jest.fn()
1312store . each = jest . fn ( )
1413store . any = jest . fn ( )
1514
16- describe ( 'cryptoKeyHelpers' , ( ) => {
17- describe . skip ( 'pubKeyUrl' , ( ) => {
18- // want to check a success and an error
19- it ( 'returns the url for the public key' , ( ) => {
20- const webId = new NamedNode ( 'https://alice.solid.example/profile/card#me' )
21- const result = pubKeyUrl ( webId )
22- expect ( result ) . toEqual ( 'https://alice.solid.example/profile/keys/publicKey.ttl' )
23- } )
24- } )
25-
26- describe ( 'getExistingPrivateKey' , ( ) => {
27- // want to make sure that getKeyIfExists is called with correct parameters
28- it ( 'returns...' , ( ) => {
29-
30- } )
31- } )
32- describe ( 'privateKeyExists' , ( ) => {
33- // want to make sure that getKeyIfExists is called with correct parameters
34- it ( 'returns...' , ( ) => {
15+ jest . mock ( '../../../../src/utils/keyHelpers/otherHelpers' , ( ) => {
16+ return {
17+ getRootIfPreferencesExist : jest . fn ( ) . mockImplementationOnce ( ( ) => {
18+ throw new Error ( )
19+ } )
20+ . mockImplementationOnce ( ( ) => 'https://alice.example.net' )
21+ . mockImplementationOnce ( ( ) => {
22+ throw new Error ( )
23+ } )
24+ . mockImplementationOnce ( ( ) => 'https://alice.example.net' )
25+ }
26+ } )
3527
28+ describe ( 'accessData' , ( ) => {
29+ const webId = new NamedNode ( 'https://alice.solid.example.net/profile/card#me' )
30+ describe ( 'pubKeyUrl' , ( ) => {
31+ it ( 'to return undefined if there is not preference file' , ( ) => {
32+ expect ( pubKeyUrl ( webId ) ) . toEqual ( undefined )
3633 } )
37- } )
38- describe . skip ( 'privKeyUrl' , ( ) => {
39- it ( 'returns...' , ( ) => {
40- const result = privKeyUrl ( new NamedNode ( 'https://alice.solid.example/profile/card#me' ) )
41- expect ( result ) . toEqual ( 'https://alice.solid.example/settings/keys/privateKey.ttl' )
34+ it ( 'returns the url for the public key' , ( ) => {
35+ const result = pubKeyUrl ( webId )
36+ expect ( result ) . toEqual ( 'https://alice.example.net/profile/keys/publicKey.ttl' )
4237 } )
4338 } )
44-
45- /* describe('getPodRoot', () => {
46- /* @ts -ignore */
47- // store.fetcher.webOperation.mockImplementationOnce(() => {})
48- /* @ts -ignore */
49- /* store.each.mockImplementationOnce(() => [{ value: 'https://alice.solid.example' }])
50- it('returns...', async () => {
51- const webId = new NamedNode('https://alice.solid.example/profile/card#me')
52- const result = await getPodRoot(webId)
53- expect(result.value).toBe('https://alice.solid.example')
54- })
55- }) */
56- describe ( 'getKeyIfExists' , ( ) => {
57- /* @ts -ignore */
58- store . any . mockReturnValue ( { value : PUB_KEY } )
59- it ( 'returns a key if it exists' , async ( ) => {
60- const webId = new NamedNode ( 'https://alice.solid.example/profile/card#me' )
61- const result = await getKeyIfExists ( webId , PUB_KEY , 'publicKey' )
62- expect ( result ) . toBe ( PUB_KEY )
63- } )
64- it . skip ( 'throws an error when load fails' , async ( ) => {
65- // need to check if 'any' can throw an error
66- const webId = new NamedNode ( 'https://alice.solid.example/profile/card#me' )
67- const result = await getKeyIfExists ( webId , 'testing' , 'publicKey' )
68- expect ( result ) . toBe ( 'testing' )
39+ describe ( 'privKeyUrl' , ( ) => {
40+ it ( 'to return undefined if there is not preference file' , ( ) => {
41+ expect ( privKeyUrl ( webId ) ) . toEqual ( undefined )
6942 } )
70- it . skip ( 'returns undefined if key not found' , async ( ) => {
71- const webId = new NamedNode ( 'https://alice.solid.example/profile/card#me' )
72- const result = await getKeyIfExists ( webId , PUB_KEY , 'publicKey' )
73- expect ( result ) . toBe ( PUB_KEY )
43+ it ( 'returns the url for the private key' , ( ) => {
44+ const result = privKeyUrl ( webId )
45+ expect ( result ) . toEqual ( 'https://alice.example.net/keys/privateKey.ttl' )
7446 } )
7547 } )
7648} )
0 commit comments