forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrustedApplications.test.ts
More file actions
78 lines (70 loc) · 2.74 KB
/
Copy pathtrustedApplications.test.ts
File metadata and controls
78 lines (70 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* eslint-env jest */
import * as $rdf from 'rdflib'
import solidNamespace from 'solid-namespace'
import { generateRandomString, getStatementsToDelete, getStatementsToAdd } from './trustedApplications.utils'
const ns = solidNamespace($rdf)
describe('generateRandomString', () => {
it('generates a random string five characters long', () => {
expect(generateRandomString().length).toBe(5)
})
})
describe('getStatementsToDelete', () => {
it('should return an empty array when there are no statements', () => {
const mockStore = $rdf.graph()
const mockOrigin = $rdf.sym('https://origin.example')
const mockProfile = $rdf.sym('https://profile.example#me')
expect(
getStatementsToDelete(mockOrigin, mockProfile, mockStore, ns)
).toEqual([])
})
it('should return all statements for the given origin', () => {
const mockStore = $rdf.graph()
const mockApplication = $rdf.sym('https://app.example')
const mockOrigin = $rdf.sym('https://origin.example')
const mockProfile = $rdf.sym('https://profile.example#me')
mockStore.add(mockApplication, ns.acl('origin'), mockOrigin)
mockStore.add(mockApplication, ns.acl('mode'), ns.acl('Read'))
mockStore.add(mockProfile, ns.acl('trustedApp'), mockApplication)
const statementsToDelete = getStatementsToDelete(
mockOrigin,
mockProfile,
mockStore,
ns
)
expect(statementsToDelete.length).toBe(3)
expect(statementsToDelete).toMatchSnapshot()
})
it('should not return statements for a different origin', () => {
const mockStore = $rdf.graph()
const mockApplication = $rdf.sym('https://app.example')
const mockOrigin = $rdf.sym('https://origin.example')
const mockProfile = $rdf.sym('https://profile.example#me')
mockStore.add(mockApplication, ns.acl('origin'), mockOrigin)
mockStore.add(mockApplication, ns.acl('mode'), ns.acl('Read'))
mockStore.add(mockProfile, ns.acl('trustedApp'), mockApplication)
const statementsToDelete = getStatementsToDelete(
$rdf.lit('A different origin'), // @@ TODO Remove casting
mockProfile,
mockStore,
ns
)
expect(statementsToDelete.length).toBe(0)
expect(statementsToDelete).toEqual([])
})
})
describe('getStatementsToAdd', () => {
it('should return all required statements to add the given permissions for a given origin', () => {
const mockOrigin = $rdf.sym('https://origin.example')
const mockProfile = $rdf.sym('https://profile.example#me')
const modes = [ns.acl('Read').value, ns.acl('Write').value]
const statementsToAdd = getStatementsToAdd(
mockOrigin,
'mock_app_id',
modes,
mockProfile,
ns
)
expect(statementsToAdd.length).toBe(4)
expect(statementsToAdd).toMatchSnapshot()
})
})