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