solid-logic 1.3.16 → 1.3.17-0abe2b84
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/.babelrc +0 -0
- package/.eslintrc.js +0 -0
- package/.github/workflows/ci.yml +0 -0
- package/.github/workflows/release.yml +0 -0
- package/.nvmrc +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/jest.config.js +1 -1
- package/lib/acl/aclLogic.d.ts +0 -0
- package/lib/acl/aclLogic.d.ts.map +0 -0
- package/lib/acl/aclLogic.js +0 -0
- package/lib/acl/aclLogic.js.map +0 -0
- package/lib/authSession/authSession.d.ts +0 -0
- package/lib/authSession/authSession.d.ts.map +0 -0
- package/lib/authSession/authSession.js +0 -0
- package/lib/authSession/authSession.js.map +0 -0
- package/lib/authn/SolidAuthnLogic.d.ts +0 -0
- package/lib/authn/SolidAuthnLogic.d.ts.map +0 -0
- package/lib/authn/SolidAuthnLogic.js +1 -1
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/authn/authUtil.d.ts +0 -0
- package/lib/authn/authUtil.d.ts.map +0 -0
- package/lib/authn/authUtil.js +1 -1
- package/lib/authn/authUtil.js.map +1 -1
- package/lib/chat/ChatLogic.d.ts +0 -0
- package/lib/chat/ChatLogic.d.ts.map +0 -0
- package/lib/chat/ChatLogic.js +0 -0
- package/lib/chat/ChatLogic.js.map +0 -0
- package/lib/chat/determineChatContainer.d.ts +0 -0
- package/lib/chat/determineChatContainer.d.ts.map +0 -0
- package/lib/chat/determineChatContainer.js +0 -0
- package/lib/chat/determineChatContainer.js.map +0 -0
- package/lib/discovery/discoveryLogic.d.ts +33 -6
- package/lib/discovery/discoveryLogic.d.ts.map +1 -1
- package/lib/discovery/discoveryLogic.js +377 -86
- package/lib/discovery/discoveryLogic.js.map +1 -1
- package/lib/inbox/InboxLogic.d.ts +0 -0
- package/lib/inbox/InboxLogic.d.ts.map +0 -0
- package/lib/inbox/InboxLogic.js +0 -0
- package/lib/inbox/InboxLogic.js.map +0 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.d.ts.map +0 -0
- package/lib/index.js +0 -0
- package/lib/index.js.map +0 -0
- package/lib/issuer/issuerLogic.d.ts +0 -0
- package/lib/issuer/issuerLogic.d.ts.map +0 -0
- package/lib/issuer/issuerLogic.js +0 -0
- package/lib/issuer/issuerLogic.js.map +0 -0
- package/lib/logic/CustomError.d.ts +0 -0
- package/lib/logic/CustomError.d.ts.map +0 -0
- package/lib/logic/CustomError.js +0 -0
- package/lib/logic/CustomError.js.map +0 -0
- package/lib/logic/SolidLogic.d.ts +0 -0
- package/lib/logic/SolidLogic.d.ts.map +0 -0
- package/lib/logic/SolidLogic.js +0 -0
- package/lib/logic/SolidLogic.js.map +0 -0
- package/lib/logic/solidLogicSingleton.d.ts +0 -0
- package/lib/logic/solidLogicSingleton.d.ts.map +0 -0
- package/lib/logic/solidLogicSingleton.js +1 -1
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/profile/ProfileLogic.d.ts +0 -0
- package/lib/profile/ProfileLogic.d.ts.map +0 -0
- package/lib/profile/ProfileLogic.js +0 -0
- package/lib/profile/ProfileLogic.js.map +0 -0
- package/lib/typeIndex/typeIndexLogic.d.ts +2 -2
- package/lib/typeIndex/typeIndexLogic.d.ts.map +0 -0
- package/lib/typeIndex/typeIndexLogic.js +4 -4
- package/lib/typeIndex/typeIndexLogic.js.map +1 -1
- package/lib/types.d.ts +0 -0
- package/lib/types.d.ts.map +0 -0
- package/lib/types.js +0 -0
- package/lib/types.js.map +0 -0
- package/lib/util/UtilityLogic.d.ts +0 -0
- package/lib/util/UtilityLogic.d.ts.map +0 -0
- package/lib/util/UtilityLogic.js +2 -2
- package/lib/util/UtilityLogic.js.map +1 -1
- package/lib/util/debug.d.ts +0 -0
- package/lib/util/debug.d.ts.map +0 -0
- package/lib/util/debug.js +0 -0
- package/lib/util/debug.js.map +0 -0
- package/lib/util/uri.d.ts +0 -0
- package/lib/util/uri.d.ts.map +0 -0
- package/lib/util/uri.js +0 -0
- package/lib/util/uri.js.map +0 -0
- package/package.json +8 -8
- package/src/acl/aclLogic.ts +0 -0
- package/src/authSession/authSession.ts +0 -0
- package/src/authn/SolidAuthnLogic.ts +5 -5
- package/src/authn/authUtil.ts +1 -1
- package/src/chat/ChatLogic.ts +0 -0
- package/src/chat/determineChatContainer.ts +0 -0
- package/src/discovery/discoveryLogic.ts +269 -48
- package/src/inbox/InboxLogic.ts +0 -0
- package/src/index.ts +0 -0
- package/src/issuer/issuerLogic.ts +0 -0
- package/src/logic/CustomError.ts +0 -0
- package/src/logic/SolidLogic.ts +0 -0
- package/src/logic/solidLogicSingleton.ts +1 -1
- package/src/profile/ProfileLogic.ts +0 -0
- package/src/typeIndex/typeIndexLogic.ts +5 -5
- package/src/types.ts +0 -0
- package/src/util/UtilityLogic.ts +3 -3
- package/src/util/debug.ts +0 -0
- package/src/util/uri.ts +0 -0
- package/test/aclLogic.test.ts +0 -0
- package/test/authUtil.test.ts +0 -0
- package/test/chatLogic.test.ts +0 -0
- package/test/discoveryLogic.test.ts +740 -0
- package/test/helpers/setup.ts +3 -0
- package/test/inboxLogic.test.ts +0 -0
- package/test/logic.test.ts +0 -0
- package/test/solidAuthLogic.test.ts +0 -0
- package/test/typeIndexLogic.test.ts +5 -4
- package/test/utilityLogic.test.ts +0 -0
- package/tsconfig.json +0 -0
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { Fetcher, Namespace, Store, sym, UpdateManager } from "rdflib";
|
|
6
|
+
import { AuthenticationContext } from '../src/types'
|
|
7
|
+
import { solidLogicSingleton } from "../src/logic/solidLogicSingleton"
|
|
8
|
+
import fetchMock from "jest-fetch-mock";
|
|
9
|
+
|
|
10
|
+
import { loadOrCreateIfNotExists, makePreferencesFileURI, followOrCreateLink, loadCommunityTypeIndexes,
|
|
11
|
+
getAppInstances, getScopedAppInstances, loadTypeIndexesFor, loadPreferences, registerInstanceInTypeIndex,
|
|
12
|
+
uniqueNodes, loadProfile } from '../src/discovery/discoveryLogic.ts'
|
|
13
|
+
|
|
14
|
+
const { getContainerMembers, authn, store } = solidLogicSingleton
|
|
15
|
+
|
|
16
|
+
/* global $SolidTestEnvironment */
|
|
17
|
+
|
|
18
|
+
/* Discovery Logic tests
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const ns = {
|
|
22
|
+
dct: Namespace('http://purl.org/dc/terms/'),
|
|
23
|
+
ldp: Namespace('http://www.w3.org/ns/ldp#'),
|
|
24
|
+
meeting: Namespace('http://www.w3.org/ns/pim/meeting#'),
|
|
25
|
+
rdf: Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#'),
|
|
26
|
+
schema: Namespace('http://schema.org/'),
|
|
27
|
+
solid: Namespace('http://www.w3.org/ns/solid/terms#'),
|
|
28
|
+
space: Namespace('http://www.w3.org/ns/pim/space#'),
|
|
29
|
+
stat: Namespace('http://www.w3.org/ns/posix/stat#'),
|
|
30
|
+
vcard: Namespace('http://www.w3.org/2006/vcard/ns#'),
|
|
31
|
+
wf: Namespace('http://www.w3.org/2005/01/wf/flow#'),
|
|
32
|
+
xsd: Namespace('http://www.w3.org/2001/XMLSchema#')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const prefixes = Object.keys(ns).map(prefix => `@prefix ${prefix}: ${ns[prefix]('')}.\n`).join('') // In turtle
|
|
36
|
+
|
|
37
|
+
const Alice = sym('https://alice.example.com/profile/card.ttl#me')
|
|
38
|
+
const AliceProfileFile = Alice.doc()
|
|
39
|
+
const AlicePreferencesFile = sym('https://alice.example.com/settings/prefs.ttl')
|
|
40
|
+
const AlicePublicTypeIndex = sym('https://alice.example.com/profle/public-type-index.ttl')
|
|
41
|
+
const AlicePrivateTypeIndex = sym('https://alice.example.com/settings/private-type-index.ttl')
|
|
42
|
+
const AlicePhotoFolder = sym(Alice.dir().uri + "Photos/")
|
|
43
|
+
|
|
44
|
+
// the Club is a community which Alice is involved and so she gets to
|
|
45
|
+
// interact with things in its type indexes.
|
|
46
|
+
|
|
47
|
+
const Club = sym('https://club.example.com/profile/card.ttl#it')
|
|
48
|
+
const ClubProfileFile = Club.doc()
|
|
49
|
+
const ClubPreferencesFile = sym('https://club.example.com/settings/prefs.ttl')
|
|
50
|
+
const ClubPublicTypeIndex = sym('https://club.example.com/profle/public-type-index.ttl')
|
|
51
|
+
const ClubPrivateTypeIndex = sym('https://club.example.com/settings/private-type-index.ttl')
|
|
52
|
+
|
|
53
|
+
const Bob = sym('https://bob.example.com/profile/card.ttl#me')
|
|
54
|
+
|
|
55
|
+
window.$SolidTestEnvironment = { username: Alice.uri }
|
|
56
|
+
|
|
57
|
+
const user = Alice
|
|
58
|
+
const profile = user.doc()
|
|
59
|
+
|
|
60
|
+
// const klass = sym('http://www.w3.org/2006/vcard/ns#AddressBook')
|
|
61
|
+
const klass = ns.wf('Tracker')
|
|
62
|
+
const Tracker = ns.wf('Tracker')
|
|
63
|
+
const Image = ns.schema('Image')
|
|
64
|
+
|
|
65
|
+
//////////////////////////////////////////////////////////// User Alice
|
|
66
|
+
const AliceProfile = `
|
|
67
|
+
<#me> a vcard:Individual;
|
|
68
|
+
space:preferencesFile ${AlicePreferencesFile};
|
|
69
|
+
solid:publicTypeIndex ${AlicePublicTypeIndex};
|
|
70
|
+
vcard:fn "Alice" .
|
|
71
|
+
`
|
|
72
|
+
const AlicePreferences = `
|
|
73
|
+
${Alice} solid:privateTypeIndex ${AlicePrivateTypeIndex};
|
|
74
|
+
solid:community ${Club} .
|
|
75
|
+
|
|
76
|
+
`
|
|
77
|
+
const AlicePublicTypes = `
|
|
78
|
+
|
|
79
|
+
:chat1 solid:forClass meeting:LongChat; solid:instance <../publicStuff/myChat.ttl#this> .
|
|
80
|
+
|
|
81
|
+
:todo solid:forClass wf:Tracker; solid:instance <../publicStuff/actionItems.ttl#this>.
|
|
82
|
+
|
|
83
|
+
:issues solid:forClass wf:Tracker; solid:instance <../project4/issues.ttl#this>.
|
|
84
|
+
|
|
85
|
+
:photos solid:forClass schema:Image; solid:instanceContainer ${AlicePhotoFolder} .
|
|
86
|
+
# :bookmarks
|
|
87
|
+
# a solid:TypeRegistration;
|
|
88
|
+
# solid:forClass bookm:Bookmark;
|
|
89
|
+
# solid:instance </public/poddit.ttl>.
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
const AlicePrivateTypes = `
|
|
93
|
+
:id1592319218311 solid:forClass wf:Tracker; solid:instance <../privateStuff/ToDo.ttl#this>.
|
|
94
|
+
|
|
95
|
+
:id1592319391415 solid:forClass wf:Tracker; solid:instance <../privateStuff/Goals.ttl#this>.
|
|
96
|
+
|
|
97
|
+
:id1595595377864 solid:forClass wf:Tracker; solid:instance <../privateStuff/workingOn.ttl#this>.
|
|
98
|
+
|
|
99
|
+
:id1596123375929 solid:forClass meeting:Meeting; solid:instance <../project4/meeting1.ttl#this>.
|
|
100
|
+
|
|
101
|
+
`;
|
|
102
|
+
|
|
103
|
+
const AlicePhotos = `
|
|
104
|
+
<>
|
|
105
|
+
a ldp:BasicContainer, ldp:Container;
|
|
106
|
+
dct:modified "2021-04-26T05:34:16Z"^^xsd:dateTime;
|
|
107
|
+
ldp:contains
|
|
108
|
+
<photo1.png>, <photo2.png>, <photo3.png> ;
|
|
109
|
+
stat:mtime 1619415256.541;
|
|
110
|
+
stat:size 4096 .
|
|
111
|
+
`
|
|
112
|
+
|
|
113
|
+
//////////////////////////////////////////////////////////// User Bob
|
|
114
|
+
const BobProfile = `
|
|
115
|
+
<#me> a vcard:Individual;
|
|
116
|
+
|
|
117
|
+
vcard:fn "Bob" .
|
|
118
|
+
`
|
|
119
|
+
|
|
120
|
+
//////////////////////////////////////////////////////////// User Club
|
|
121
|
+
const ClubProfile = `
|
|
122
|
+
|
|
123
|
+
<#it> a vcard:Organization;
|
|
124
|
+
space:preferencesFile ${ClubPreferencesFile};
|
|
125
|
+
solid:publicTypeIndex ${ClubPublicTypeIndex};
|
|
126
|
+
vcard:fn "Card Club" .
|
|
127
|
+
`
|
|
128
|
+
const ClubPreferences = `
|
|
129
|
+
${Club} solid:privateTypeIndex ${ClubPrivateTypeIndex} .
|
|
130
|
+
`
|
|
131
|
+
const ClubPublicTypes = `
|
|
132
|
+
|
|
133
|
+
:chat1 solid:forClass meeting:LongChat; solid:instance <../publicStuff/ourChat.ttl#this> .
|
|
134
|
+
|
|
135
|
+
:todo solid:forClass wf:Tracker; solid:instance <../publicStuff/actionItems.ttl#this>.
|
|
136
|
+
|
|
137
|
+
:issues solid:forClass wf:Tracker; solid:instance <../project4/clubIssues.ttl#this>.
|
|
138
|
+
|
|
139
|
+
# :bookmarks
|
|
140
|
+
# a solid:TypeRegistration;
|
|
141
|
+
# solid:forClass bookm:Bookmark;
|
|
142
|
+
# solid:instance </public/poddit.ttl>.
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
const ClubPrivateTypes = `
|
|
146
|
+
:id1592319218311 solid:forClass wf:Tracker; solid:instance <../privateStuff/ToDo.ttl#this>.
|
|
147
|
+
|
|
148
|
+
:id1592319391415 solid:forClass wf:Tracker; solid:instance <../privateStuff/Goals.ttl#this>.
|
|
149
|
+
|
|
150
|
+
:id1595595377864 solid:forClass wf:Tracker; solid:instance <../privateStuff/tasks.ttl#this>.
|
|
151
|
+
|
|
152
|
+
:id1596123375929 solid:forClass meeting:Meeting; solid:instance <../project4/clubMeeting.ttl#this>.
|
|
153
|
+
|
|
154
|
+
`;
|
|
155
|
+
|
|
156
|
+
////////////////////////////////////////////////////////////////////////////
|
|
157
|
+
|
|
158
|
+
const web = {}
|
|
159
|
+
web[profile.uri] = AliceProfile
|
|
160
|
+
web[AlicePreferencesFile.uri] = AlicePreferences
|
|
161
|
+
web[AlicePrivateTypeIndex.uri] = AlicePrivateTypes
|
|
162
|
+
web[AlicePublicTypeIndex.uri] = AlicePublicTypes
|
|
163
|
+
web[AlicePhotoFolder.uri] = AlicePhotos
|
|
164
|
+
web[Bob.doc().uri] = BobProfile
|
|
165
|
+
|
|
166
|
+
web[Club.doc().uri] = ClubProfile
|
|
167
|
+
web[ClubPreferencesFile.uri] = ClubPreferences
|
|
168
|
+
web[ClubPrivateTypeIndex.uri] = ClubPrivateTypes
|
|
169
|
+
web[ClubPublicTypeIndex.uri] = ClubPublicTypes
|
|
170
|
+
|
|
171
|
+
let requests = []
|
|
172
|
+
let statustoBeReturned = 200
|
|
173
|
+
|
|
174
|
+
describe("Discovery Logic", () => {
|
|
175
|
+
let store;
|
|
176
|
+
let options;
|
|
177
|
+
beforeEach(() => {
|
|
178
|
+
fetchMock.resetMocks();
|
|
179
|
+
requests = []
|
|
180
|
+
statustoBeReturned = 200
|
|
181
|
+
const init = {headers: { "Content-Type": "text/turtle" }} // Fetch options tend to be called this
|
|
182
|
+
|
|
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
|
+
|
|
213
|
+
options = { fetch: fetch };
|
|
214
|
+
store = new Store()
|
|
215
|
+
store.fetcher = new Fetcher (store, options);
|
|
216
|
+
store.updater = new UpdateManager(store);
|
|
217
|
+
// util = new UtilityLogic(store, ns, fetcher);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// uniqueNodes
|
|
221
|
+
|
|
222
|
+
describe('uniqueNodes', () => {
|
|
223
|
+
it('exists', () => {
|
|
224
|
+
expect(uniqueNodes).toBeInstanceOf(Function)
|
|
225
|
+
})
|
|
226
|
+
it('removed duplicates', async () => {
|
|
227
|
+
const input = [ sym('https://a.com/'), sym('https://b.com/'),sym('https://a.com/'), sym('https://a.com/'), sym('https://c.com/'), ]
|
|
228
|
+
const expected = [ sym('https://a.com/'), sym('https://b.com/'), sym('https://c.com/'), ]
|
|
229
|
+
const result = uniqueNodes(input)
|
|
230
|
+
expect(result).toEqual(expected)
|
|
231
|
+
|
|
232
|
+
})
|
|
233
|
+
it('handles an empty array', async () => {
|
|
234
|
+
const result = await uniqueNodes([])
|
|
235
|
+
expect(result).toEqual([])
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
// loadOrCreateIfNotExists
|
|
239
|
+
|
|
240
|
+
describe('loadOrCreateIfNotExists', () => {
|
|
241
|
+
it('exists', () => {
|
|
242
|
+
expect(loadOrCreateIfNotExists).toBeInstanceOf(Function)
|
|
243
|
+
})
|
|
244
|
+
it('does nothing if existing file', async () => {
|
|
245
|
+
const result = await loadOrCreateIfNotExists(store, Alice.doc())
|
|
246
|
+
expect(requests).toEqual([])
|
|
247
|
+
|
|
248
|
+
})
|
|
249
|
+
it('creates empty file if did not exist', async () => {
|
|
250
|
+
const newFile = sym(Bob.doc().uri + /refhoijhoegg/)
|
|
251
|
+
const result = await loadOrCreateIfNotExists(store, newFile)
|
|
252
|
+
expect(requests[0].method).toEqual('PUT')
|
|
253
|
+
expect(requests[0].url).toEqual(newFile.uri)
|
|
254
|
+
})
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
// followOrCreateLink
|
|
258
|
+
|
|
259
|
+
describe('followOrCreateLink', () => {
|
|
260
|
+
it('exists', () => {
|
|
261
|
+
expect(followOrCreateLink).toBeInstanceOf(Function)
|
|
262
|
+
})
|
|
263
|
+
it('follows existing link', async () => {
|
|
264
|
+
const result = await followOrCreateLink(store, Alice, ns.space('preferencesFile'), 'blah', Alice.doc())
|
|
265
|
+
expect(result).toEqual(AlicePreferencesFile)
|
|
266
|
+
|
|
267
|
+
})
|
|
268
|
+
it('creates empty file if did not exist and new link', async () => {
|
|
269
|
+
const suggestion = 'https://bob.example.com/settings/prefsSuggestion.ttl'
|
|
270
|
+
const newFile = sym(suggestion)
|
|
271
|
+
const result = await followOrCreateLink(store, Bob, ns.space('preferencesFile'), sym(suggestion), Bob.doc())
|
|
272
|
+
expect(result).toEqual(sym(suggestion))
|
|
273
|
+
expect(requests[0].method).toEqual('PATCH') // or patch first?
|
|
274
|
+
expect(requests[0].url).toEqual(Bob.doc().uri)
|
|
275
|
+
expect(requests[1].method).toEqual('PUT') // or patch first?
|
|
276
|
+
expect(requests[1].url).toEqual(suggestion)
|
|
277
|
+
expect(store.holds(Bob, ns.space('preferencesFile'), sym(suggestion), Bob.doc())).toEqual(true)
|
|
278
|
+
})
|
|
279
|
+
//
|
|
280
|
+
it('returns null if it cannot create the new file', async () => {
|
|
281
|
+
const suggestion = 'https://bob.example.com/settings/prefsSuggestion.ttl'
|
|
282
|
+
const newFile = sym(suggestion)
|
|
283
|
+
statustoBeReturned = 403 // Unauthorized
|
|
284
|
+
const result = await followOrCreateLink(store, Bob, ns.space('preferencesFile'), sym(suggestion), Bob.doc())
|
|
285
|
+
expect(result).toEqual(null)
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
describe('loadProfile', () => {
|
|
291
|
+
it('exists', () => {
|
|
292
|
+
expect(loadProfile).toBeInstanceOf(Function)
|
|
293
|
+
})
|
|
294
|
+
it('loads data', async () => {
|
|
295
|
+
const result = await loadProfile(store, user)
|
|
296
|
+
expect(result).toBeInstanceOf(Object)
|
|
297
|
+
expect(result.uri).toEqual(AliceProfileFile.uri)
|
|
298
|
+
expect(store.holds(user, ns.rdf('type'), ns.vcard('Individual'), profile)).toEqual(true)
|
|
299
|
+
expect(store.holds(user, ns.space('preferencesFile'), AlicePreferencesFile, profile)).toEqual(true)
|
|
300
|
+
expect(store.statementsMatching(null, null, null, profile).length).toEqual(4)
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
describe('loadPreferences', () => {
|
|
305
|
+
it('exists', () => {
|
|
306
|
+
expect(loadPreferences).toBeInstanceOf(Function)
|
|
307
|
+
})
|
|
308
|
+
it('loads data', async () => {
|
|
309
|
+
const result = await loadPreferences(store, Alice)
|
|
310
|
+
expect(result).toBeInstanceOf(Object)
|
|
311
|
+
expect(result.uri).toEqual(AlicePreferencesFile.uri)
|
|
312
|
+
expect(store.holds(user, ns.rdf('type'), ns.vcard('Individual'), profile)).toEqual(true)
|
|
313
|
+
expect(store.statementsMatching(null, null, null, profile).length).toEqual(4)
|
|
314
|
+
|
|
315
|
+
expect(store.statementsMatching(null, null, null, AlicePreferencesFile).length).toEqual(2)
|
|
316
|
+
expect(store.holds(user, ns.solid('privateTypeIndex'), AlicePrivateTypeIndex, AlicePreferencesFile)).toEqual(true)
|
|
317
|
+
})
|
|
318
|
+
it('creates new file', async () => {
|
|
319
|
+
const result = await loadPreferences(store, Bob)
|
|
320
|
+
|
|
321
|
+
const patchRequest = requests[0]
|
|
322
|
+
expect(patchRequest.method).toEqual('PATCH')
|
|
323
|
+
expect(patchRequest.url).toEqual(Bob.doc().uri)
|
|
324
|
+
const text = await patchRequest.text()
|
|
325
|
+
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> .')
|
|
326
|
+
|
|
327
|
+
const putRequest = requests[1]
|
|
328
|
+
expect(putRequest.method).toEqual('PUT')
|
|
329
|
+
expect(putRequest.url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
|
|
330
|
+
// const text2 = await putRequest.text()
|
|
331
|
+
expect(web[putRequest.url]).toEqual('')
|
|
332
|
+
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
const AliceScopes = [ {
|
|
338
|
+
"agent": {
|
|
339
|
+
"classOrder": 5,
|
|
340
|
+
"termType": "NamedNode",
|
|
341
|
+
"value": "https://alice.example.com/profile/card.ttl#me",
|
|
342
|
+
},
|
|
343
|
+
"index": {
|
|
344
|
+
"classOrder": 5,
|
|
345
|
+
"termType": "NamedNode",
|
|
346
|
+
"value": "https://alice.example.com/profle/public-type-index.ttl",
|
|
347
|
+
},
|
|
348
|
+
"label": "public",
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
"agent": {
|
|
352
|
+
"classOrder": 5,
|
|
353
|
+
"termType": "NamedNode",
|
|
354
|
+
"value": "https://alice.example.com/profile/card.ttl#me",
|
|
355
|
+
},
|
|
356
|
+
"index": {
|
|
357
|
+
"classOrder": 5,
|
|
358
|
+
"termType": "NamedNode",
|
|
359
|
+
"value": "https://alice.example.com/settings/private-type-index.ttl",
|
|
360
|
+
},
|
|
361
|
+
"label": "private",
|
|
362
|
+
}
|
|
363
|
+
];
|
|
364
|
+
|
|
365
|
+
describe('loadTypeIndexesFor', () => {
|
|
366
|
+
it('exists', () => {
|
|
367
|
+
expect(loadTypeIndexesFor).toBeInstanceOf(Function)
|
|
368
|
+
})
|
|
369
|
+
it('loads data', async () => {
|
|
370
|
+
const result = await loadTypeIndexesFor(store, user)
|
|
371
|
+
expect(result).toEqual(AliceScopes)
|
|
372
|
+
expect(store.statementsMatching(null, null, null, AlicePrivateTypeIndex).length).toEqual(
|
|
373
|
+
|
|
374
|
+
8)
|
|
375
|
+
expect(store.statementsMatching(null, null, null, AlicePublicTypeIndex).length).toEqual(8)
|
|
376
|
+
})
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
const ClubScopes =
|
|
380
|
+
[
|
|
381
|
+
{
|
|
382
|
+
"agent": {
|
|
383
|
+
"classOrder": 5,
|
|
384
|
+
"termType": "NamedNode",
|
|
385
|
+
"value": "https://club.example.com/profile/card.ttl#it",
|
|
386
|
+
},
|
|
387
|
+
"index": {
|
|
388
|
+
"classOrder": 5,
|
|
389
|
+
"termType": "NamedNode",
|
|
390
|
+
"value": "https://club.example.com/profle/public-type-index.ttl",
|
|
391
|
+
},
|
|
392
|
+
"label": "public",
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
"agent": {
|
|
396
|
+
"classOrder": 5,
|
|
397
|
+
"termType": "NamedNode",
|
|
398
|
+
"value": "https://club.example.com/profile/card.ttl#it",
|
|
399
|
+
},
|
|
400
|
+
"index": {
|
|
401
|
+
"classOrder": 5,
|
|
402
|
+
"termType": "NamedNode",
|
|
403
|
+
"value": "https://club.example.com/settings/private-type-index.ttl",
|
|
404
|
+
},
|
|
405
|
+
"label": "private",
|
|
406
|
+
},
|
|
407
|
+
];
|
|
408
|
+
describe('loadCommunityTypeIndexes', () => {
|
|
409
|
+
it('exists', () => {
|
|
410
|
+
expect(loadCommunityTypeIndexes).toBeInstanceOf(Function)
|
|
411
|
+
})
|
|
412
|
+
it('loads data', async () => {
|
|
413
|
+
const result = await loadCommunityTypeIndexes(store, user) // @@ tbd
|
|
414
|
+
expect(result).toEqual(ClubScopes)
|
|
415
|
+
})
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
const AliceAndClubScopes =
|
|
419
|
+
[
|
|
420
|
+
{
|
|
421
|
+
"instance": {
|
|
422
|
+
"classOrder": 5,
|
|
423
|
+
"termType": "NamedNode",
|
|
424
|
+
"value": "https://alice.example.com/publicStuff/actionItems.ttl#this",
|
|
425
|
+
},
|
|
426
|
+
"scope": {
|
|
427
|
+
"agent": {
|
|
428
|
+
"classOrder": 5,
|
|
429
|
+
"termType": "NamedNode",
|
|
430
|
+
"value": "https://alice.example.com/profile/card.ttl#me",
|
|
431
|
+
},
|
|
432
|
+
"index": {
|
|
433
|
+
"classOrder": 5,
|
|
434
|
+
"termType": "NamedNode",
|
|
435
|
+
"value": "https://alice.example.com/profle/public-type-index.ttl",
|
|
436
|
+
},
|
|
437
|
+
"label": "public",
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
"instance": {
|
|
442
|
+
"classOrder": 5,
|
|
443
|
+
"termType": "NamedNode",
|
|
444
|
+
"value": "https://alice.example.com/project4/issues.ttl#this",
|
|
445
|
+
},
|
|
446
|
+
"scope": {
|
|
447
|
+
"agent": {
|
|
448
|
+
"classOrder": 5,
|
|
449
|
+
"termType": "NamedNode",
|
|
450
|
+
"value": "https://alice.example.com/profile/card.ttl#me",
|
|
451
|
+
},
|
|
452
|
+
"index": {
|
|
453
|
+
"classOrder": 5,
|
|
454
|
+
"termType": "NamedNode",
|
|
455
|
+
"value": "https://alice.example.com/profle/public-type-index.ttl",
|
|
456
|
+
},
|
|
457
|
+
"label": "public",
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
"instance": {
|
|
462
|
+
"classOrder": 5,
|
|
463
|
+
"termType": "NamedNode",
|
|
464
|
+
"value": "https://alice.example.com/privateStuff/ToDo.ttl#this",
|
|
465
|
+
},
|
|
466
|
+
"scope": {
|
|
467
|
+
"agent": {
|
|
468
|
+
"classOrder": 5,
|
|
469
|
+
"termType": "NamedNode",
|
|
470
|
+
"value": "https://alice.example.com/profile/card.ttl#me",
|
|
471
|
+
},
|
|
472
|
+
"index": {
|
|
473
|
+
"classOrder": 5,
|
|
474
|
+
"termType": "NamedNode",
|
|
475
|
+
"value": "https://alice.example.com/settings/private-type-index.ttl",
|
|
476
|
+
},
|
|
477
|
+
"label": "private",
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
"instance": {
|
|
482
|
+
"classOrder": 5,
|
|
483
|
+
"termType": "NamedNode",
|
|
484
|
+
"value": "https://alice.example.com/privateStuff/Goals.ttl#this",
|
|
485
|
+
},
|
|
486
|
+
"scope": {
|
|
487
|
+
"agent": {
|
|
488
|
+
"classOrder": 5,
|
|
489
|
+
"termType": "NamedNode",
|
|
490
|
+
"value": "https://alice.example.com/profile/card.ttl#me",
|
|
491
|
+
},
|
|
492
|
+
"index": {
|
|
493
|
+
"classOrder": 5,
|
|
494
|
+
"termType": "NamedNode",
|
|
495
|
+
"value": "https://alice.example.com/settings/private-type-index.ttl",
|
|
496
|
+
},
|
|
497
|
+
"label": "private",
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
"instance": {
|
|
502
|
+
"classOrder": 5,
|
|
503
|
+
"termType": "NamedNode",
|
|
504
|
+
"value": "https://alice.example.com/privateStuff/workingOn.ttl#this",
|
|
505
|
+
},
|
|
506
|
+
"scope": {
|
|
507
|
+
"agent": {
|
|
508
|
+
"classOrder": 5,
|
|
509
|
+
"termType": "NamedNode",
|
|
510
|
+
"value": "https://alice.example.com/profile/card.ttl#me",
|
|
511
|
+
},
|
|
512
|
+
"index": {
|
|
513
|
+
"classOrder": 5,
|
|
514
|
+
"termType": "NamedNode",
|
|
515
|
+
"value": "https://alice.example.com/settings/private-type-index.ttl",
|
|
516
|
+
},
|
|
517
|
+
"label": "private",
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
"instance": {
|
|
522
|
+
"classOrder": 5,
|
|
523
|
+
"termType": "NamedNode",
|
|
524
|
+
"value": "https://club.example.com/publicStuff/actionItems.ttl#this",
|
|
525
|
+
},
|
|
526
|
+
"scope": {
|
|
527
|
+
"agent": {
|
|
528
|
+
"classOrder": 5,
|
|
529
|
+
"termType": "NamedNode",
|
|
530
|
+
"value": "https://club.example.com/profile/card.ttl#it",
|
|
531
|
+
},
|
|
532
|
+
"index": {
|
|
533
|
+
"classOrder": 5,
|
|
534
|
+
"termType": "NamedNode",
|
|
535
|
+
"value": "https://club.example.com/profle/public-type-index.ttl",
|
|
536
|
+
},
|
|
537
|
+
"label": "public",
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
"instance": {
|
|
542
|
+
"classOrder": 5,
|
|
543
|
+
"termType": "NamedNode",
|
|
544
|
+
"value": "https://club.example.com/project4/clubIssues.ttl#this",
|
|
545
|
+
},
|
|
546
|
+
"scope": {
|
|
547
|
+
"agent": {
|
|
548
|
+
"classOrder": 5,
|
|
549
|
+
"termType": "NamedNode",
|
|
550
|
+
"value": "https://club.example.com/profile/card.ttl#it",
|
|
551
|
+
},
|
|
552
|
+
"index": {
|
|
553
|
+
"classOrder": 5,
|
|
554
|
+
"termType": "NamedNode",
|
|
555
|
+
"value": "https://club.example.com/profle/public-type-index.ttl",
|
|
556
|
+
},
|
|
557
|
+
"label": "public",
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
"instance": {
|
|
562
|
+
"classOrder": 5,
|
|
563
|
+
"termType": "NamedNode",
|
|
564
|
+
"value": "https://club.example.com/privateStuff/ToDo.ttl#this",
|
|
565
|
+
},
|
|
566
|
+
"scope": {
|
|
567
|
+
"agent": {
|
|
568
|
+
"classOrder": 5,
|
|
569
|
+
"termType": "NamedNode",
|
|
570
|
+
"value": "https://club.example.com/profile/card.ttl#it",
|
|
571
|
+
},
|
|
572
|
+
"index": {
|
|
573
|
+
"classOrder": 5,
|
|
574
|
+
"termType": "NamedNode",
|
|
575
|
+
"value": "https://club.example.com/settings/private-type-index.ttl",
|
|
576
|
+
},
|
|
577
|
+
"label": "private",
|
|
578
|
+
},
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
"instance": {
|
|
582
|
+
"classOrder": 5,
|
|
583
|
+
"termType": "NamedNode",
|
|
584
|
+
"value": "https://club.example.com/privateStuff/Goals.ttl#this",
|
|
585
|
+
},
|
|
586
|
+
"scope": {
|
|
587
|
+
"agent": {
|
|
588
|
+
"classOrder": 5,
|
|
589
|
+
"termType": "NamedNode",
|
|
590
|
+
"value": "https://club.example.com/profile/card.ttl#it",
|
|
591
|
+
},
|
|
592
|
+
"index": {
|
|
593
|
+
"classOrder": 5,
|
|
594
|
+
"termType": "NamedNode",
|
|
595
|
+
"value": "https://club.example.com/settings/private-type-index.ttl",
|
|
596
|
+
},
|
|
597
|
+
"label": "private",
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
"instance": {
|
|
602
|
+
"classOrder": 5,
|
|
603
|
+
"termType": "NamedNode",
|
|
604
|
+
"value": "https://club.example.com/privateStuff/tasks.ttl#this",
|
|
605
|
+
},
|
|
606
|
+
"scope": {
|
|
607
|
+
"agent": {
|
|
608
|
+
"classOrder": 5,
|
|
609
|
+
"termType": "NamedNode",
|
|
610
|
+
"value": "https://club.example.com/profile/card.ttl#it",
|
|
611
|
+
},
|
|
612
|
+
"index": {
|
|
613
|
+
"classOrder": 5,
|
|
614
|
+
"termType": "NamedNode",
|
|
615
|
+
"value": "https://club.example.com/settings/private-type-index.ttl",
|
|
616
|
+
},
|
|
617
|
+
"label": "private",
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
]
|
|
621
|
+
|
|
622
|
+
describe('getScopedAppInstances', () => {
|
|
623
|
+
it('exists', () => {
|
|
624
|
+
expect(getScopedAppInstances).toBeInstanceOf(Function)
|
|
625
|
+
})
|
|
626
|
+
it('pulls in users scopes and also community ones', async () => {
|
|
627
|
+
const result = await getScopedAppInstances(store, Tracker, user)
|
|
628
|
+
expect(result).toEqual(AliceAndClubScopes)
|
|
629
|
+
})
|
|
630
|
+
it('creates new typeIndeex files where they dont exist', async () => {
|
|
631
|
+
const result = await getScopedAppInstances(store, Tracker, Bob)
|
|
632
|
+
|
|
633
|
+
expect(requests[0].method).toEqual('PATCH') // Add link to preferrencesFile
|
|
634
|
+
expect(requests[0].url).toEqual('https://bob.example.com/profile/card.ttl')
|
|
635
|
+
|
|
636
|
+
expect(requests[1].method).toEqual('PUT') // Link to pub typ ind
|
|
637
|
+
expect(requests[1].url).toEqual('https://bob.example.com/profile/publicTypeIndex.ttl')
|
|
638
|
+
|
|
639
|
+
expect(requests[2].method).toEqual('PATCH') // Add link to preferrencesFile
|
|
640
|
+
expect(requests[2].url).toEqual('https://bob.example.com/profile/card.ttl')
|
|
641
|
+
|
|
642
|
+
expect(requests[3].method).toEqual('PATCH')
|
|
643
|
+
expect(requests[3].url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
|
|
644
|
+
|
|
645
|
+
expect(requests[4].method).toEqual('PUT')
|
|
646
|
+
expect(requests[4].url).toEqual('https://bob.example.com/Settings/privateTypeIndex.ttl')
|
|
647
|
+
|
|
648
|
+
expect(requests.length).toEqual(5)
|
|
649
|
+
|
|
650
|
+
})
|
|
651
|
+
})
|
|
652
|
+
|
|
653
|
+
const TRACKERS =
|
|
654
|
+
[
|
|
655
|
+
{
|
|
656
|
+
"classOrder": 5,
|
|
657
|
+
"termType": "NamedNode",
|
|
658
|
+
"value": "https://alice.example.com/publicStuff/actionItems.ttl#this",
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
"classOrder": 5,
|
|
662
|
+
"termType": "NamedNode",
|
|
663
|
+
"value": "https://alice.example.com/project4/issues.ttl#this",
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
"classOrder": 5,
|
|
667
|
+
"termType": "NamedNode",
|
|
668
|
+
"value": "https://alice.example.com/privateStuff/ToDo.ttl#this",
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
"classOrder": 5,
|
|
672
|
+
"termType": "NamedNode",
|
|
673
|
+
"value": "https://alice.example.com/privateStuff/Goals.ttl#this",
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
"classOrder": 5,
|
|
677
|
+
"termType": "NamedNode",
|
|
678
|
+
"value": "https://alice.example.com/privateStuff/workingOn.ttl#this",
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
"classOrder": 5,
|
|
682
|
+
"termType": "NamedNode",
|
|
683
|
+
"value": "https://club.example.com/publicStuff/actionItems.ttl#this",
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
"classOrder": 5,
|
|
687
|
+
"termType": "NamedNode",
|
|
688
|
+
"value": "https://club.example.com/project4/clubIssues.ttl#this",
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
"classOrder": 5,
|
|
692
|
+
"termType": "NamedNode",
|
|
693
|
+
"value": "https://club.example.com/privateStuff/ToDo.ttl#this",
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
"classOrder": 5,
|
|
697
|
+
"termType": "NamedNode",
|
|
698
|
+
"value": "https://club.example.com/privateStuff/Goals.ttl#this",
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
"classOrder": 5,
|
|
702
|
+
"termType": "NamedNode",
|
|
703
|
+
"value": "https://club.example.com/privateStuff/tasks.ttl#this",
|
|
704
|
+
},
|
|
705
|
+
]
|
|
706
|
+
|
|
707
|
+
describe('getAppInstances', () => {
|
|
708
|
+
it('exists', () => {
|
|
709
|
+
expect(getAppInstances).toBeInstanceOf(Function)
|
|
710
|
+
})
|
|
711
|
+
it('finds trackers', async () => {
|
|
712
|
+
const result = await getAppInstances(store, Tracker)
|
|
713
|
+
expect(result).toEqual(TRACKERS)
|
|
714
|
+
expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
|
|
715
|
+
})
|
|
716
|
+
it('finds images in containers', async () => {
|
|
717
|
+
const result = await getAppInstances(store, Image)
|
|
718
|
+
expect(result.length).toEqual(3)
|
|
719
|
+
expect(result).toEqual(uniqueNodes(result)) // shoud have no dups
|
|
720
|
+
expect(result.map(x => x.uri).join()).toEqual("https://alice.example.com/profile/Photos/photo1.png,https://alice.example.com/profile/Photos/photo2.png,https://alice.example.com/profile/Photos/photo3.png")
|
|
721
|
+
})
|
|
722
|
+
})
|
|
723
|
+
|
|
724
|
+
describe('registerInstanceInTypeIndex', () => {
|
|
725
|
+
it('exists', () => {
|
|
726
|
+
expect(registerInstanceInTypeIndex).toBeInstanceOf(Function)
|
|
727
|
+
})
|
|
728
|
+
it('adds a registration', async () => {
|
|
729
|
+
const instance = sym(Alice.doc().uri + 'trackers/myToDo.ttl#this')
|
|
730
|
+
const index = AlicePublicTypeIndex
|
|
731
|
+
const result = await registerInstanceInTypeIndex(store, instance, index, klass)
|
|
732
|
+
expect(result.doc()).toEqual(index)
|
|
733
|
+
expect(store.any(result, ns.solid('forClass'), null, index)).toEqual(klass)
|
|
734
|
+
expect(store.any(result, ns.solid('instance'), null, index)).toEqual(instance)
|
|
735
|
+
expect(store.holds(result, ns.rdf('type'), ns.solid('TypeRegistration'), index)).toEqual(true)
|
|
736
|
+
expect(requests[0].url).toEqual(index.uri)
|
|
737
|
+
})
|
|
738
|
+
})
|
|
739
|
+
|
|
740
|
+
})
|