|
2 | 2 | * @jest-environment jsdom |
3 | 3 | * |
4 | 4 | */ |
5 | | -import { Fetcher, Store, sym, UpdateManager } from 'rdflib' |
| 5 | +import { Fetcher, parse, Store, sym, UpdateManager } from 'rdflib' |
6 | 6 | import { createAclLogic } from '../src/acl/aclLogic' |
7 | 7 | import { createProfileLogic } from '../src/profile/profileLogic' |
8 | 8 | import { createTypeIndexLogic} from '../src/typeIndex/typeIndexLogic' |
@@ -51,7 +51,7 @@ describe('TypeIndex logic NEW', () => { |
51 | 51 | requests = [] |
52 | 52 | statustoBeReturned = 200 |
53 | 53 |
|
54 | | - fetchMock.mockIf(/^https?.*$/, async req => { |
| 54 | + fetchMock.mockIf(/^(https?|mailto):.*$/, async req => { |
55 | 55 |
|
56 | 56 | if (req.method !== 'GET') { |
57 | 57 | requests.push(req) |
@@ -131,6 +131,50 @@ describe('TypeIndex logic NEW', () => { |
131 | 131 | expect(store.statementsMatching(null, null, null, AlicePrivateTypeIndex).length).toEqual(8) |
132 | 132 | expect(store.statementsMatching(null, null, null, AlicePublicTypeIndex).length).toEqual(8) |
133 | 133 | }) |
| 134 | + it('uses existing publicTypeIndex when suggestion fails', async () => { |
| 135 | + const carol = sym('urn:uuid:carol#me') |
| 136 | + const CarolProfileDoc = carol.doc() |
| 137 | + const CarolPreferencesFile = sym('https://carol.example.com/settings/prefs.ttl') |
| 138 | + const CarolPublicTypeIndex = sym('https://carol.example.com/profile/public-type-index.ttl') |
| 139 | + const CarolPrivateTypeIndex = sym('https://carol.example.com/settings/private-type-index.ttl') |
| 140 | + |
| 141 | + const CarolProfile = ` |
| 142 | +<#me> a vcard:Individual; |
| 143 | + space:preferencesFile ${CarolPreferencesFile}; |
| 144 | + solid:publicTypeIndex ${CarolPublicTypeIndex}. |
| 145 | +` |
| 146 | + const CarolPreferences = ` |
| 147 | + ${carol} solid:privateTypeIndex ${CarolPrivateTypeIndex} . |
| 148 | +` |
| 149 | + |
| 150 | + web[CarolPreferencesFile.uri] = CarolPreferences |
| 151 | + web[CarolPublicTypeIndex.uri] = ` |
| 152 | +:t solid:forClass wf:Tracker; solid:instance <../publicStuff/actionItems.ttl#this> . |
| 153 | +` |
| 154 | + web[CarolPrivateTypeIndex.uri] = ` |
| 155 | +:t solid:forClass wf:Tracker; solid:instance <../privateStuff/ToDo.ttl#this> . |
| 156 | +` |
| 157 | + |
| 158 | + const util = createUtilityLogic(store, createAclLogic(store), createContainerLogic(store)) |
| 159 | + const profileLogic = { |
| 160 | + loadProfile: async (user) => { |
| 161 | + parse(prefixes + CarolProfile, store, CarolProfileDoc.uri, 'text/turtle') |
| 162 | + return user.doc() |
| 163 | + }, |
| 164 | + silencedLoadPreferences: async () => { |
| 165 | + parse(prefixes + CarolPreferences, store, CarolPreferencesFile.uri, 'text/turtle') |
| 166 | + return CarolPreferencesFile |
| 167 | + } |
| 168 | + } |
| 169 | + const typeIndexLogicWithStub = createTypeIndexLogic(store, authn, profileLogic as any, util) |
| 170 | + |
| 171 | + const result = await typeIndexLogicWithStub.loadTypeIndexesFor(carol) |
| 172 | + expect(result).toEqual([ |
| 173 | + { label: 'public', index: CarolPublicTypeIndex as any, agent: carol as any }, |
| 174 | + { label: 'private', index: CarolPrivateTypeIndex as any, agent: carol as any } |
| 175 | + ]) |
| 176 | + expect(requests.length).toEqual(0) |
| 177 | + }) |
134 | 178 | }) |
135 | 179 |
|
136 | 180 | const ClubScopes = |
|
0 commit comments