solid-logic 1.3.17-615b75c1 → 1.3.17-6e0634d8
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 +2 -2
- package/jest.config.js +1 -1
- package/lib/acl/aclLogic.d.ts +3 -30
- package/lib/acl/aclLogic.d.ts.map +1 -1
- package/lib/acl/aclLogic.js +150 -119
- package/lib/acl/aclLogic.js.map +1 -1
- package/lib/authn/SolidAuthnLogic.d.ts.map +1 -1
- package/lib/authn/SolidAuthnLogic.js +2 -2
- package/lib/authn/SolidAuthnLogic.js.map +1 -1
- package/lib/chat/chatLogic.d.ts +3 -0
- package/lib/chat/chatLogic.d.ts.map +1 -0
- package/lib/chat/{ChatLogic.js → chatLogic.js} +82 -86
- package/lib/chat/chatLogic.js.map +1 -0
- package/lib/inbox/inboxLogic.d.ts +3 -0
- package/lib/inbox/inboxLogic.d.ts.map +1 -0
- package/lib/inbox/{InboxLogic.js → inboxLogic.js} +59 -64
- package/lib/inbox/inboxLogic.js.map +1 -0
- package/lib/index.d.ts +6 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -25
- package/lib/index.js.map +1 -1
- package/lib/issuer/issuerLogic.js +1 -1
- package/lib/issuer/issuerLogic.js.map +1 -1
- package/lib/logic/CustomError.d.ts +4 -0
- package/lib/logic/CustomError.d.ts.map +1 -1
- package/lib/logic/CustomError.js +17 -1
- package/lib/logic/CustomError.js.map +1 -1
- package/lib/logic/solidLogic.d.ts +6 -0
- package/lib/logic/solidLogic.d.ts.map +1 -0
- package/lib/logic/solidLogic.js +92 -0
- package/lib/logic/solidLogic.js.map +1 -0
- package/lib/logic/solidLogicSingleton.d.ts +1 -2
- package/lib/logic/solidLogicSingleton.d.ts.map +1 -1
- package/lib/logic/solidLogicSingleton.js +3 -3
- package/lib/logic/solidLogicSingleton.js.map +1 -1
- package/lib/profile/profileLogic.d.ts +3 -0
- package/lib/profile/profileLogic.d.ts.map +1 -0
- package/lib/profile/profileLogic.js +246 -0
- package/lib/profile/profileLogic.js.map +1 -0
- package/lib/typeIndex/typeIndexLogic.d.ts +2 -21
- package/lib/typeIndex/typeIndexLogic.d.ts.map +1 -1
- package/lib/typeIndex/typeIndexLogic.js +304 -296
- package/lib/typeIndex/typeIndexLogic.js.map +1 -1
- package/lib/types.d.ts +82 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/util/containerLogic.d.ts +11 -0
- package/lib/util/containerLogic.d.ts.map +1 -0
- package/lib/{profile/ProfileLogic.js → util/containerLogic.js} +51 -44
- package/lib/util/containerLogic.js.map +1 -0
- package/lib/util/ns.d.ts +2 -0
- package/lib/util/ns.d.ts.map +1 -0
- package/lib/util/ns.js +34 -0
- package/lib/util/ns.js.map +1 -0
- package/lib/util/utilityLogic.d.ts +15 -0
- package/lib/util/utilityLogic.d.ts.map +1 -0
- package/lib/util/utilityLogic.js +274 -0
- package/lib/util/utilityLogic.js.map +1 -0
- package/lib/util/utils.d.ts +8 -0
- package/lib/util/utils.d.ts.map +1 -0
- package/lib/util/utils.js +48 -0
- package/lib/util/utils.js.map +1 -0
- package/package.json +5 -1
- package/src/acl/aclLogic.ts +136 -118
- package/src/authn/SolidAuthnLogic.ts +3 -2
- package/src/chat/chatLogic.ts +225 -0
- package/src/inbox/inboxLogic.ts +58 -0
- package/src/index.ts +11 -29
- package/src/issuer/issuerLogic.ts +1 -1
- package/src/logic/CustomError.ts +5 -1
- package/src/logic/solidLogic.ts +75 -0
- package/src/logic/solidLogicSingleton.ts +3 -3
- package/src/profile/profileLogic.ts +126 -0
- package/src/typeIndex/typeIndexLogic.ts +175 -182
- package/src/types.ts +83 -4
- package/src/util/containerLogic.ts +53 -0
- package/src/util/ns.ts +5 -0
- package/src/util/utilityLogic.ts +156 -0
- package/src/util/utils.ts +52 -0
- package/test/aclLogic.test.ts +13 -4
- package/test/chatLogic.test.ts +70 -71
- package/test/container.test.ts +57 -0
- package/test/helpers/dataSetup.ts +134 -0
- package/test/helpers/setup.ts +1 -0
- package/test/inboxLogic.test.ts +40 -38
- package/test/logic.test.ts +10 -9
- package/test/profileLogic.test.ts +246 -0
- package/test/typeIndexLogic.test.ts +487 -30
- package/test/utilityLogic.test.ts +172 -126
- package/test/utils.test.ts +32 -0
- package/lib/chat/ChatLogic.d.ts +0 -26
- package/lib/chat/ChatLogic.d.ts.map +0 -1
- package/lib/chat/ChatLogic.js.map +0 -1
- package/lib/chat/determineChatContainer.d.ts +0 -3
- package/lib/chat/determineChatContainer.d.ts.map +0 -1
- package/lib/chat/determineChatContainer.js +0 -12
- package/lib/chat/determineChatContainer.js.map +0 -1
- package/lib/discovery/discoveryLogic.d.ts +0 -40
- package/lib/discovery/discoveryLogic.d.ts.map +0 -1
- package/lib/discovery/discoveryLogic.js +0 -494
- package/lib/discovery/discoveryLogic.js.map +0 -1
- package/lib/inbox/InboxLogic.d.ts +0 -18
- package/lib/inbox/InboxLogic.d.ts.map +0 -1
- package/lib/inbox/InboxLogic.js.map +0 -1
- package/lib/logic/SolidLogic.d.ts +0 -48
- package/lib/logic/SolidLogic.d.ts.map +0 -1
- package/lib/logic/SolidLogic.js +0 -321
- package/lib/logic/SolidLogic.js.map +0 -1
- package/lib/profile/ProfileLogic.d.ts +0 -13
- package/lib/profile/ProfileLogic.d.ts.map +0 -1
- package/lib/profile/ProfileLogic.js.map +0 -1
- package/lib/util/UtilityLogic.d.ts +0 -33
- package/lib/util/UtilityLogic.d.ts.map +0 -1
- package/lib/util/UtilityLogic.js +0 -240
- package/lib/util/UtilityLogic.js.map +0 -1
- package/lib/util/uri.d.ts +0 -3
- package/lib/util/uri.d.ts.map +0 -1
- package/lib/util/uri.js +0 -9
- package/lib/util/uri.js.map +0 -1
- package/src/chat/ChatLogic.ts +0 -244
- package/src/chat/determineChatContainer.ts +0 -14
- package/src/discovery/discoveryLogic.ts +0 -311
- package/src/inbox/InboxLogic.ts +0 -66
- package/src/logic/SolidLogic.ts +0 -262
- package/src/profile/ProfileLogic.ts +0 -44
- package/src/util/UtilityLogic.ts +0 -161
- package/src/util/uri.ts +0 -5
- package/test/discoveryLogic.test.ts +0 -740
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { sym } from 'rdflib'
|
|
2
|
+
import * as rdf from "rdflib";
|
|
3
|
+
import solidNamespace from "solid-namespace";
|
|
4
|
+
import { SolidNamespace } from '../../src/types';
|
|
5
|
+
const ns: SolidNamespace = solidNamespace(rdf);
|
|
6
|
+
|
|
7
|
+
//------ Club -------------------------------------------------------
|
|
8
|
+
const club = sym('https://club.example.com/profile/card.ttl#it')
|
|
9
|
+
const ClubPreferencesFile = sym('https://club.example.com/settings/prefs.ttl')
|
|
10
|
+
const ClubPublicTypeIndex = sym('https://club.example.com/profile/public-type-index.ttl')
|
|
11
|
+
const ClubPrivateTypeIndex = sym('https://club.example.com/settings/private-type-index.ttl')
|
|
12
|
+
|
|
13
|
+
const ClubProfile = `
|
|
14
|
+
|
|
15
|
+
<#it> a vcard:Organization;
|
|
16
|
+
space:preferencesFile ${ClubPreferencesFile};
|
|
17
|
+
solid:publicTypeIndex ${ClubPublicTypeIndex};
|
|
18
|
+
vcard:fn "Card Club" .
|
|
19
|
+
`
|
|
20
|
+
const ClubPreferences = `
|
|
21
|
+
${club} solid:privateTypeIndex ${ClubPrivateTypeIndex} .
|
|
22
|
+
`
|
|
23
|
+
const ClubPublicTypes = `
|
|
24
|
+
|
|
25
|
+
:chat1 solid:forClass meeting:LongChat; solid:instance <../publicStuff/ourChat.ttl#this> .
|
|
26
|
+
|
|
27
|
+
:todo solid:forClass wf:Tracker; solid:instance <../publicStuff/actionItems.ttl#this>.
|
|
28
|
+
|
|
29
|
+
:issues solid:forClass wf:Tracker; solid:instance <../project4/clubIssues.ttl#this>.
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
const ClubPrivateTypes = `
|
|
33
|
+
:id1592319218311 solid:forClass wf:Tracker; solid:instance <../privateStuff/ToDo.ttl#this>.
|
|
34
|
+
|
|
35
|
+
:id1592319391415 solid:forClass wf:Tracker; solid:instance <../privateStuff/Goals.ttl#this>.
|
|
36
|
+
|
|
37
|
+
:id1595595377864 solid:forClass wf:Tracker; solid:instance <../privateStuff/tasks.ttl#this>.
|
|
38
|
+
|
|
39
|
+
:id1596123375929 solid:forClass meeting:Meeting; solid:instance <../project4/clubMeeting.ttl#this>.
|
|
40
|
+
|
|
41
|
+
`;
|
|
42
|
+
|
|
43
|
+
//------ Alice -------------------------------------------------------
|
|
44
|
+
const alice = sym("https://alice.example.com/profile/card.ttl#me")
|
|
45
|
+
const AliceProfileFile = alice.doc()
|
|
46
|
+
const AlicePreferencesFile = sym('https://alice.example.com/settings/prefs.ttl')
|
|
47
|
+
const AlicePublicTypeIndex = sym('https://alice.example.com/profile/public-type-index.ttl')
|
|
48
|
+
const AlicePrivateTypeIndex = sym('https://alice.example.com/settings/private-type-index.ttl')
|
|
49
|
+
const AlicePhotoFolder = sym(alice.dir().uri + "Photos/")
|
|
50
|
+
const AliceProfile = `
|
|
51
|
+
<#me> a vcard:Individual;
|
|
52
|
+
space:preferencesFile ${AlicePreferencesFile};
|
|
53
|
+
solid:publicTypeIndex ${AlicePublicTypeIndex};
|
|
54
|
+
vcard:fn "Alice" .
|
|
55
|
+
`
|
|
56
|
+
const AlicePreferences = `
|
|
57
|
+
${alice} solid:privateTypeIndex ${AlicePrivateTypeIndex};
|
|
58
|
+
solid:community ${club} .
|
|
59
|
+
`
|
|
60
|
+
const AlicePublicTypes = `
|
|
61
|
+
|
|
62
|
+
:chat1 solid:forClass meeting:LongChat; solid:instance <../publicStuff/myChat.ttl#this> .
|
|
63
|
+
|
|
64
|
+
:todo solid:forClass wf:Tracker; solid:instance <../publicStuff/actionItems.ttl#this>.
|
|
65
|
+
|
|
66
|
+
:issues solid:forClass wf:Tracker; solid:instance <../project4/issues.ttl#this>.
|
|
67
|
+
|
|
68
|
+
:photos solid:forClass schema:Image; solid:instanceContainer ${AlicePhotoFolder} .
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
const AlicePrivateTypes = `
|
|
72
|
+
:id1592319218311 solid:forClass wf:Tracker; solid:instance <../privateStuff/ToDo.ttl#this>.
|
|
73
|
+
|
|
74
|
+
:id1592319391415 solid:forClass wf:Tracker; solid:instance <../privateStuff/Goals.ttl#this>.
|
|
75
|
+
|
|
76
|
+
:id1595595377864 solid:forClass wf:Tracker; solid:instance <../privateStuff/workingOn.ttl#this>.
|
|
77
|
+
|
|
78
|
+
:id1596123375929 solid:forClass meeting:Meeting; solid:instance <../project4/meeting1.ttl#this>.
|
|
79
|
+
|
|
80
|
+
`;
|
|
81
|
+
|
|
82
|
+
const AlicePhotos = `
|
|
83
|
+
<>
|
|
84
|
+
a ldp:BasicContainer, ldp:Container;
|
|
85
|
+
dct:modified "2021-04-26T05:34:16Z"^^xsd:dateTime;
|
|
86
|
+
ldp:contains
|
|
87
|
+
<photo1.png>, <photo2.png>, <photo3.png> ;
|
|
88
|
+
stat:mtime 1619415256.541;
|
|
89
|
+
stat:size 4096 .
|
|
90
|
+
`
|
|
91
|
+
|
|
92
|
+
//------ Bob -------------------------------------------------------
|
|
93
|
+
const bob = sym('https://bob.example.com/profile/card.ttl#me')
|
|
94
|
+
|
|
95
|
+
const BobProfile = `
|
|
96
|
+
<#me> a vcard:Individual;
|
|
97
|
+
vcard:fn "Bob" .
|
|
98
|
+
`
|
|
99
|
+
|
|
100
|
+
//------ Boby -------------------------------------------------------
|
|
101
|
+
const boby = sym('https://boby.example.com/profile/card.ttl#me')
|
|
102
|
+
|
|
103
|
+
const BobyProfile = `
|
|
104
|
+
<#me> a vcard:Individual;
|
|
105
|
+
vcard:fn "Boby" .
|
|
106
|
+
`
|
|
107
|
+
export function loadWebObject() {
|
|
108
|
+
const web = {}
|
|
109
|
+
web[alice.doc().uri] = AliceProfile
|
|
110
|
+
web[AlicePreferencesFile.uri] = AlicePreferences
|
|
111
|
+
web[AlicePrivateTypeIndex.uri] = AlicePrivateTypes
|
|
112
|
+
web[AlicePublicTypeIndex.uri] = AlicePublicTypes
|
|
113
|
+
web[AlicePhotoFolder.uri] = AlicePhotos
|
|
114
|
+
web[bob.doc().uri] = BobProfile
|
|
115
|
+
web[boby.doc().uri] = BobyProfile
|
|
116
|
+
|
|
117
|
+
web[club.doc().uri] = ClubProfile
|
|
118
|
+
web[ClubPreferencesFile.uri] = ClubPreferences
|
|
119
|
+
web[ClubPrivateTypeIndex.uri] = ClubPrivateTypes
|
|
120
|
+
web[ClubPublicTypeIndex.uri] = ClubPublicTypes
|
|
121
|
+
return web
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function clearLocalStore(store) {
|
|
125
|
+
store.statements.slice().forEach(store.remove.bind(store))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
alice, bob, boby, club,
|
|
130
|
+
AlicePhotoFolder, AlicePreferences, AlicePhotos, AlicePreferencesFile, AlicePrivateTypeIndex, AlicePrivateTypes, AliceProfile, AliceProfileFile, AlicePublicTypeIndex, AlicePublicTypes,
|
|
131
|
+
BobProfile,
|
|
132
|
+
ClubPreferences, ClubPreferencesFile, ClubPrivateTypeIndex, ClubPrivateTypes, ClubProfile, ClubPublicTypeIndex, ClubPublicTypes,
|
|
133
|
+
clearLocalStore
|
|
134
|
+
}
|
package/test/helpers/setup.ts
CHANGED
package/test/inboxLogic.test.ts
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment jsdom
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { UpdateManager, Store, Fetcher, sym } from "rdflib";
|
|
6
|
+
import { createAclLogic } from "../src/acl/aclLogic";
|
|
7
|
+
import { createInboxLogic } from '../src/inbox/inboxLogic';
|
|
8
|
+
import { createProfileLogic } from "../src/profile/profileLogic";
|
|
9
|
+
import { createContainerLogic } from "../src/util/containerLogic";
|
|
10
|
+
import { createUtilityLogic } from "../src/util/utilityLogic";
|
|
9
11
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const alice = rdf.sym("https://alice.example/profile/card#me");
|
|
13
|
-
const bob = rdf.sym("https://bob.example/profile/card#me");
|
|
12
|
+
const alice = sym("https://alice.example.com/profile/card#me");
|
|
13
|
+
const bob = sym("https://bob.example.com/profile/card#me");
|
|
14
14
|
|
|
15
15
|
describe("Inbox logic", () => {
|
|
16
|
-
let inbox;
|
|
17
16
|
let store;
|
|
17
|
+
let inboxLogic
|
|
18
18
|
beforeEach(() => {
|
|
19
19
|
fetchMock.resetMocks();
|
|
20
20
|
fetchMock.mockResponse("Not Found", {
|
|
21
21
|
status: 404,
|
|
22
22
|
});
|
|
23
|
-
|
|
24
|
-
store =
|
|
25
|
-
store.fetcher = rdf.fetcher(store, fetcher);
|
|
23
|
+
store = new Store()
|
|
24
|
+
store.fetcher = new Fetcher(store, { fetch: fetch });
|
|
26
25
|
store.updater = new UpdateManager(store);
|
|
27
26
|
const authn = {
|
|
28
27
|
currentUser: () => {
|
|
29
28
|
return alice;
|
|
30
29
|
},
|
|
31
30
|
};
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
31
|
+
const containerLogic = createContainerLogic(store)
|
|
32
|
+
const aclLogic = createAclLogic(store)
|
|
33
|
+
const util = createUtilityLogic(store, aclLogic, containerLogic);
|
|
34
|
+
const profile = createProfileLogic(store, authn, util);
|
|
35
|
+
inboxLogic = createInboxLogic(store, profile, util, containerLogic, aclLogic);
|
|
35
36
|
});
|
|
36
37
|
|
|
37
38
|
describe("getNewMessages", () => {
|
|
@@ -40,7 +41,7 @@ describe("Inbox logic", () => {
|
|
|
40
41
|
beforeEach(async () => {
|
|
41
42
|
bobHasAnInbox();
|
|
42
43
|
inboxIsEmpty();
|
|
43
|
-
result = await
|
|
44
|
+
result = await inboxLogic.getNewMessages(bob);
|
|
44
45
|
});
|
|
45
46
|
it("Resolves to an empty array", () => {
|
|
46
47
|
expect(result).toEqual([]);
|
|
@@ -51,7 +52,8 @@ describe("Inbox logic", () => {
|
|
|
51
52
|
beforeEach(async () => {
|
|
52
53
|
bobHasAnInbox();
|
|
53
54
|
inboxHasSomeContainmentTriples();
|
|
54
|
-
|
|
55
|
+
const messages = await inboxLogic.getNewMessages(bob);
|
|
56
|
+
result = messages.map(oneMessage => oneMessage.value)
|
|
55
57
|
});
|
|
56
58
|
it("Resolves to an array with URLs of non-container resources in inbox", () => {
|
|
57
59
|
expect(result.sort()).toEqual([
|
|
@@ -65,14 +67,14 @@ describe("Inbox logic", () => {
|
|
|
65
67
|
aliceHasValidProfile();
|
|
66
68
|
// First for the PUT:
|
|
67
69
|
fetchMock.mockOnceIf(
|
|
68
|
-
"https://alice.example/p2p-inboxes/Peer%20Person/",
|
|
70
|
+
"https://alice.example.com/p2p-inboxes/Peer%20Person/",
|
|
69
71
|
"Created", {
|
|
70
72
|
status: 201
|
|
71
73
|
}
|
|
72
74
|
)
|
|
73
75
|
// Then for the GET to read the ACL link:
|
|
74
76
|
fetchMock.mockOnceIf(
|
|
75
|
-
"https://alice.example/p2p-inboxes/Peer%20Person/",
|
|
77
|
+
"https://alice.example.com/p2p-inboxes/Peer%20Person/",
|
|
76
78
|
" ", {
|
|
77
79
|
status: 200,
|
|
78
80
|
headers: {
|
|
@@ -82,12 +84,12 @@ describe("Inbox logic", () => {
|
|
|
82
84
|
)
|
|
83
85
|
fetchMock.mockIf("https://some/acl", "Created", { status: 201 });
|
|
84
86
|
|
|
85
|
-
await
|
|
87
|
+
await inboxLogic.createInboxFor('https://peer.com/#me', 'Peer Person');
|
|
86
88
|
});
|
|
87
89
|
it("creates the inbox", () => {
|
|
88
90
|
expect(fetchMock.mock.calls).toEqual([
|
|
89
|
-
[ "https://alice.example/profile/card", fetchMock.mock.calls[0][1] ],
|
|
90
|
-
[ "https://alice.example/p2p-inboxes/Peer%20Person/", {
|
|
91
|
+
[ "https://alice.example.com/profile/card", fetchMock.mock.calls[0][1] ],
|
|
92
|
+
[ "https://alice.example.com/p2p-inboxes/Peer%20Person/", {
|
|
91
93
|
body: " ",
|
|
92
94
|
headers: {
|
|
93
95
|
"Content-Type": "text/turtle",
|
|
@@ -96,18 +98,18 @@ describe("Inbox logic", () => {
|
|
|
96
98
|
},
|
|
97
99
|
method: "PUT"
|
|
98
100
|
}],
|
|
99
|
-
[ "https://alice.example/p2p-inboxes/Peer%20Person/", fetchMock.mock.calls[2][1] ],
|
|
101
|
+
[ "https://alice.example.com/p2p-inboxes/Peer%20Person/", fetchMock.mock.calls[2][1] ],
|
|
100
102
|
[ "https://some/acl", {
|
|
101
103
|
body: '@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n' +
|
|
102
104
|
'\n' +
|
|
103
105
|
'<#alice> a acl:Authorization;\n' +
|
|
104
|
-
' acl:agent <https://alice.example/profile/card#me>;\n' +
|
|
105
|
-
' acl:accessTo <https://alice.example/p2p-inboxes/Peer%20Person/>;\n' +
|
|
106
|
-
' acl:default <https://alice.example/p2p-inboxes/Peer%20Person/>;\n' +
|
|
106
|
+
' acl:agent <https://alice.example.com/profile/card#me>;\n' +
|
|
107
|
+
' acl:accessTo <https://alice.example.com/p2p-inboxes/Peer%20Person/>;\n' +
|
|
108
|
+
' acl:default <https://alice.example.com/p2p-inboxes/Peer%20Person/>;\n' +
|
|
107
109
|
' acl:mode acl:Read, acl:Write, acl:Control.\n' +
|
|
108
110
|
'<#bobAccessTo> a acl:Authorization;\n' +
|
|
109
111
|
' acl:agent <https://peer.com/#me>;\n' +
|
|
110
|
-
' acl:accessTo <https://alice.example/p2p-inboxes/Peer%20Person/>;\n' +
|
|
112
|
+
' acl:accessTo <https://alice.example.com/p2p-inboxes/Peer%20Person/>;\n' +
|
|
111
113
|
' acl:mode acl:Append.\n',
|
|
112
114
|
headers: [
|
|
113
115
|
[ 'Content-Type', 'text/turtle' ]
|
|
@@ -135,7 +137,7 @@ describe("Inbox logic", () => {
|
|
|
135
137
|
headers: { "Content-Type": "text/turtle" },
|
|
136
138
|
}
|
|
137
139
|
);
|
|
138
|
-
await
|
|
140
|
+
await inboxLogic.markAsRead("https://container.com/item.ttl", new Date('31 March 2111 UTC'));
|
|
139
141
|
});
|
|
140
142
|
it('moves the item to archive', async () => {
|
|
141
143
|
expect(fetchMock.mock.calls).toEqual([
|
|
@@ -160,11 +162,11 @@ describe("Inbox logic", () => {
|
|
|
160
162
|
|
|
161
163
|
function aliceHasValidProfile() {
|
|
162
164
|
fetchMock.mockOnceIf(
|
|
163
|
-
"https://alice.example/profile/card",
|
|
165
|
+
"https://alice.example.com/profile/card",
|
|
164
166
|
`
|
|
165
|
-
<https://alice.example/profile/card#me>
|
|
166
|
-
<http://www.w3.org/ns/pim/space#storage> <https://alice.example/> ;
|
|
167
|
-
<http://www.w3.org/ns/solid/terms#privateTypeIndex> <https://alice.example/settings/privateTypeIndex.ttl> ;
|
|
167
|
+
<https://alice.example.com/profile/card#me>
|
|
168
|
+
<http://www.w3.org/ns/pim/space#storage> <https://alice.example.com/> ;
|
|
169
|
+
<http://www.w3.org/ns/solid/terms#privateTypeIndex> <https://alice.example.com/settings/privateTypeIndex.ttl> ;
|
|
168
170
|
.`,
|
|
169
171
|
{
|
|
170
172
|
headers: {
|
|
@@ -176,8 +178,8 @@ describe("Inbox logic", () => {
|
|
|
176
178
|
|
|
177
179
|
function bobHasAnInbox() {
|
|
178
180
|
fetchMock.mockOnceIf(
|
|
179
|
-
"https://bob.example/profile/card",
|
|
180
|
-
"<https://bob.example/profile/card#me><http://www.w3.org/ns/ldp#inbox><https://container.com/>.",
|
|
181
|
+
"https://bob.example.com/profile/card",
|
|
182
|
+
"<https://bob.example.com/profile/card#me><http://www.w3.org/ns/ldp#inbox><https://container.com/>.",
|
|
181
183
|
{
|
|
182
184
|
headers: { "Content-Type": "text/turtle" },
|
|
183
185
|
}
|
package/test/logic.test.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import { solidLogicSingleton } from "../src/
|
|
1
|
+
import { solidLogicSingleton } from "../src/logic/solidLogicSingleton"
|
|
2
2
|
import { silenceDebugMessages } from "./helpers/setup"
|
|
3
3
|
|
|
4
4
|
silenceDebugMessages()
|
|
5
5
|
|
|
6
|
-
describe('
|
|
6
|
+
describe('store', () => {
|
|
7
7
|
it('exists', () => {
|
|
8
|
-
expect(solidLogicSingleton).toBeInstanceOf(Object)
|
|
8
|
+
expect(solidLogicSingleton.store).toBeInstanceOf(Object)
|
|
9
9
|
})
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
describe('
|
|
12
|
+
describe('store.fetcher', () => {
|
|
13
13
|
it('exists', () => {
|
|
14
|
-
expect(solidLogicSingleton.store).toBeInstanceOf(Object)
|
|
14
|
+
expect(solidLogicSingleton.store.fetcher).toBeInstanceOf(Object)
|
|
15
15
|
})
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
describe('
|
|
18
|
+
describe('store.updater', () => {
|
|
19
19
|
it('exists', () => {
|
|
20
|
-
expect(solidLogicSingleton.store.
|
|
20
|
+
expect(solidLogicSingleton.store.updater).toBeInstanceOf(Object)
|
|
21
21
|
})
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
describe('
|
|
24
|
+
describe('authn', () => {
|
|
25
25
|
it('exists', () => {
|
|
26
|
-
expect(solidLogicSingleton.
|
|
26
|
+
expect(solidLogicSingleton.authn).toBeInstanceOf(Object)
|
|
27
27
|
})
|
|
28
28
|
})
|
|
29
|
+
|
|
@@ -0,0 +1,246 @@
|
|
|
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 = []
|
|
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
|
+
const result = await profileLogic.silencedLoadPreferences(bob)
|
|
151
|
+
|
|
152
|
+
const patchRequest = requests[0]
|
|
153
|
+
expect(patchRequest.method).toEqual('PATCH')
|
|
154
|
+
expect(patchRequest.url).toEqual(bob.doc().uri)
|
|
155
|
+
const text = await patchRequest.text()
|
|
156
|
+
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> .')
|
|
157
|
+
|
|
158
|
+
const putRequest = requests[1]
|
|
159
|
+
expect(putRequest.method).toEqual('PUT')
|
|
160
|
+
expect(putRequest.url).toEqual('https://bob.example.com/Settings/Preferences.ttl')
|
|
161
|
+
expect(web[putRequest.url]).toEqual('')
|
|
162
|
+
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
describe('loadPreferences', () => {
|
|
168
|
+
window.$SolidTestEnvironment = { username: boby.uri }
|
|
169
|
+
let store
|
|
170
|
+
requests = []
|
|
171
|
+
const statustoBeReturned = 200
|
|
172
|
+
let web = {}
|
|
173
|
+
const authn = {
|
|
174
|
+
currentUser: () => {
|
|
175
|
+
return boby;
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
beforeEach(() => {
|
|
179
|
+
fetchMock.resetMocks();
|
|
180
|
+
web = loadWebObject()
|
|
181
|
+
requests = []
|
|
182
|
+
fetchMock.mockIf(/^https?.*$/, async req => {
|
|
183
|
+
|
|
184
|
+
if (req.method !== 'GET') {
|
|
185
|
+
requests.push(req)
|
|
186
|
+
if (req.method === 'PUT') {
|
|
187
|
+
const contents = await req.text()
|
|
188
|
+
web[req.url] = contents // Update our dummy web
|
|
189
|
+
console.log(`Tetst: Updated ${req.url} on PUT to <<<${web[req.url]}>>>`)
|
|
190
|
+
}
|
|
191
|
+
return { status: statustoBeReturned }
|
|
192
|
+
}
|
|
193
|
+
const contents = web[req.url]
|
|
194
|
+
if (contents !== undefined) { //
|
|
195
|
+
return {
|
|
196
|
+
body: prefixes + contents, // Add namespaces to anything
|
|
197
|
+
status: 200,
|
|
198
|
+
headers: {
|
|
199
|
+
"Content-Type": "text/turtle",
|
|
200
|
+
"WAC-Allow": 'user="write", public="read"',
|
|
201
|
+
"Accept-Patch": "application/sparql-update"
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} // if contents
|
|
205
|
+
return {
|
|
206
|
+
status: 404,
|
|
207
|
+
body: 'Not Found'
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
store = new Store()
|
|
212
|
+
store.fetcher = new Fetcher(store, { fetch: fetch });
|
|
213
|
+
store.updater = new UpdateManager(store);
|
|
214
|
+
const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store))
|
|
215
|
+
profileLogic = createProfileLogic(store, authn, util)
|
|
216
|
+
})
|
|
217
|
+
it('exists', () => {
|
|
218
|
+
expect(profileLogic.loadPreferences).toBeInstanceOf(Function)
|
|
219
|
+
})
|
|
220
|
+
it('loads data', async () => {
|
|
221
|
+
const result = await profileLogic.loadPreferences(alice)
|
|
222
|
+
expect(result).toBeInstanceOf(Object)
|
|
223
|
+
expect(result.uri).toEqual(AlicePreferencesFile.uri)
|
|
224
|
+
expect(store.holds(user, ns.rdf('type'), ns.vcard('Individual'), profile)).toEqual(true)
|
|
225
|
+
expect(store.statementsMatching(null, null, null, profile).length).toEqual(4)
|
|
226
|
+
|
|
227
|
+
expect(store.statementsMatching(null, null, null, AlicePreferencesFile).length).toEqual(2)
|
|
228
|
+
expect(store.holds(user, ns.solid('privateTypeIndex'), AlicePrivateTypeIndex, AlicePreferencesFile)).toEqual(true)
|
|
229
|
+
})
|
|
230
|
+
it('creates new file', async () => {
|
|
231
|
+
const result = await profileLogic.loadPreferences(boby)
|
|
232
|
+
|
|
233
|
+
const patchRequest = requests[0]
|
|
234
|
+
expect(patchRequest.method).toEqual('PATCH')
|
|
235
|
+
expect(patchRequest.url).toEqual(boby.doc().uri)
|
|
236
|
+
const text = await patchRequest.text()
|
|
237
|
+
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> .')
|
|
238
|
+
|
|
239
|
+
const putRequest = requests[1]
|
|
240
|
+
expect(putRequest.method).toEqual('PUT')
|
|
241
|
+
expect(putRequest.url).toEqual('https://boby.example.com/Settings/Preferences.ttl')
|
|
242
|
+
expect(web[putRequest.url]).toEqual('')
|
|
243
|
+
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
})
|