Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
ab0899b
initial
bourgeoa Apr 16, 2023
d84ea71
some lint
bourgeoa Apr 16, 2023
ec9e90b
updates
bourgeoa Apr 16, 2023
490a364
getBlankMsg
bourgeoa Apr 16, 2023
1911313
getPrivateKey
bourgeoa Apr 17, 2023
1d8b733
key exists
bourgeoa Apr 17, 2023
6df03c8
add first test
bourgeoa Apr 17, 2023
109c494
resolve typescript issues
bourgeoa Apr 17, 2023
2da93f8
tests generate keys with node crypto in setup
bourgeoa Apr 18, 2023
6c8461c
keys.test.ts
bourgeoa Apr 18, 2023
94b70b5
signature.test.ts
bourgeoa Apr 19, 2023
c5b2fb8
updates
bourgeoa Apr 21, 2023
20175fe
update package-lock.json
bourgeoa Apr 21, 2023
a5809dd
missing awaits
bourgeoa Apr 25, 2023
9f7a01d
package-lock.json
bourgeoa Apr 25, 2023
cd2500d
separated helpers for testing
SharonStrats Apr 26, 2023
5975073
updates message.js
bourgeoa Apr 26, 2023
8ec0833
refactored to smaller parts
SharonStrats Apr 27, 2023
9c84c1e
create keys and improvements
bourgeoa Apr 27, 2023
96e84cf
package-lock.json
bourgeoa Apr 27, 2023
2166356
update keyUrl with space:storage
bourgeoa Apr 29, 2023
eed9bea
add key container ACL
bourgeoa Apr 30, 2023
3652e5c
update setAcl key container
bourgeoa May 1, 2023
c239a13
trying to mock store fetcher load function
SharonStrats May 3, 2023
0ba702c
Update src/chat/keys.ts
bourgeoa May 3, 2023
ef25bb1
adding testing to docs
SharonStrats May 4, 2023
098e8a7
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 4, 2023
89f16fa
update get podRoot, use NamedNode
bourgeoa May 5, 2023
67289c6
Merge branch 'chat-proof' of https://github.com/solidos/solid-ui into…
bourgeoa May 5, 2023
8eed263
skip failing keys.test.ts
bourgeoa May 5, 2023
11c883a
mocked load
SharonStrats May 6, 2023
beea007
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 6, 2023
282702e
more cleaning
bourgeoa May 6, 2023
17005e6
Merge branch 'chat-proof' of https://github.com/solidos/solid-ui into…
bourgeoa May 6, 2023
0202734
more NamedNode
bourgeoa May 7, 2023
a6ef582
some cleaning
bourgeoa May 7, 2023
a573676
refactored function names
SharonStrats May 10, 2023
4370b23
added tests
SharonStrats May 10, 2023
0493bdd
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 10, 2023
69ecfab
created a keyhelper dir
SharonStrats May 10, 2023
18070a0
split files up for easier testing
SharonStrats May 10, 2023
aa51d1d
readmes for testing
SharonStrats May 10, 2023
830468e
key file tests
SharonStrats May 10, 2023
50ca84d
keys testing
SharonStrats May 10, 2023
a1b9ed4
updated testing readme
SharonStrats May 10, 2023
70090f2
added tests
SharonStrats May 17, 2023
27b35f4
acl refactor and tests
SharonStrats May 17, 2023
d02c4c2
key tests
SharonStrats May 17, 2023
f7310cd
fixed broken test
SharonStrats May 17, 2023
85020be
access data test
SharonStrats May 17, 2023
12e3adb
Update test/unit/README.md
SharonStrats May 17, 2023
3f1ead6
Update test/unit/README.md
SharonStrats May 17, 2023
90c87cc
Update test/unit/README.md
SharonStrats May 17, 2023
47a7934
Update test/unit/README.md
SharonStrats May 17, 2023
4bbe4cc
Update test/unit/README.md
SharonStrats May 17, 2023
0a40d64
Update test/unit/README.md
SharonStrats May 17, 2023
ea3f761
Update test/unit/README.md
SharonStrats May 17, 2023
15b7da3
rename deleteKey to deleteKeyAcl
bourgeoa May 18, 2023
7506217
getPodRoot returns NamedNode
bourgeoa May 18, 2023
998e1dd
move privateKey to /settings/keys/privateKey.ttl
bourgeoa May 18, 2023
cb30461
replace pop with slice
bourgeoa May 18, 2023
3576458
Update test/unit/README.md
SharonStrats May 20, 2023
d527997
testing
SharonStrats May 22, 2023
0829883
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 22, 2023
2da9b5c
remove testing debug msg
SharonStrats May 22, 2023
9ee704c
fix lint error
SharonStrats May 22, 2023
3d362e6
restore PUT on 404
bourgeoa May 24, 2023
027eefb
use solid ontology
bourgeoa May 24, 2023
840c347
removed commented out code
SharonStrats May 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ When you want to test the component within a solid-pane, you can use the [develo

## Adding Tests

Need to point to Unit test Readme.
The following document gives guidance on how to add and perform testing in solid-ui.
[Testing in solid-ui](https://github.com/SolidOS/solid-ui/blob/18070a02fa8159a2b83d9503ee400f8e046bf1f6/test/unit/README.md)

## Further documentation

Expand Down
10 changes: 7 additions & 3 deletions src/chat/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export function generatePublicKey (privateKey: string): string {
return bytesToHex(schnorr.getPublicKey(privateKey))
}

/**
* getPublicKey
* used for displaying messages in chat, therefore does not
* create a new key if not found
* @param webId
* @returns string | undefined
*/
export async function getPublicKey (webId: NamedNode) {
await store.fetcher.load(webId)
const publicKeyDoc = await pubKeyUrl(webId)
Expand All @@ -26,9 +33,6 @@ export async function getPublicKey (webId: NamedNode) {
} catch (err) {
return undefined
}
// this is called in display message and should not try to create a publicKeyDoc
// const publicKey = await publicKeyExists(webId)
// return publicKey
}

export async function getPrivateKey (webId: NamedNode) {
Expand Down
32 changes: 31 additions & 1 deletion test/unit/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
# Solid-UI Unit Testing
The purpose of this README is to provide guidance on how to write tests for solid-ui for beginners.

Although we would love to have 100% test coverage, we realize that this is not a commericial product. solid-ui is an open source, volunteer built library that houses UI components that can be used to build Solid applications. We are working to increase test coverage on existing code, any help is much appreciated. If you add a new component to solid-ui, you should write tests to test the main functionality of your component in order for your PR to be merged.

## Running Tests

### All
The following command will run all the tests.
`npm run test`

### One file at a time
There are a lot of tests in `solid-ui` so you will most likely want to run only the test you are working on at the moment. In order to do that you can use the following command.
`npm test <filetobetested>`
`npm test test/unit/utils/keyHelpers/accessData.test.ts`

### Coverage
Run the following command:
`npm run coverage`

Then you can see the results in `coverage/lcov-report/index.html`. If you are using VSCode you can right click and select to `Open in Browser Preview`. Otherwise, you can type the path in your browswer, for instance `file:///Users/<yourhomedirectory>/2023Development/solid-ui/coverage/lcov-report/index.html` is an example.

## Tips and Tricks
The following are some tips and tricks in hopes to make testing easier.

### VSCode Debugging
There is an extension that can be used to aide in debugging jest tests. To find out more about it you can look at [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner)

### Mocking
In solid-ui we do not currently follow a MVC pattern therefore there can be some difficulty in testing. The following are patterns to help with this.
#### Store methods
##### Load
In SolidOS we use [rdflib.js](https://github.com/linkeddata/rdflib.js/) to work with LinkedData. The way this works is that you first load the document you need to work with into the store. Once the document is loaded you can then access the data by using additional methods on the store such as `any, each,...`. Since the data that gets returned will need to be mocked, `load` doesn't need to do anything. See below for what you need to put in the top of your file in order to mock the `load` method.
`import { store } from 'solid-logic'` at the top of your file.

`store.fetcher.load = jest.fn().mockImplementation(() => {})`

### Mock the fetcher
##### Any

##### Each
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### Any
##### Each
##### `Any`
##### `Each`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TallTed thank you for all the corrections.

35 changes: 21 additions & 14 deletions test/unit/chat/keys.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { error, log, trace, warn } from '../../src/debug'
import { generatePrivateKey, generatePublicKey, getPublicKey } from '../../../src/chat/keys'
import Fetcher from 'rdflib/lib/fetcher'
import { solidLogicSingleton } from 'solid-logic'
// import * as helpers from '../../../src/utils/cryptoKeyHelpers'
import { store } from 'solid-logic'
import { NamedNode } from 'rdflib'
import * as helpers from '../../../src/utils/keyHelpers/accessData'
const PRIV_KEY = 'a11bc5d2eee6cdb3b37f5473a712cad905ccfb13fb2ccdbf1be0a1ac4fdc7d2a'
const PUB_KEY = '023a9da707bee1302f66083c9d95673ff969b41607a66f52686fa774d64ceb87'

const store = solidLogicSingleton
// jest.mock('../../../src/utils/cryptoKeyHelpers')

// @ts-ignore
// store.fetcher.load = jest.fn().mockImplementation(() => {}) as unknown as Fetcher

// @ts-ignore
// jest.spyOn('helpers', 'pubKeyUrl').mockImplementation(() => 'test')
jest.mock('../../../src/utils/keyHelpers/accessData')
store.fetcher.load = jest.fn().mockImplementation(() => {})
store.any = jest.fn()

describe('generate key pair', () => {
// console.log('alain')
Expand All @@ -29,7 +23,20 @@ describe('generate key pair', () => {
})

describe('getPublicKey', () => {
it.skip('should do something', async () => {
expect(await getPublicKey('https://sstratsianis.solidcommunity.net/profile/card#me')).toThrowError()
const webId = new NamedNode('https://alice.solidcommunity.net/profile/card#me')
it('should return the key', async () => {
/* @ts-ignore */
jest.spyOn(helpers, 'pubKeyUrl').mockResolvedValue('https://alice.solidcommunity.net/profile/keys/publicKey.ttl')
/* @ts-ignore */
store.any.mockReturnValue({ value: PUB_KEY })
const webId = new NamedNode('https://alice.solidcommunity.net/profile/card#me')
const result = await getPublicKey(webId)
expect(result).toBe(PUB_KEY)
})
it.skip('should return undefined if loading and retrieving key fails', async () => {
jest.spyOn(helpers, 'pubKeyUrl').mockResolvedValue('https://alice.solidcommunity.net/profile/keys/publicKey.ttl')
/* @ts-ignore */
store.any.mockRejectedValue()
expect(await getPublicKey(webId)).rejects.toThrowError()
})
})
18 changes: 15 additions & 3 deletions test/unit/utils/keyHelpers/acl.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
describe('acl Helpers', () => {
describe.skip('setAcl', () => {
it.skip('not sure yet', () => {
import { store } from 'solid-logic'
import { setAcl, keyAclBody } from '../../../../src/utils/keyHelpers/acl'

store.fetcher.load = jest.fn().mockImplementation(() => {})
store.any = jest.fn()

describe('ACL Helpers', () => {
describe('setAcl', () => {
it('throws an error if an ACL document is NOT found', async () => {
/* @ts-ignore */
store.any.mockReturnValue('')
const keyDoc = 'https://alice.solidcommunity.net/profile/keys/publicKey.ttl'
await expect(setAcl(keyDoc, keyAclBody(keyDoc, ''))).rejects.toThrowError('Key ACL doc not found!')
})
it.skip('want to find out why we delete and then re-add', () => {

})
})
Expand Down