@@ -8,7 +8,7 @@ import { solidLogicSingleton } from "../src/logic/solidLogicSingleton"
88import fetchMock from "jest-fetch-mock" ;
99
1010import { loadOrCreateIfNotExists , makePreferencesFileURI , followOrCreateLink , loadCommunityTypeIndexes ,
11- getAppInstances , getScopedAppInstances , loadTypeIndexesFor , loadPreferences ,
11+ getAppInstances , getScopedAppInstances , loadTypeIndexesFor , loadPreferences , registerInstanceInTypeIndex ,
1212 uniqueNodes , loadProfile } from '../src/discovery/discoveryLogic.ts'
1313
1414const { getContainerMembers, authn, store } = solidLogicSingleton
@@ -244,11 +244,11 @@ describe('uniqueNodes', () => {
244244 expect ( requests ) . toEqual ( [ ] )
245245
246246 } )
247- it . skip ( 'creates empty file if did not exist' , async ( ) => {
248- const result = await loadOrCreateIfNotExists ( store , Bob . doc ( ) )
249- // console.log('@@@@@ test requests', requests )
247+ it ( 'creates empty file if did not exist' , async ( ) => {
248+ const newFile = sym ( Bob . doc ( ) . uri + / r e f h o i j h o e g g / )
249+ const result = await loadOrCreateIfNotExists ( store , newFile )
250250 expect ( requests [ 0 ] . method ) . toEqual ( 'PUT' )
251- expect ( requests [ 0 ] . url ) . toEqual ( Bob . doc ( ) . uri )
251+ expect ( requests [ 0 ] . url ) . toEqual ( newFile . uri )
252252 } )
253253 } )
254254
@@ -697,16 +697,33 @@ const TRACKERS =
697697 it ( 'exists' , ( ) => {
698698 expect ( getAppInstances ) . toBeInstanceOf ( Function )
699699 } )
700- it ( 'finds trackers' , async ( ) => { // needs auth mock
700+ it ( 'finds trackers' , async ( ) => {
701701 const result = await getAppInstances ( store , Tracker )
702702 expect ( result ) . toEqual ( TRACKERS )
703703 expect ( result ) . toEqual ( uniqueNodes ( result ) ) // shoud have no dups
704704 } )
705- it ( 'finds images in containers' , async ( ) => { // needs auth mock
705+ it ( 'finds images in containers' , async ( ) => {
706706 const result = await getAppInstances ( store , Image )
707707 expect ( result . length ) . toEqual ( 3 )
708708 expect ( result ) . toEqual ( uniqueNodes ( result ) ) // shoud have no dups
709709 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" )
710710 } )
711711 } )
712+
713+ describe ( 'registerInstanceInTypeIndex' , ( ) => {
714+ it ( 'exists' , ( ) => {
715+ expect ( registerInstanceInTypeIndex ) . toBeInstanceOf ( Function )
716+ } )
717+ it ( 'adds a registration' , async ( ) => {
718+ const instance = sym ( Alice . doc ( ) . uri + 'trackers/myToDo.ttl#this' )
719+ const index = AlicePublicTypeIndex
720+ const result = await registerInstanceInTypeIndex ( store , instance , index , klass )
721+ expect ( result . doc ( ) ) . toEqual ( index )
722+ expect ( store . any ( result , ns . solid ( 'forClass' ) , null , index ) ) . toEqual ( klass )
723+ expect ( store . any ( result , ns . solid ( 'instance' ) , null , index ) ) . toEqual ( instance )
724+ expect ( store . holds ( result , ns . rdf ( 'type' ) , ns . solid ( 'TypeRegistration' ) , index ) ) . toEqual ( true )
725+ expect ( requests [ 0 ] . url ) . toEqual ( index . uri )
726+ } )
727+ } )
728+
712729} )
0 commit comments