Skip to content

Commit 50ca84d

Browse files
committed
keys testing
1 parent 830468e commit 50ca84d

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

src/chat/keys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function generatePublicKey (privateKey: string): string {
1818

1919
/**
2020
* getPublicKey
21-
* used for displaying messages in chat, therefore does not
21+
* used for displaying messages in chat, therefore does not
2222
* create a new key if not found
2323
* @param webId
2424
* @returns string | undefined

test/unit/chat/keys.test.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { generatePrivateKey, generatePublicKey, getPublicKey } from '../../../src/chat/keys'
22
import { 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'
45
const PRIV_KEY = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
56
const PUB_KEY = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'
67

7-
// jest.mock('../../../src/utils/cryptoKeyHelpers')
8+
jest.mock('../../../src/utils/keyHelpers/accessData')
89
store.fetcher.load = jest.fn().mockImplementation(() => {})
9-
10-
// @ts-ignore
11-
// jest.spyOn('helpers', 'pubKeyUrl').mockImplementation(() => 'test')
10+
store.any = jest.fn()
1211

1312
describe('generate key pair', () => {
1413
// console.log('alain')
@@ -24,10 +23,24 @@ describe('generate key pair', () => {
2423
})
2524

2625
describe('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

Comments
 (0)