solid-logic 3.0.9-15abc0b → 3.0.9-22c8d8a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -2
- package/dist/solid-logic.js +35 -0
- package/dist/solid-logic.js.map +1 -0
- package/package.json +11 -4
- package/babel.config.js +0 -6
- package/eslint.config.js +0 -28
- package/jest.config.js +0 -17
- package/lib/solid-logic.js +0 -107
- package/lib/solid-logic.js.map +0 -1
- package/rollup.config.js +0 -29
- package/src/acl/aclLogic.ts +0 -156
- package/src/authSession/authSession.ts +0 -13
- package/src/authn/SolidAuthnLogic.ts +0 -126
- package/src/authn/authUtil.ts +0 -70
- package/src/chat/chatLogic.ts +0 -226
- package/src/inbox/inboxLogic.ts +0 -59
- package/src/index.ts +0 -21
- package/src/issuer/issuerLogic.ts +0 -40
- package/src/logic/CustomError.ts +0 -29
- package/src/logic/solidLogic.ts +0 -76
- package/src/logic/solidLogicSingleton.ts +0 -20
- package/src/profile/profileLogic.ts +0 -125
- package/src/typeIndex/typeIndexLogic.ts +0 -198
- package/src/types.ts +0 -122
- package/src/util/containerLogic.ts +0 -53
- package/src/util/debug.ts +0 -16
- package/src/util/ns.ts +0 -5
- package/src/util/utilityLogic.ts +0 -156
- package/src/util/utils.ts +0 -52
- package/src/versionInfo.ts +0 -32
- package/test/aclLogic.test.ts +0 -24
- package/test/authUtil.test.ts +0 -23
- package/test/chatLogic.test.ts +0 -322
- package/test/container.test.ts +0 -58
- package/test/helpers/dataSetup.ts +0 -135
- package/test/helpers/setup.ts +0 -22
- package/test/inboxLogic.test.ts +0 -209
- package/test/logic.test.ts +0 -29
- package/test/profileLogic.test.ts +0 -248
- package/test/solidAuthLogic.test.ts +0 -49
- package/test/typeIndexLogic.test.ts +0 -255
- package/test/utilityLogic.test.ts +0 -180
- package/test/utils.test.ts +0 -32
- package/timestamp.sh +0 -13
- package/tsconfig.json +0 -77
- package/tsconfig.test.json +0 -8
- /package/{lib → dist}/acl/aclLogic.d.ts +0 -0
- /package/{lib → dist}/acl/aclLogic.d.ts.map +0 -0
- /package/{lib → dist}/authSession/authSession.d.ts +0 -0
- /package/{lib → dist}/authSession/authSession.d.ts.map +0 -0
- /package/{lib → dist}/authn/SolidAuthnLogic.d.ts +0 -0
- /package/{lib → dist}/authn/SolidAuthnLogic.d.ts.map +0 -0
- /package/{lib → dist}/authn/authUtil.d.ts +0 -0
- /package/{lib → dist}/authn/authUtil.d.ts.map +0 -0
- /package/{lib → dist}/chat/chatLogic.d.ts +0 -0
- /package/{lib → dist}/chat/chatLogic.d.ts.map +0 -0
- /package/{lib → dist}/inbox/inboxLogic.d.ts +0 -0
- /package/{lib → dist}/inbox/inboxLogic.d.ts.map +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/index.d.ts.map +0 -0
- /package/{lib → dist}/issuer/issuerLogic.d.ts +0 -0
- /package/{lib → dist}/issuer/issuerLogic.d.ts.map +0 -0
- /package/{lib → dist}/logic/CustomError.d.ts +0 -0
- /package/{lib → dist}/logic/CustomError.d.ts.map +0 -0
- /package/{lib → dist}/logic/solidLogic.d.ts +0 -0
- /package/{lib → dist}/logic/solidLogic.d.ts.map +0 -0
- /package/{lib → dist}/logic/solidLogicSingleton.d.ts +0 -0
- /package/{lib → dist}/logic/solidLogicSingleton.d.ts.map +0 -0
- /package/{lib → dist}/profile/profileLogic.d.ts +0 -0
- /package/{lib → dist}/profile/profileLogic.d.ts.map +0 -0
- /package/{lib → dist}/typeIndex/typeIndexLogic.d.ts +0 -0
- /package/{lib → dist}/typeIndex/typeIndexLogic.d.ts.map +0 -0
- /package/{lib → dist}/types.d.ts +0 -0
- /package/{lib → dist}/types.d.ts.map +0 -0
- /package/{lib → dist}/util/containerLogic.d.ts +0 -0
- /package/{lib → dist}/util/containerLogic.d.ts.map +0 -0
- /package/{lib → dist}/util/debug.d.ts +0 -0
- /package/{lib → dist}/util/debug.d.ts.map +0 -0
- /package/{lib → dist}/util/ns.d.ts +0 -0
- /package/{lib → dist}/util/ns.d.ts.map +0 -0
- /package/{lib → dist}/util/utilityLogic.d.ts +0 -0
- /package/{lib → dist}/util/utilityLogic.d.ts.map +0 -0
- /package/{lib → dist}/util/utils.d.ts +0 -0
- /package/{lib → dist}/util/utils.d.ts.map +0 -0
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
import { UpdateManager, Store, Fetcher } from 'rdflib'
|
|
6
|
-
import { createProfileLogic } from '../src/profile/profileLogic'
|
|
7
|
-
import { createUtilityLogic } from '../src/util/utilityLogic'
|
|
8
|
-
import { ns } from '../src/util/ns'
|
|
9
|
-
import {
|
|
10
|
-
alice, AlicePreferencesFile, AlicePrivateTypeIndex, AliceProfileFile, bob, boby, loadWebObject
|
|
11
|
-
} from './helpers/dataSetup'
|
|
12
|
-
import { createAclLogic } from '../src/acl/aclLogic'
|
|
13
|
-
import { createContainerLogic } from '../src/util/containerLogic'
|
|
14
|
-
|
|
15
|
-
const prefixes = Object.keys(ns).map(prefix => `@prefix ${prefix}: ${ns[prefix]('')}.\n`).join('') // In turtle
|
|
16
|
-
const user = alice
|
|
17
|
-
const profile = user.doc()
|
|
18
|
-
let requests: Request[] = []
|
|
19
|
-
let profileLogic
|
|
20
|
-
|
|
21
|
-
describe('Profile', () => {
|
|
22
|
-
|
|
23
|
-
describe('loadProfile', () => {
|
|
24
|
-
window.$SolidTestEnvironment = { username: alice.uri }
|
|
25
|
-
let store
|
|
26
|
-
requests = []
|
|
27
|
-
const statustoBeReturned = 200
|
|
28
|
-
let web = {}
|
|
29
|
-
const authn = {
|
|
30
|
-
currentUser: () => {
|
|
31
|
-
return alice
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
fetchMock.resetMocks()
|
|
36
|
-
web = loadWebObject()
|
|
37
|
-
requests = []
|
|
38
|
-
fetchMock.mockIf(/^https?.*$/, async req => {
|
|
39
|
-
|
|
40
|
-
if (req.method !== 'GET') {
|
|
41
|
-
requests.push(req)
|
|
42
|
-
if (req.method === 'PUT') {
|
|
43
|
-
const contents = await req.text()
|
|
44
|
-
web[req.url] = contents // Update our dummy web
|
|
45
|
-
console.log(`Tetst: Updated ${req.url} on PUT to <<<${web[req.url]}>>>`)
|
|
46
|
-
}
|
|
47
|
-
return { status: statustoBeReturned }
|
|
48
|
-
}
|
|
49
|
-
const contents = web[req.url]
|
|
50
|
-
if (contents !== undefined) { //
|
|
51
|
-
return {
|
|
52
|
-
body: prefixes + contents, // Add namespaces to anything
|
|
53
|
-
status: 200,
|
|
54
|
-
headers: {
|
|
55
|
-
'Content-Type': 'text/turtle',
|
|
56
|
-
'WAC-Allow': 'user="write", public="read"',
|
|
57
|
-
'Accept-Patch': 'application/sparql-update'
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
} // if contents
|
|
61
|
-
return {
|
|
62
|
-
status: 404,
|
|
63
|
-
body: 'Not Found'
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
store = new Store()
|
|
68
|
-
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
69
|
-
store.updater = new UpdateManager(store)
|
|
70
|
-
const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
|
|
71
|
-
profileLogic = createProfileLogic(store, authn, util)
|
|
72
|
-
})
|
|
73
|
-
it('exists', () => {
|
|
74
|
-
expect(profileLogic.loadProfile).toBeInstanceOf(Function)
|
|
75
|
-
})
|
|
76
|
-
it('loads data', async () => {
|
|
77
|
-
const result = await profileLogic.loadProfile(user)
|
|
78
|
-
expect(result).toBeInstanceOf(Object)
|
|
79
|
-
expect(result.uri).toEqual(AliceProfileFile.uri)
|
|
80
|
-
expect(store.holds(user, ns.rdf('type'), ns.vcard('Individual'), profile)).toEqual(true)
|
|
81
|
-
expect(store.holds(user, ns.space('preferencesFile'), AlicePreferencesFile, profile)).toEqual(true)
|
|
82
|
-
expect(store.statementsMatching(null, null, null, profile).length).toEqual(4)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
describe('silencedLoadPreferences', () => {
|
|
87
|
-
window.$SolidTestEnvironment = { username: alice.uri }
|
|
88
|
-
let store
|
|
89
|
-
requests = []
|
|
90
|
-
const statustoBeReturned = 200
|
|
91
|
-
let web = {}
|
|
92
|
-
const authn = {
|
|
93
|
-
currentUser: () => {
|
|
94
|
-
return alice
|
|
95
|
-
},
|
|
96
|
-
}
|
|
97
|
-
beforeEach(() => {
|
|
98
|
-
fetchMock.resetMocks()
|
|
99
|
-
web = loadWebObject()
|
|
100
|
-
requests = []
|
|
101
|
-
fetchMock.mockIf(/^https?.*$/, async req => {
|
|
102
|
-
|
|
103
|
-
if (req.method !== 'GET') {
|
|
104
|
-
requests.push(req)
|
|
105
|
-
if (req.method === 'PUT') {
|
|
106
|
-
const contents = await req.text()
|
|
107
|
-
web[req.url] = contents // Update our dummy web
|
|
108
|
-
console.log(`Tetst: Updated ${req.url} on PUT to <<<${web[req.url]}>>>`)
|
|
109
|
-
}
|
|
110
|
-
return { status: statustoBeReturned }
|
|
111
|
-
}
|
|
112
|
-
const contents = web[req.url]
|
|
113
|
-
if (contents !== undefined) { //
|
|
114
|
-
return {
|
|
115
|
-
body: prefixes + contents, // Add namespaces to anything
|
|
116
|
-
status: 200,
|
|
117
|
-
headers: {
|
|
118
|
-
'Content-Type': 'text/turtle',
|
|
119
|
-
'WAC-Allow': 'user="write", public="read"',
|
|
120
|
-
'Accept-Patch': 'application/sparql-update'
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
} // if contents
|
|
124
|
-
return {
|
|
125
|
-
status: 404,
|
|
126
|
-
body: 'Not Found'
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
store = new Store()
|
|
131
|
-
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
132
|
-
store.updater = new UpdateManager(store)
|
|
133
|
-
const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
|
|
134
|
-
profileLogic = createProfileLogic(store, authn, util)
|
|
135
|
-
})
|
|
136
|
-
it('exists', () => {
|
|
137
|
-
expect(profileLogic.silencedLoadPreferences).toBeInstanceOf(Function)
|
|
138
|
-
})
|
|
139
|
-
it('loads data', async () => {
|
|
140
|
-
const result = await profileLogic.silencedLoadPreferences(alice)
|
|
141
|
-
expect(result).toBeInstanceOf(Object)
|
|
142
|
-
expect(result.uri).toEqual(AlicePreferencesFile.uri)
|
|
143
|
-
expect(store.holds(user, ns.rdf('type'), ns.vcard('Individual'), profile)).toEqual(true)
|
|
144
|
-
expect(store.statementsMatching(null, null, null, profile).length).toEqual(4)
|
|
145
|
-
|
|
146
|
-
expect(store.statementsMatching(null, null, null, AlicePreferencesFile).length).toEqual(2)
|
|
147
|
-
expect(store.holds(user, ns.solid('privateTypeIndex'), AlicePrivateTypeIndex, AlicePreferencesFile)).toEqual(true)
|
|
148
|
-
})
|
|
149
|
-
it('creates new file', async () => {
|
|
150
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
151
|
-
const result = await profileLogic.silencedLoadPreferences(bob)
|
|
152
|
-
|
|
153
|
-
const patchRequest = requests[0]
|
|
154
|
-
expect(patchRequest.method).toEqual('PATCH')
|
|
155
|
-
expect(patchRequest.url).toEqual(bob.doc().uri)
|
|
156
|
-
const text = await patchRequest.text()
|
|
157
|
-
expect(text).toContain('INSERT DATA { <https://bob.example.com/profile/card.ttl#me> <http://www.w3.org/ns/pim/space#preferencesFile> <https://bob.example.com/Settings/Preferences.ttl> .')
|
|
158
|
-
|
|
159
|
-
const putRequest = requests[1]
|
|
160
|
-
expect(putRequest.method).toEqual('PUT')
|
|
161
|
-
expect(putRequest.url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
|
|
162
|
-
expect(web[putRequest.url]).toEqual('')
|
|
163
|
-
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
describe('loadPreferences', () => {
|
|
169
|
-
window.$SolidTestEnvironment = { username: boby.uri }
|
|
170
|
-
let store
|
|
171
|
-
requests = []
|
|
172
|
-
const statustoBeReturned = 200
|
|
173
|
-
let web = {}
|
|
174
|
-
const authn = {
|
|
175
|
-
currentUser: () => {
|
|
176
|
-
return boby
|
|
177
|
-
},
|
|
178
|
-
}
|
|
179
|
-
beforeEach(() => {
|
|
180
|
-
fetchMock.resetMocks()
|
|
181
|
-
web = loadWebObject()
|
|
182
|
-
requests = []
|
|
183
|
-
fetchMock.mockIf(/^https?.*$/, async req => {
|
|
184
|
-
|
|
185
|
-
if (req.method !== 'GET') {
|
|
186
|
-
requests.push(req)
|
|
187
|
-
if (req.method === 'PUT') {
|
|
188
|
-
const contents = await req.text()
|
|
189
|
-
web[req.url] = contents // Update our dummy web
|
|
190
|
-
console.log(`Tetst: Updated ${req.url} on PUT to <<<${web[req.url]}>>>`)
|
|
191
|
-
}
|
|
192
|
-
return { status: statustoBeReturned }
|
|
193
|
-
}
|
|
194
|
-
const contents = web[req.url]
|
|
195
|
-
if (contents !== undefined) { //
|
|
196
|
-
return {
|
|
197
|
-
body: prefixes + contents, // Add namespaces to anything
|
|
198
|
-
status: 200,
|
|
199
|
-
headers: {
|
|
200
|
-
'Content-Type': 'text/turtle',
|
|
201
|
-
'WAC-Allow': 'user="write", public="read"',
|
|
202
|
-
'Accept-Patch': 'application/sparql-update'
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
} // if contents
|
|
206
|
-
return {
|
|
207
|
-
status: 404,
|
|
208
|
-
body: 'Not Found'
|
|
209
|
-
}
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
store = new Store()
|
|
213
|
-
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
214
|
-
store.updater = new UpdateManager(store)
|
|
215
|
-
const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
|
|
216
|
-
profileLogic = createProfileLogic(store, authn, util)
|
|
217
|
-
})
|
|
218
|
-
it('exists', () => {
|
|
219
|
-
expect(profileLogic.loadPreferences).toBeInstanceOf(Function)
|
|
220
|
-
})
|
|
221
|
-
it('loads data', async () => {
|
|
222
|
-
const result = await profileLogic.loadPreferences(alice)
|
|
223
|
-
expect(result).toBeInstanceOf(Object)
|
|
224
|
-
expect(result.uri).toEqual(AlicePreferencesFile.uri)
|
|
225
|
-
expect(store.holds(user, ns.rdf('type'), ns.vcard('Individual'), profile)).toEqual(true)
|
|
226
|
-
expect(store.statementsMatching(null, null, null, profile).length).toEqual(4)
|
|
227
|
-
|
|
228
|
-
expect(store.statementsMatching(null, null, null, AlicePreferencesFile).length).toEqual(2)
|
|
229
|
-
expect(store.holds(user, ns.solid('privateTypeIndex'), AlicePrivateTypeIndex, AlicePreferencesFile)).toEqual(true)
|
|
230
|
-
})
|
|
231
|
-
it('creates new file', async () => {
|
|
232
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
233
|
-
const result = await profileLogic.loadPreferences(boby)
|
|
234
|
-
|
|
235
|
-
const patchRequest = requests[0]
|
|
236
|
-
expect(patchRequest.method).toEqual('PATCH')
|
|
237
|
-
expect(patchRequest.url).toEqual(boby.doc().uri)
|
|
238
|
-
const text = await patchRequest.text()
|
|
239
|
-
expect(text).toContain('INSERT DATA { <https://boby.example.com/profile/card.ttl#me> <http://www.w3.org/ns/pim/space#preferencesFile> <https://boby.example.com/Settings/Preferences.ttl> .')
|
|
240
|
-
|
|
241
|
-
const putRequest = requests[1]
|
|
242
|
-
expect(putRequest.method).toEqual('PUT')
|
|
243
|
-
expect(putRequest.url).toEqual('https://boby.example.com/Settings/Preferences.ttl')
|
|
244
|
-
expect(web[putRequest.url]).toEqual('')
|
|
245
|
-
|
|
246
|
-
})
|
|
247
|
-
})
|
|
248
|
-
})
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
import { SolidAuthnLogic } from '../src/authn/SolidAuthnLogic'
|
|
6
|
-
import { silenceDebugMessages } from './helpers/setup'
|
|
7
|
-
import { authSession } from '../src/authSession/authSession'
|
|
8
|
-
import { AuthenticationContext } from '../src/types'
|
|
9
|
-
|
|
10
|
-
silenceDebugMessages()
|
|
11
|
-
let solidAuthnLogic
|
|
12
|
-
|
|
13
|
-
describe('SolidAuthnLogic', () => {
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
solidAuthnLogic = new SolidAuthnLogic(authSession)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe('checkUser', () => {
|
|
20
|
-
it('exists', () => {
|
|
21
|
-
expect(solidAuthnLogic.checkUser).toBeInstanceOf(Function)
|
|
22
|
-
})
|
|
23
|
-
it('runs', async () => {
|
|
24
|
-
expect(await solidAuthnLogic.checkUser()).toEqual(null)
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe('currentUser', () => {
|
|
29
|
-
it('exists', () => {
|
|
30
|
-
expect(solidAuthnLogic.currentUser).toBeInstanceOf(Function)
|
|
31
|
-
})
|
|
32
|
-
it('runs', async () => {
|
|
33
|
-
expect(await solidAuthnLogic.currentUser()).toEqual(null)
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
describe('saveUser', () => {
|
|
38
|
-
it('exists', () => {
|
|
39
|
-
expect(solidAuthnLogic.saveUser).toBeInstanceOf(Function)
|
|
40
|
-
})
|
|
41
|
-
it('runs', () => {
|
|
42
|
-
expect(solidAuthnLogic.saveUser(
|
|
43
|
-
'',
|
|
44
|
-
{} as AuthenticationContext
|
|
45
|
-
)).toEqual(null)
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
})
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment jsdom
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
import { Fetcher, Store, sym, UpdateManager } from 'rdflib'
|
|
6
|
-
import { createAclLogic } from '../src/acl/aclLogic'
|
|
7
|
-
import { createProfileLogic } from '../src/profile/profileLogic'
|
|
8
|
-
import { createTypeIndexLogic} from '../src/typeIndex/typeIndexLogic'
|
|
9
|
-
import { createContainerLogic } from '../src/util/containerLogic'
|
|
10
|
-
import { ns } from '../src/util/ns'
|
|
11
|
-
import { createUtilityLogic } from '../src/util/utilityLogic'
|
|
12
|
-
import { uniqueNodes } from '../src/util/utils'
|
|
13
|
-
import { alice, AlicePhotoFolder, AlicePhotos, AlicePreferences, AlicePreferencesFile, AlicePrivateTypeIndex, AlicePrivateTypes, AliceProfile, AlicePublicTypeIndex, AlicePublicTypes, bob, BobProfile, club, ClubPreferences, ClubPreferencesFile, ClubPrivateTypeIndex, ClubPrivateTypes, ClubProfile, ClubPublicTypeIndex, ClubPublicTypes } from './helpers/dataSetup'
|
|
14
|
-
|
|
15
|
-
const prefixes = Object.keys(ns).map(prefix => `@prefix ${prefix}: ${ns[prefix]('')}.\n`).join('') // In turtle
|
|
16
|
-
window.$SolidTestEnvironment = { username: alice.uri }
|
|
17
|
-
|
|
18
|
-
const Tracker = ns.wf('Tracker')
|
|
19
|
-
const Image = ns.schema('Image')
|
|
20
|
-
|
|
21
|
-
//let web = {}
|
|
22
|
-
//web = loadWebObject()
|
|
23
|
-
const user = alice
|
|
24
|
-
const profile = user.doc()
|
|
25
|
-
const web = {}
|
|
26
|
-
web[profile.uri] = AliceProfile
|
|
27
|
-
web[AlicePreferencesFile.uri] = AlicePreferences
|
|
28
|
-
web[AlicePrivateTypeIndex.uri] = AlicePrivateTypes
|
|
29
|
-
web[AlicePublicTypeIndex.uri] = AlicePublicTypes
|
|
30
|
-
web[AlicePhotoFolder.uri] = AlicePhotos
|
|
31
|
-
web[bob.doc().uri] = BobProfile
|
|
32
|
-
|
|
33
|
-
web[club.doc().uri] = ClubProfile
|
|
34
|
-
web[ClubPreferencesFile.uri] = ClubPreferences
|
|
35
|
-
web[ClubPrivateTypeIndex.uri] = ClubPrivateTypes
|
|
36
|
-
web[ClubPublicTypeIndex.uri] = ClubPublicTypes
|
|
37
|
-
let requests: Request[] = []
|
|
38
|
-
let statustoBeReturned = 200
|
|
39
|
-
let typeIndexLogic
|
|
40
|
-
|
|
41
|
-
describe('TypeIndex logic NEW', () => {
|
|
42
|
-
let store
|
|
43
|
-
const authn = {
|
|
44
|
-
currentUser: () => {
|
|
45
|
-
return alice
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
beforeEach(() => {
|
|
50
|
-
fetchMock.resetMocks()
|
|
51
|
-
requests = []
|
|
52
|
-
statustoBeReturned = 200
|
|
53
|
-
|
|
54
|
-
fetchMock.mockIf(/^https?.*$/, async req => {
|
|
55
|
-
|
|
56
|
-
if (req.method !== 'GET') {
|
|
57
|
-
requests.push(req)
|
|
58
|
-
if (req.method === 'PUT') {
|
|
59
|
-
const contents = await req.text()
|
|
60
|
-
web[req.url] = contents // Update our dummy web
|
|
61
|
-
console.log(`Tetst: Updated ${req.url} on PUT to <<<${web[req.url]}>>>`)
|
|
62
|
-
}
|
|
63
|
-
return { status: statustoBeReturned }
|
|
64
|
-
}
|
|
65
|
-
const contents = web[req.url]
|
|
66
|
-
if (contents !== undefined) { //
|
|
67
|
-
return {
|
|
68
|
-
body: prefixes + contents, // Add namespaces to anything
|
|
69
|
-
status: 200,
|
|
70
|
-
headers: {
|
|
71
|
-
'Content-Type': 'text/turtle',
|
|
72
|
-
'WAC-Allow': 'user="write", public="read"',
|
|
73
|
-
'Accept-Patch': 'application/sparql-update'
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} // if contents
|
|
77
|
-
return {
|
|
78
|
-
status: 404,
|
|
79
|
-
body: 'Not Found'
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
store = new Store()
|
|
84
|
-
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
85
|
-
store.updater = new UpdateManager(store)
|
|
86
|
-
const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
|
|
87
|
-
typeIndexLogic = createTypeIndexLogic(store, authn, createProfileLogic(store, authn, util), util)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
describe('loadAllTypeIndexes', () => {
|
|
91
|
-
it('exists', () => {
|
|
92
|
-
expect(typeIndexLogic.loadAllTypeIndexes).toBeInstanceOf(Function)
|
|
93
|
-
})
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const AliceScopes = [{
|
|
97
|
-
'agent': {
|
|
98
|
-
'classOrder': 5,
|
|
99
|
-
'termType': 'NamedNode',
|
|
100
|
-
'value': 'https://alice.example.com/profile/card.ttl#me',
|
|
101
|
-
},
|
|
102
|
-
'index': {
|
|
103
|
-
'classOrder': 5,
|
|
104
|
-
'termType': 'NamedNode',
|
|
105
|
-
'value': 'https://alice.example.com/profile/public-type-index.ttl',
|
|
106
|
-
},
|
|
107
|
-
'label': 'public',
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
'agent': {
|
|
111
|
-
'classOrder': 5,
|
|
112
|
-
'termType': 'NamedNode',
|
|
113
|
-
'value': 'https://alice.example.com/profile/card.ttl#me',
|
|
114
|
-
},
|
|
115
|
-
'index': {
|
|
116
|
-
'classOrder': 5,
|
|
117
|
-
'termType': 'NamedNode',
|
|
118
|
-
'value': 'https://alice.example.com/settings/private-type-index.ttl',
|
|
119
|
-
},
|
|
120
|
-
'label': 'private',
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
|
|
124
|
-
describe('loadTypeIndexesFor', () => {
|
|
125
|
-
it('exists', () => {
|
|
126
|
-
expect(typeIndexLogic.loadTypeIndexesFor).toBeInstanceOf(Function)
|
|
127
|
-
})
|
|
128
|
-
it('loads data', async () => {
|
|
129
|
-
const result = await typeIndexLogic.loadTypeIndexesFor(alice)
|
|
130
|
-
expect(result).toEqual(AliceScopes)
|
|
131
|
-
expect(store.statementsMatching(null, null, null, AlicePrivateTypeIndex).length).toEqual(8)
|
|
132
|
-
expect(store.statementsMatching(null, null, null, AlicePublicTypeIndex).length).toEqual(8)
|
|
133
|
-
})
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
const ClubScopes =
|
|
137
|
-
[
|
|
138
|
-
{
|
|
139
|
-
'agent': {
|
|
140
|
-
'classOrder': 5,
|
|
141
|
-
'termType': 'NamedNode',
|
|
142
|
-
'value': 'https://club.example.com/profile/card.ttl#it',
|
|
143
|
-
},
|
|
144
|
-
'index': {
|
|
145
|
-
'classOrder': 5,
|
|
146
|
-
'termType': 'NamedNode',
|
|
147
|
-
'value': 'https://club.example.com/profile/public-type-index.ttl',
|
|
148
|
-
},
|
|
149
|
-
'label': 'public',
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
'agent': {
|
|
153
|
-
'classOrder': 5,
|
|
154
|
-
'termType': 'NamedNode',
|
|
155
|
-
'value': 'https://club.example.com/profile/card.ttl#it',
|
|
156
|
-
},
|
|
157
|
-
'index': {
|
|
158
|
-
'classOrder': 5,
|
|
159
|
-
'termType': 'NamedNode',
|
|
160
|
-
'value': 'https://club.example.com/settings/private-type-index.ttl',
|
|
161
|
-
},
|
|
162
|
-
'label': 'private',
|
|
163
|
-
}
|
|
164
|
-
]
|
|
165
|
-
describe('loadCommunityTypeIndexes', () => {
|
|
166
|
-
it('exists', () => {
|
|
167
|
-
expect(typeIndexLogic.loadCommunityTypeIndexes).toBeInstanceOf(Function)
|
|
168
|
-
})
|
|
169
|
-
it('loads data', async () => {
|
|
170
|
-
const result = await typeIndexLogic.loadCommunityTypeIndexes(alice)
|
|
171
|
-
expect(result).toEqual(ClubScopes)
|
|
172
|
-
})
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
const AliceAndClubScopes = [{'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/publicStuff/actionItems.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/project4/issues.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/ToDo.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/Goals.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/workingOn.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/profile/card.ttl#me'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/publicStuff/actionItems.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/project4/clubIssues.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/public-type-index.ttl'}, 'label': 'public'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/ToDo.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/Goals.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}, {'instance': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/tasks.ttl#this'}, 'scope': {'agent': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/profile/card.ttl#it'}, 'index': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/settings/private-type-index.ttl'}, 'label': 'private'}, 'type': {'classOrder': 5, 'termType': 'NamedNode', 'value': 'http://www.w3.org/2005/01/wf/flow#Tracker'}}]
|
|
176
|
-
|
|
177
|
-
describe('getScopedAppInstances', () => {
|
|
178
|
-
it('exists', () => {
|
|
179
|
-
expect(typeIndexLogic.getScopedAppInstances).toBeInstanceOf(Function)
|
|
180
|
-
})
|
|
181
|
-
it('pulls in users scopes and also community ones', async () => {
|
|
182
|
-
const result = await typeIndexLogic.getScopedAppInstances(Tracker, alice)
|
|
183
|
-
expect(result).toEqual(AliceAndClubScopes) // @@ AliceAndClubScopes
|
|
184
|
-
})
|
|
185
|
-
it('creates new preferenceFile and typeIndex files where they dont exist', async () => {
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
187
|
-
const result = await typeIndexLogic.getScopedAppInstances(Tracker, bob)
|
|
188
|
-
|
|
189
|
-
expect(requests[0].method).toEqual('PATCH') // Add preferrencesFile link to profile
|
|
190
|
-
expect(requests[0].url).toEqual('https://bob.example.com/profile/card.ttl')
|
|
191
|
-
|
|
192
|
-
expect(requests[1].method).toEqual('PUT') // create publiTypeIndex
|
|
193
|
-
expect(requests[1].url).toEqual('https://bob.example.com/profile/publicTypeIndex.ttl')
|
|
194
|
-
|
|
195
|
-
expect(requests[2].method).toEqual('PATCH') // Add link of publiTypeIndex to profile
|
|
196
|
-
expect(requests[2].url).toEqual('https://bob.example.com/profile/card.ttl')
|
|
197
|
-
|
|
198
|
-
expect(requests[3].method).toEqual('PUT') // create preferenceFile
|
|
199
|
-
expect(requests[3].url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
|
|
200
|
-
|
|
201
|
-
expect(requests[4].method).toEqual('PATCH') // Add privateTypeIndex link preference file
|
|
202
|
-
expect(requests[4].url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
|
|
203
|
-
|
|
204
|
-
expect(requests[5].method).toEqual('PUT') //create privatTypeIndex
|
|
205
|
-
expect(requests[5].url).toEqual('https://bob.example.com/Settings/privateTypeIndex.ttl')
|
|
206
|
-
|
|
207
|
-
expect(requests.length).toEqual(6)
|
|
208
|
-
|
|
209
|
-
})
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
const TRACKERS =
|
|
213
|
-
[{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/publicStuff/actionItems.ttl#this'},
|
|
214
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/project4/issues.ttl#this'},
|
|
215
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/ToDo.ttl#this'},
|
|
216
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/Goals.ttl#this'},
|
|
217
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://alice.example.com/privateStuff/workingOn.ttl#this'},
|
|
218
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/publicStuff/actionItems.ttl#this'},
|
|
219
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/project4/clubIssues.ttl#this'},
|
|
220
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/ToDo.ttl#this'},
|
|
221
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/Goals.ttl#this'},
|
|
222
|
-
{'classOrder': 5, 'termType': 'NamedNode', 'value': 'https://club.example.com/privateStuff/tasks.ttl#this'} ]
|
|
223
|
-
|
|
224
|
-
describe('getAppInstances', () => {
|
|
225
|
-
it('exists', () => {
|
|
226
|
-
expect(typeIndexLogic.getAppInstances).toBeInstanceOf(Function)
|
|
227
|
-
})
|
|
228
|
-
it('finds trackers', async () => {
|
|
229
|
-
const result = await typeIndexLogic.getAppInstances(Tracker)
|
|
230
|
-
expect(result).toEqual(TRACKERS) // TRACKERS @@
|
|
231
|
-
expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
|
|
232
|
-
})
|
|
233
|
-
it('finds containers', async () => {
|
|
234
|
-
const result = await typeIndexLogic.getAppInstances(Image)
|
|
235
|
-
expect(result.length).toEqual(1)
|
|
236
|
-
expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
|
|
237
|
-
expect(result.map(x => x.uri).join()).toEqual('https://alice.example.com/profile/Photos/')
|
|
238
|
-
})
|
|
239
|
-
})
|
|
240
|
-
|
|
241
|
-
describe('registerInTypeIndex', () => {
|
|
242
|
-
it('exists', () => {
|
|
243
|
-
expect(typeIndexLogic.registerInTypeIndex).toBeInstanceOf(Function)
|
|
244
|
-
})
|
|
245
|
-
it('throws error', async () => {
|
|
246
|
-
const result = await typeIndexLogic.registerInTypeIndex(
|
|
247
|
-
sym('https://test.test#'),
|
|
248
|
-
sym('https://test.test#'),
|
|
249
|
-
sym('https://test.test/TheClass')
|
|
250
|
-
)
|
|
251
|
-
console.log(result)
|
|
252
|
-
expect(result).toEqual(null)
|
|
253
|
-
})
|
|
254
|
-
})
|
|
255
|
-
})
|