@@ -357,3 +357,86 @@ test("MockFederation without queue sends all activities immediately", async () =
357357 assertEquals ( mockFederation . sentActivities [ 0 ] . queue , undefined ) ;
358358 assertEquals ( mockFederation . sentActivities [ 0 ] . sentOrder , 1 ) ;
359359} ) ;
360+
361+ test ( "MockContext.getActor() calls registered actor dispatcher" , async ( ) => {
362+ const mockFederation = createFederation < void > ( ) ;
363+
364+ // Register actor dispatcher
365+ mockFederation . setActorDispatcher (
366+ "/users/{identifier}" ,
367+ ( ctx , identifier ) => {
368+ return new Person ( {
369+ id : ctx . getActorUri ( identifier ) ,
370+ preferredUsername : identifier ,
371+ name : `Test User ${ identifier } ` ,
372+ } ) ;
373+ } ,
374+ ) ;
375+
376+ const context = mockFederation . createContext (
377+ new URL ( "https://example.com" ) ,
378+ undefined ,
379+ ) ;
380+
381+ const actor = await context . getActor ( "alice" ) ;
382+
383+ assertEquals ( actor instanceof Person , true ) ;
384+ assertEquals ( actor ?. preferredUsername , "alice" ) ;
385+ assertEquals ( actor ?. name , "Test User alice" ) ;
386+ assertEquals ( actor ?. id ?. href , "https://example.com/users/alice" ) ;
387+ } ) ;
388+
389+ test ( "MockContext.getObject() calls registered object dispatcher" , async ( ) => {
390+ const mockFederation = createFederation < void > ( ) ;
391+
392+ // Register object dispatcher
393+ mockFederation . setObjectDispatcher (
394+ Note ,
395+ "/users/{identifier}/posts/{postId}" ,
396+ ( ctx , values ) => {
397+ return new Note ( {
398+ id : ctx . getObjectUri ( Note , values ) ,
399+ content : `Post ${ values . postId } by ${ values . identifier } ` ,
400+ } ) ;
401+ } ,
402+ ) ;
403+
404+ const context = mockFederation . createContext (
405+ new URL ( "https://example.com" ) ,
406+ undefined ,
407+ ) ;
408+
409+ const note = await context . getObject ( Note , {
410+ identifier : "alice" ,
411+ postId : "123" ,
412+ } ) ;
413+
414+ assertEquals ( note instanceof Note , true ) ;
415+ assertEquals ( note ?. content , "Post 123 by alice" ) ;
416+ assertEquals ( note ?. id ?. href , "https://example.com/users/alice/posts/123" ) ;
417+ } ) ;
418+
419+ test ( "MockContext.getActor() returns null when no dispatcher registered" , async ( ) => {
420+ const mockFederation = createFederation < void > ( ) ;
421+ const context = mockFederation . createContext (
422+ new URL ( "https://example.com" ) ,
423+ undefined ,
424+ ) ;
425+
426+ const actor = await context . getActor ( "alice" ) ;
427+ assertEquals ( actor , null ) ;
428+ } ) ;
429+
430+ test ( "MockContext.getObject() returns null when no dispatcher registered" , async ( ) => {
431+ const mockFederation = createFederation < void > ( ) ;
432+ const context = mockFederation . createContext (
433+ new URL ( "https://example.com" ) ,
434+ undefined ,
435+ ) ;
436+
437+ const note = await context . getObject ( Note , {
438+ identifier : "alice" ,
439+ postId : "123" ,
440+ } ) ;
441+ assertEquals ( note , null ) ;
442+ } ) ;
0 commit comments