solid-logic 3.0.9-f327aa58 → 3.0.9-f51524a8
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/babel.config.js +6 -0
- package/eslint.config.js +23 -24
- package/jest.config.js +15 -8
- package/lib/acl/aclLogic.d.ts +2 -2
- package/lib/acl/aclLogic.d.ts.map +1 -1
- package/lib/authSession/authSession.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.d.ts +3 -3
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/authUtil.d.ts +1 -1
- package/lib/chat/chatLogic.d.ts +1 -1
- package/lib/inbox/inboxLogic.d.ts +1 -1
- package/lib/inbox/inboxLogic.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/solidLogic.d.ts +2 -2
- package/lib/logic/solidLogic.d.ts.map +1 -1
- package/lib/profile/profileLogic.d.ts +1 -1
- package/lib/solid-logic.js +107 -0
- package/lib/solid-logic.js.map +1 -0
- package/lib/types.d.ts +2 -2
- package/lib/util/containerLogic.d.ts +1 -1
- package/lib/util/containerLogic.d.ts.map +1 -1
- package/lib/util/debug.d.ts.map +1 -1
- package/lib/util/utilityLogic.d.ts +1 -1
- package/lib/util/utilityLogic.d.ts.map +1 -1
- package/lib/util/utils.d.ts +1 -1
- package/lib/util/utils.d.ts.map +1 -1
- package/package.json +39 -16
- package/rollup.config.js +29 -0
- package/src/acl/aclLogic.ts +8 -8
- package/src/authSession/authSession.ts +7 -1
- package/src/authn/SolidAuthnLogic.ts +7 -8
- package/src/authn/authUtil.ts +1 -1
- package/src/chat/chatLogic.ts +75 -75
- package/src/inbox/inboxLogic.ts +19 -19
- package/src/index.ts +1 -1
- package/src/logic/CustomError.ts +6 -6
- package/src/logic/solidLogic.ts +22 -22
- package/src/logic/solidLogicSingleton.ts +3 -3
- package/src/profile/profileLogic.ts +22 -22
- package/src/typeIndex/typeIndexLogic.ts +7 -7
- package/src/types.ts +2 -2
- package/src/util/containerLogic.ts +15 -15
- package/src/util/debug.ts +4 -8
- package/src/util/utilityLogic.ts +18 -18
- package/src/util/utils.ts +12 -12
- package/src/versionInfo.ts +32 -0
- package/test/aclLogic.test.ts +5 -5
- package/test/authUtil.test.ts +1 -1
- package/test/chatLogic.test.ts +160 -154
- package/test/container.test.ts +23 -23
- package/test/helpers/dataSetup.ts +2 -1
- package/test/helpers/setup.ts +8 -3
- package/test/inboxLogic.test.ts +101 -110
- package/test/logic.test.ts +2 -2
- package/test/profileLogic.test.ts +35 -33
- package/test/solidAuthLogic.test.ts +1 -1
- package/test/typeIndexLogic.test.ts +71 -71
- package/test/utilityLogic.test.ts +46 -45
- package/test/utils.test.ts +11 -11
- package/timestamp.sh +13 -0
- package/tsconfig.json +5 -3
- package/tsconfig.test.json +8 -0
- package/lib/acl/aclLogic.js +0 -168
- package/lib/acl/aclLogic.js.map +0 -1
- package/lib/authSession/authSession.js +0 -6
- package/lib/authSession/authSession.js.map +0 -1
- package/lib/authn/SolidAuthnLogic.js +0 -193
- package/lib/authn/SolidAuthnLogic.js.map +0 -1
- package/lib/authn/authUtil.js +0 -105
- package/lib/authn/authUtil.js.map +0 -1
- package/lib/chat/chatLogic.js +0 -272
- package/lib/chat/chatLogic.js.map +0 -1
- package/lib/inbox/inboxLogic.js +0 -139
- package/lib/inbox/inboxLogic.js.map +0 -1
- package/lib/index.js +0 -29
- package/lib/index.js.map +0 -1
- package/lib/issuer/issuerLogic.js +0 -52
- package/lib/issuer/issuerLogic.js.map +0 -1
- package/lib/logic/CustomError.js +0 -89
- package/lib/logic/CustomError.js.map +0 -1
- package/lib/logic/solidLogic.js +0 -102
- package/lib/logic/solidLogic.js.map +0 -1
- package/lib/logic/solidLogicSingleton.js +0 -94
- package/lib/logic/solidLogicSingleton.js.map +0 -1
- package/lib/profile/profileLogic.js +0 -259
- package/lib/profile/profileLogic.js.map +0 -1
- package/lib/typeIndex/typeIndexLogic.js +0 -399
- package/lib/typeIndex/typeIndexLogic.js.map +0 -1
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/lib/util/containerLogic.js +0 -102
- package/lib/util/containerLogic.js.map +0 -1
- package/lib/util/debug.js +0 -40
- package/lib/util/debug.js.map +0 -1
- package/lib/util/ns.js +0 -44
- package/lib/util/ns.js.map +0 -1
- package/lib/util/utilityLogic.js +0 -284
- package/lib/util/utilityLogic.js.map +0 -1
- package/lib/util/utils.js +0 -47
- package/lib/util/utils.js.map +0 -1
package/test/chatLogic.test.ts
CHANGED
|
@@ -2,91 +2,97 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
|
-
import { UpdateManager, Store, Fetcher } from
|
|
6
|
-
import { createAclLogic } from
|
|
7
|
-
import { createChatLogic } from '../src/chat/chatLogic'
|
|
8
|
-
import { createProfileLogic } from
|
|
9
|
-
import { createContainerLogic } from
|
|
10
|
-
import { createUtilityLogic } from
|
|
11
|
-
import { alice, bob } from
|
|
5
|
+
import { UpdateManager, Store, Fetcher } from 'rdflib'
|
|
6
|
+
import { createAclLogic } from '../src/acl/aclLogic'
|
|
7
|
+
import { createChatLogic } from '../src/chat/chatLogic'
|
|
8
|
+
import { createProfileLogic } from '../src/profile/profileLogic'
|
|
9
|
+
import { createContainerLogic } from '../src/util/containerLogic'
|
|
10
|
+
import { createUtilityLogic } from '../src/util/utilityLogic'
|
|
11
|
+
import { alice, bob } from './helpers/dataSetup'
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
interface Window {
|
|
15
|
+
$SolidTestEnvironment?: { username: string }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
12
18
|
|
|
13
19
|
window.$SolidTestEnvironment = { username: alice.uri }
|
|
14
20
|
|
|
15
|
-
describe(
|
|
16
|
-
let chatLogic
|
|
17
|
-
let store
|
|
21
|
+
describe('Chat logic', () => {
|
|
22
|
+
let chatLogic
|
|
23
|
+
let store
|
|
18
24
|
beforeEach(() => {
|
|
19
|
-
fetchMock.resetMocks()
|
|
20
|
-
fetchMock.mockResponse(
|
|
25
|
+
fetchMock.resetMocks()
|
|
26
|
+
fetchMock.mockResponse('Not Found', {
|
|
21
27
|
status: 404,
|
|
22
|
-
})
|
|
28
|
+
})
|
|
23
29
|
store = new Store()
|
|
24
|
-
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
25
|
-
store.updater = new UpdateManager(store)
|
|
30
|
+
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
31
|
+
store.updater = new UpdateManager(store)
|
|
26
32
|
const authn = {
|
|
27
33
|
currentUser: () => {
|
|
28
|
-
return alice
|
|
34
|
+
return alice
|
|
29
35
|
},
|
|
30
|
-
}
|
|
36
|
+
}
|
|
31
37
|
const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
|
|
32
38
|
chatLogic = createChatLogic(store, createProfileLogic(store, authn, util))
|
|
33
|
-
})
|
|
39
|
+
})
|
|
34
40
|
|
|
35
|
-
describe(
|
|
36
|
-
describe(
|
|
37
|
-
let result
|
|
41
|
+
describe('get chat, without creating', () => {
|
|
42
|
+
describe('when no chat exists yet', () => {
|
|
43
|
+
let result
|
|
38
44
|
beforeEach(async () => {
|
|
39
|
-
aliceHasValidProfile()
|
|
40
|
-
noChatWithBobExists()
|
|
41
|
-
result = await chatLogic.getChat(bob, false)
|
|
42
|
-
})
|
|
43
|
-
it(
|
|
44
|
-
expect(result).toBeNull()
|
|
45
|
-
})
|
|
46
|
-
it(
|
|
45
|
+
aliceHasValidProfile()
|
|
46
|
+
noChatWithBobExists()
|
|
47
|
+
result = await chatLogic.getChat(bob, false)
|
|
48
|
+
})
|
|
49
|
+
it('does not return a chat', async () => {
|
|
50
|
+
expect(result).toBeNull()
|
|
51
|
+
})
|
|
52
|
+
it('loaded the current user profile', () => {
|
|
47
53
|
expect(fetchMock.mock.calls[0][0]).toBe(
|
|
48
|
-
|
|
49
|
-
)
|
|
50
|
-
})
|
|
51
|
-
it(
|
|
54
|
+
'https://alice.example.com/profile/card.ttl'
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
it('tried to load the chat document', () => {
|
|
52
58
|
expect(fetchMock.mock.calls[1][0]).toBe(
|
|
53
|
-
|
|
54
|
-
)
|
|
55
|
-
})
|
|
56
|
-
it(
|
|
57
|
-
expect(fetchMock.mock.calls.length).toBe(2)
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
})
|
|
59
|
+
'https://alice.example.com/IndividualChats/bob.example.com/index.ttl'
|
|
60
|
+
)
|
|
61
|
+
})
|
|
62
|
+
it('has no additional fetch requests', () => {
|
|
63
|
+
expect(fetchMock.mock.calls.length).toBe(2)
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
})
|
|
61
67
|
|
|
62
|
-
describe(
|
|
63
|
-
describe(
|
|
64
|
-
let result
|
|
68
|
+
describe('get chat, create if missing', () => {
|
|
69
|
+
describe('when no chat exists yet', () => {
|
|
70
|
+
let result
|
|
65
71
|
beforeEach(async () => {
|
|
66
72
|
Date.now = jest.fn(() =>
|
|
67
73
|
new Date(Date.UTC(2021, 1, 6, 10, 11, 12)).valueOf()
|
|
68
|
-
)
|
|
69
|
-
aliceHasValidProfile()
|
|
70
|
-
noChatWithBobExists()
|
|
71
|
-
chatWithBobCanBeCreated()
|
|
72
|
-
bobHasAnInbox()
|
|
73
|
-
invitationCanBeSent()
|
|
74
|
-
chatContainerIsFound()
|
|
75
|
-
chatContainerAclCanBeSet()
|
|
76
|
-
editablePrivateTypeIndexIsFound()
|
|
77
|
-
privateTypeIndexIsUpdated()
|
|
78
|
-
result = await chatLogic.getChat(bob, true)
|
|
79
|
-
})
|
|
80
|
-
it(
|
|
74
|
+
)
|
|
75
|
+
aliceHasValidProfile()
|
|
76
|
+
noChatWithBobExists()
|
|
77
|
+
chatWithBobCanBeCreated()
|
|
78
|
+
bobHasAnInbox()
|
|
79
|
+
invitationCanBeSent()
|
|
80
|
+
chatContainerIsFound()
|
|
81
|
+
chatContainerAclCanBeSet()
|
|
82
|
+
editablePrivateTypeIndexIsFound()
|
|
83
|
+
privateTypeIndexIsUpdated()
|
|
84
|
+
result = await chatLogic.getChat(bob, true)
|
|
85
|
+
})
|
|
86
|
+
it('returns the chat URI based on the invitee\'s WebID', () => {
|
|
81
87
|
expect(result.uri).toBe(
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
})
|
|
85
|
-
it(
|
|
88
|
+
'https://alice.example.com/IndividualChats/bob.example.com/index.ttl#this'
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
it('created a chat document', () => {
|
|
86
92
|
const request = getRequestTo(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
93
|
+
'PUT',
|
|
94
|
+
'https://alice.example.com/IndividualChats/bob.example.com/index.ttl'
|
|
95
|
+
)
|
|
90
96
|
expect(request.body).toBe(`@prefix : <#>.
|
|
91
97
|
@prefix dc: <http://purl.org/dc/elements/1.1/>.
|
|
92
98
|
@prefix meeting: <http://www.w3.org/ns/pim/meeting#>.
|
|
@@ -98,13 +104,13 @@ describe("Chat logic", () => {
|
|
|
98
104
|
dc:author c:me;
|
|
99
105
|
dc:created "2021-02-06T10:11:12Z"^^xsd:dateTime;
|
|
100
106
|
dc:title "Chat channel".
|
|
101
|
-
`)
|
|
102
|
-
})
|
|
103
|
-
it(
|
|
107
|
+
`)
|
|
108
|
+
})
|
|
109
|
+
it('allowed Bob to participate in the chat by adding an ACL', () => {
|
|
104
110
|
const request = getRequestTo(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
)
|
|
111
|
+
'PUT',
|
|
112
|
+
'https://alice.example.com/IndividualChats/bob.example.com/.acl'
|
|
113
|
+
)
|
|
108
114
|
expect(request.body).toBe(`
|
|
109
115
|
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
|
|
110
116
|
<#owner>
|
|
@@ -121,59 +127,59 @@ describe("Chat logic", () => {
|
|
|
121
127
|
acl:default <.>;
|
|
122
128
|
acl:mode
|
|
123
129
|
acl:Read, acl:Append.
|
|
124
|
-
`)
|
|
125
|
-
})
|
|
126
|
-
it(
|
|
127
|
-
const request = getRequestTo(
|
|
130
|
+
`)
|
|
131
|
+
})
|
|
132
|
+
it('sent an invitation to invitee inbox', () => {
|
|
133
|
+
const request = getRequestTo('POST', 'https://bob.example.com/inbox')
|
|
128
134
|
expect(request.body).toContain(`
|
|
129
135
|
<> a <http://www.w3.org/ns/pim/meeting#LongChatInvite> ;
|
|
130
136
|
<http://www.w3.org/1999/02/22-rdf-syntax-ns#seeAlso> <https://alice.example.com/IndividualChats/bob.example.com/index.ttl#this> .
|
|
131
|
-
`)
|
|
132
|
-
})
|
|
133
|
-
it(
|
|
137
|
+
`)
|
|
138
|
+
})
|
|
139
|
+
it('added the new chat to private type index', () => {
|
|
134
140
|
const request = getRequestTo(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
)
|
|
141
|
+
'PATCH',
|
|
142
|
+
'https://alice.example.com/settings/privateTypeIndex.ttl'
|
|
143
|
+
)
|
|
138
144
|
expect(request.body)
|
|
139
145
|
.toBe(`INSERT DATA { <https://alice.example.com/settings/privateTypeIndex.ttl#id1612606272000> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/solid/terms#TypeRegistration> .
|
|
140
146
|
<https://alice.example.com/settings/privateTypeIndex.ttl#id1612606272000> <http://www.w3.org/ns/solid/terms#forClass> <http://www.w3.org/ns/pim/meeting#LongChat> .
|
|
141
147
|
<https://alice.example.com/settings/privateTypeIndex.ttl#id1612606272000> <http://www.w3.org/ns/solid/terms#instance> <https://alice.example.com/IndividualChats/bob.example.com/index.ttl#this> .
|
|
142
148
|
}
|
|
143
|
-
`)
|
|
144
|
-
})
|
|
145
|
-
it(
|
|
146
|
-
expect(fetchMock.mock.calls.length).toBe(9)
|
|
147
|
-
})
|
|
148
|
-
})
|
|
149
|
-
})
|
|
149
|
+
`)
|
|
150
|
+
})
|
|
151
|
+
it('has no additional fetch requests', () => {
|
|
152
|
+
expect(fetchMock.mock.calls.length).toBe(9)
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
})
|
|
150
156
|
|
|
151
|
-
describe(
|
|
152
|
-
it(
|
|
153
|
-
fetchMock.mockOnceIf(
|
|
157
|
+
describe('possible errors', () => {
|
|
158
|
+
it('profile does not link to storage', async () => {
|
|
159
|
+
fetchMock.mockOnceIf('https://alice.example.com/profile/card.ttl', '<><><>.', {
|
|
154
160
|
headers: {
|
|
155
|
-
|
|
161
|
+
'Content-Type': 'text/turtle',
|
|
156
162
|
},
|
|
157
|
-
})
|
|
158
|
-
const expectedError = new Error(
|
|
159
|
-
await expect(chatLogic.getChat(bob, false)).rejects.toEqual(expectedError)
|
|
160
|
-
})
|
|
163
|
+
})
|
|
164
|
+
const expectedError = new Error('User pod root not found!')
|
|
165
|
+
await expect(chatLogic.getChat(bob, false)).rejects.toEqual(expectedError)
|
|
166
|
+
})
|
|
161
167
|
|
|
162
|
-
it(
|
|
163
|
-
aliceHasValidProfile()
|
|
164
|
-
noChatWithBobExists()
|
|
165
|
-
chatWithBobCanBeCreated()
|
|
166
|
-
bobDoesNotHaveAnInbox()
|
|
168
|
+
it('invitee inbox not found', async () => {
|
|
169
|
+
aliceHasValidProfile()
|
|
170
|
+
noChatWithBobExists()
|
|
171
|
+
chatWithBobCanBeCreated()
|
|
172
|
+
bobDoesNotHaveAnInbox()
|
|
167
173
|
const expectedError = new Error(
|
|
168
|
-
|
|
169
|
-
)
|
|
170
|
-
await expect(chatLogic.getChat(bob, true)).rejects.toEqual(expectedError)
|
|
171
|
-
})
|
|
172
|
-
})
|
|
174
|
+
'Invitee inbox not found! https://bob.example.com/profile/card.ttl#me'
|
|
175
|
+
)
|
|
176
|
+
await expect(chatLogic.getChat(bob, true)).rejects.toEqual(expectedError)
|
|
177
|
+
})
|
|
178
|
+
})
|
|
173
179
|
|
|
174
180
|
function aliceHasValidProfile() {
|
|
175
181
|
fetchMock.mockOnceIf(
|
|
176
|
-
|
|
182
|
+
'https://alice.example.com/profile/card.ttl',
|
|
177
183
|
`
|
|
178
184
|
<https://alice.example.com/profile/card.ttl#me>
|
|
179
185
|
<http://www.w3.org/ns/pim/space#storage> <https://alice.example.com/> ;
|
|
@@ -181,136 +187,136 @@ describe("Chat logic", () => {
|
|
|
181
187
|
.`,
|
|
182
188
|
{
|
|
183
189
|
headers: {
|
|
184
|
-
|
|
190
|
+
'Content-Type': 'text/turtle',
|
|
185
191
|
},
|
|
186
192
|
}
|
|
187
|
-
)
|
|
193
|
+
)
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
function noChatWithBobExists() {
|
|
191
197
|
return fetchMock.mockOnceIf(
|
|
192
198
|
({ url, method }) =>
|
|
193
|
-
url ===
|
|
194
|
-
method ===
|
|
195
|
-
|
|
199
|
+
url === 'https://alice.example.com/IndividualChats/bob.example.com/index.ttl' &&
|
|
200
|
+
method === 'GET',
|
|
201
|
+
'Not found',
|
|
196
202
|
{
|
|
197
203
|
status: 404,
|
|
198
204
|
}
|
|
199
|
-
)
|
|
205
|
+
)
|
|
200
206
|
}
|
|
201
207
|
|
|
202
208
|
function chatWithBobCanBeCreated() {
|
|
203
209
|
return fetchMock.mockOnceIf(
|
|
204
210
|
({ url, method }) =>
|
|
205
|
-
url ===
|
|
206
|
-
method ===
|
|
207
|
-
|
|
211
|
+
url === 'https://alice.example.com/IndividualChats/bob.example.com/index.ttl' &&
|
|
212
|
+
method === 'PUT',
|
|
213
|
+
'Created',
|
|
208
214
|
{
|
|
209
215
|
status: 201,
|
|
210
216
|
}
|
|
211
|
-
)
|
|
217
|
+
)
|
|
212
218
|
}
|
|
213
219
|
|
|
214
220
|
function bobHasAnInbox() {
|
|
215
221
|
fetchMock.mockOnceIf(
|
|
216
|
-
|
|
217
|
-
|
|
222
|
+
'https://bob.example.com/profile/card.ttl',
|
|
223
|
+
'<https://bob.example.com/profile/card.ttl#me><http://www.w3.org/ns/ldp#inbox><https://bob.example.com/inbox>.',
|
|
218
224
|
{
|
|
219
|
-
headers: {
|
|
225
|
+
headers: { 'Content-Type': 'text/turtle' },
|
|
220
226
|
}
|
|
221
|
-
)
|
|
227
|
+
)
|
|
222
228
|
}
|
|
223
229
|
|
|
224
230
|
function bobDoesNotHaveAnInbox() {
|
|
225
|
-
fetchMock.mockOnceIf(
|
|
231
|
+
fetchMock.mockOnceIf('https://bob.example.com/profile/card.ttl', '<><><>.', {
|
|
226
232
|
headers: {
|
|
227
|
-
|
|
233
|
+
'Content-Type': 'text/turtle',
|
|
228
234
|
},
|
|
229
|
-
})
|
|
235
|
+
})
|
|
230
236
|
}
|
|
231
237
|
|
|
232
238
|
function invitationCanBeSent() {
|
|
233
239
|
return fetchMock.mockOnceIf(
|
|
234
240
|
({ url, method }) =>
|
|
235
|
-
url ===
|
|
236
|
-
|
|
241
|
+
url === 'https://bob.example.com/inbox' && method === 'POST',
|
|
242
|
+
'Created',
|
|
237
243
|
{
|
|
238
244
|
status: 201,
|
|
239
245
|
headers: {
|
|
240
246
|
location:
|
|
241
|
-
|
|
247
|
+
'https://bob.example.com/inbox/22373339-6cc0-49fc-b69e-0402edda6e4e.ttl',
|
|
242
248
|
},
|
|
243
249
|
}
|
|
244
|
-
)
|
|
250
|
+
)
|
|
245
251
|
}
|
|
246
252
|
|
|
247
253
|
function chatContainerIsFound() {
|
|
248
254
|
return fetchMock.mockOnceIf(
|
|
249
255
|
({ url, method }) =>
|
|
250
|
-
url ===
|
|
251
|
-
method ===
|
|
252
|
-
|
|
256
|
+
url === 'https://alice.example.com/IndividualChats/bob.example.com/' &&
|
|
257
|
+
method === 'GET',
|
|
258
|
+
'<><><>.',
|
|
253
259
|
{
|
|
254
260
|
status: 200,
|
|
255
261
|
headers: {
|
|
256
|
-
|
|
262
|
+
'Content-Type': 'text/turtle',
|
|
257
263
|
Link: '<.acl>; rel="acl"',
|
|
258
264
|
},
|
|
259
265
|
}
|
|
260
|
-
)
|
|
266
|
+
)
|
|
261
267
|
}
|
|
262
268
|
|
|
263
269
|
function chatContainerAclCanBeSet() {
|
|
264
270
|
return fetchMock.mockOnceIf(
|
|
265
271
|
({ url, method }) =>
|
|
266
|
-
url ===
|
|
267
|
-
method ===
|
|
268
|
-
|
|
272
|
+
url === 'https://alice.example.com/IndividualChats/bob.example.com/.acl' &&
|
|
273
|
+
method === 'PUT',
|
|
274
|
+
'Created',
|
|
269
275
|
{
|
|
270
276
|
status: 201,
|
|
271
277
|
}
|
|
272
|
-
)
|
|
278
|
+
)
|
|
273
279
|
}
|
|
274
280
|
|
|
275
281
|
function editablePrivateTypeIndexIsFound() {
|
|
276
282
|
return fetchMock.mockOnceIf(
|
|
277
283
|
({ url, method }) =>
|
|
278
|
-
url ===
|
|
279
|
-
method ===
|
|
280
|
-
|
|
284
|
+
url === 'https://alice.example.com/settings/privateTypeIndex.ttl' &&
|
|
285
|
+
method === 'GET',
|
|
286
|
+
'<><><>.',
|
|
281
287
|
{
|
|
282
288
|
status: 200,
|
|
283
289
|
headers: {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
290
|
+
'Content-Type': 'text/turtle',
|
|
291
|
+
'wac-allow': 'user="read write append control",public=""',
|
|
292
|
+
'ms-author-via': 'SPARQL',
|
|
287
293
|
},
|
|
288
294
|
}
|
|
289
|
-
)
|
|
295
|
+
)
|
|
290
296
|
}
|
|
291
297
|
|
|
292
298
|
function privateTypeIndexIsUpdated() {
|
|
293
299
|
return fetchMock.mockOnceIf(
|
|
294
300
|
({ url, method }) =>
|
|
295
|
-
url ===
|
|
296
|
-
method ===
|
|
297
|
-
|
|
301
|
+
url === 'https://alice.example.com/settings/privateTypeIndex.ttl' &&
|
|
302
|
+
method === 'PATCH',
|
|
303
|
+
'OK',
|
|
298
304
|
{
|
|
299
305
|
status: 200,
|
|
300
306
|
}
|
|
301
|
-
)
|
|
307
|
+
)
|
|
302
308
|
}
|
|
303
309
|
|
|
304
310
|
function getRequestTo(
|
|
305
|
-
method:
|
|
311
|
+
method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'PATCH',
|
|
306
312
|
url: string
|
|
307
313
|
): RequestInit {
|
|
308
314
|
const call = fetchMock.mock.calls.find(
|
|
309
315
|
(it) => it[0] === url && method === it[1]?.method
|
|
310
|
-
)
|
|
311
|
-
expect(call).not.toBeNull()
|
|
312
|
-
const request = call?.[1]
|
|
313
|
-
expect(request).not.toBeNull()
|
|
314
|
-
return request
|
|
316
|
+
)
|
|
317
|
+
expect(call).not.toBeNull()
|
|
318
|
+
const request = call?.[1]
|
|
319
|
+
expect(request).not.toBeNull()
|
|
320
|
+
return request!
|
|
315
321
|
}
|
|
316
|
-
})
|
|
322
|
+
})
|
package/test/container.test.ts
CHANGED
|
@@ -2,57 +2,57 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*
|
|
4
4
|
*/
|
|
5
|
-
import { UpdateManager, Store, Fetcher, sym } from
|
|
6
|
-
import { createContainerLogic } from
|
|
7
|
-
import { alice } from
|
|
5
|
+
import { UpdateManager, Store, Fetcher, sym } from 'rdflib'
|
|
6
|
+
import { createContainerLogic } from '../src/util/containerLogic'
|
|
7
|
+
import { alice } from './helpers/dataSetup'
|
|
8
8
|
|
|
9
9
|
window.$SolidTestEnvironment = { username: alice.uri }
|
|
10
10
|
|
|
11
|
-
describe(
|
|
11
|
+
describe('Container', () => {
|
|
12
12
|
let store
|
|
13
13
|
let containerLogic
|
|
14
14
|
beforeEach(() => {
|
|
15
15
|
fetchMock.resetMocks()
|
|
16
16
|
store = new Store()
|
|
17
|
-
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
18
|
-
store.updater = new UpdateManager(store)
|
|
17
|
+
store.fetcher = new Fetcher(store, { fetch: fetch })
|
|
18
|
+
store.updater = new UpdateManager(store)
|
|
19
19
|
containerLogic = createContainerLogic(store)
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
it(
|
|
22
|
+
it('getContainerMembers - When container has some containment triples', async () => {
|
|
23
23
|
containerHasSomeContainmentTriples()
|
|
24
|
-
const containerMembers = await containerLogic.getContainerMembers(sym('https://container.com/'))
|
|
24
|
+
const containerMembers = await containerLogic.getContainerMembers(sym('https://container.com/'))
|
|
25
25
|
const result = containerMembers.map(oneResult => oneResult.value)
|
|
26
26
|
expect(result.sort()).toEqual([
|
|
27
27
|
'https://container.com/foo.txt',
|
|
28
28
|
'https://container.com/bar/'
|
|
29
|
-
].sort())
|
|
30
|
-
})
|
|
31
|
-
it.skip(
|
|
29
|
+
].sort())
|
|
30
|
+
})
|
|
31
|
+
it.skip('getContainerMembers- When container is empty - Resolves to an empty array', async () => {
|
|
32
32
|
jest.setTimeout(2000)
|
|
33
|
-
containerIsEmpty()
|
|
34
|
-
const result = await containerLogic.getContainerMembers(sym('https://container.com/'))
|
|
35
|
-
expect(result).toEqual([])
|
|
36
|
-
})
|
|
33
|
+
containerIsEmpty()
|
|
34
|
+
const result = await containerLogic.getContainerMembers(sym('https://container.com/'))
|
|
35
|
+
expect(result).toEqual([])
|
|
36
|
+
})
|
|
37
37
|
|
|
38
38
|
function containerIsEmpty() {
|
|
39
39
|
fetchMock.mockOnceIf(
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
'https://com/',
|
|
41
|
+
'', // FIXME: https://github.com/jefflau/jest-fetch-mock/issues/189
|
|
42
42
|
{
|
|
43
|
-
headers: {
|
|
43
|
+
headers: { 'Content-Type': 'text/turtle' },
|
|
44
44
|
}
|
|
45
|
-
)
|
|
45
|
+
)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function containerHasSomeContainmentTriples() {
|
|
49
49
|
fetchMock.mockOnceIf(
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
'https://container.com/',
|
|
51
|
+
'<.> <http://www.w3.org/ns/ldp#contains> <./foo.txt>, <./bar/> .',
|
|
52
52
|
{
|
|
53
|
-
headers: {
|
|
53
|
+
headers: { 'Content-Type': 'text/turtle' },
|
|
54
54
|
}
|
|
55
|
-
)
|
|
55
|
+
)
|
|
56
56
|
|
|
57
57
|
}
|
|
58
58
|
})
|
|
@@ -46,7 +46,8 @@ const AliceProfileFile = alice.doc()
|
|
|
46
46
|
const AlicePreferencesFile = sym('https://alice.example.com/settings/prefs.ttl')
|
|
47
47
|
const AlicePublicTypeIndex = sym('https://alice.example.com/profile/public-type-index.ttl')
|
|
48
48
|
const AlicePrivateTypeIndex = sym('https://alice.example.com/settings/private-type-index.ttl')
|
|
49
|
-
const
|
|
49
|
+
const aliceDir = alice.dir();
|
|
50
|
+
const AlicePhotoFolder = sym((aliceDir && aliceDir.uri ? aliceDir.uri : "") + "Photos/")
|
|
50
51
|
const AliceProfile = `
|
|
51
52
|
<#me> a vcard:Individual;
|
|
52
53
|
space:preferencesFile ${AlicePreferencesFile};
|
package/test/helpers/setup.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { error, log, trace, warn } from '../../src/util/debug'
|
|
2
2
|
import fetchMock from "jest-fetch-mock";
|
|
3
|
-
import { TextEncoder, TextDecoder } from 'util'
|
|
4
|
-
|
|
5
|
-
global.
|
|
3
|
+
import { TextEncoder as UtilTextEncoder, TextDecoder as UtilTextDecoder } from 'util'
|
|
4
|
+
|
|
5
|
+
if (typeof global.TextEncoder === 'undefined') {
|
|
6
|
+
global.TextEncoder = UtilTextEncoder as unknown as { new (): TextEncoder; prototype: TextEncoder }
|
|
7
|
+
}
|
|
8
|
+
if (typeof global.TextDecoder === 'undefined') {
|
|
9
|
+
global.TextDecoder = UtilTextDecoder as unknown as { new (): TextDecoder; prototype: TextDecoder }
|
|
10
|
+
}
|
|
6
11
|
|
|
7
12
|
|
|
8
13
|
fetchMock.enableMocks();
|