@@ -5,12 +5,17 @@ import { Effect } from "effect"
55import fc from "fast-check"
66
77import {
8+ activityForgeFedJsonLdContext ,
89 actorJsonLdContext ,
910 federationJsonLdResponseContentType
1011} from "../src/api/contracts.js"
1112import {
1213 federationActorDocumentResponse ,
1314 federationExchangeStatusResponse ,
15+ federationFollowersDocumentResponse ,
16+ federationFollowingDocumentResponse ,
17+ federationLikedDocumentResponse ,
18+ federationOutboxDocumentResponse ,
1419 resolveConfiguredFederationPublicOrigin
1520} from "../src/http.js"
1621import { clearFederationState } from "../src/services/federation.js"
@@ -52,7 +57,11 @@ const federationDocumentHandler = HttpApp.toWebHandler(
5257 Effect . flatten (
5358 HttpRouter . toHttpApp (
5459 HttpRouter . empty . pipe (
55- HttpRouter . get ( "/federation/actor" , federationActorDocumentResponse ( ) )
60+ HttpRouter . get ( "/federation/actor" , federationActorDocumentResponse ( ) ) ,
61+ HttpRouter . get ( "/federation/outbox" , federationOutboxDocumentResponse ( ) ) ,
62+ HttpRouter . get ( "/federation/followers" , federationFollowersDocumentResponse ( ) ) ,
63+ HttpRouter . get ( "/federation/following" , federationFollowingDocumentResponse ( ) ) ,
64+ HttpRouter . get ( "/federation/liked" , federationLikedDocumentResponse ( ) )
5665 )
5766 )
5867 )
@@ -118,6 +127,44 @@ const parseJsonObject = (raw: string): object | null => {
118127const readField = ( value : object | null , key : string ) : unknown =>
119128 value === null ? undefined : Reflect . get ( value , key )
120129
130+ const federationDocumentCases : ReadonlyArray < {
131+ readonly path : string
132+ readonly expectedContext : unknown
133+ readonly expectedId : string
134+ readonly expectedType : string
135+ } > = [
136+ {
137+ path : "/federation/actor" ,
138+ expectedContext : actorJsonLdContext ,
139+ expectedId : "https://public.example.test/federation/actor" ,
140+ expectedType : "Person"
141+ } ,
142+ {
143+ path : "/federation/outbox" ,
144+ expectedContext : activityForgeFedJsonLdContext ,
145+ expectedId : "https://public.example.test/federation/outbox" ,
146+ expectedType : "OrderedCollection"
147+ } ,
148+ {
149+ path : "/federation/followers" ,
150+ expectedContext : activityForgeFedJsonLdContext ,
151+ expectedId : "https://public.example.test/federation/followers" ,
152+ expectedType : "OrderedCollection"
153+ } ,
154+ {
155+ path : "/federation/following" ,
156+ expectedContext : activityForgeFedJsonLdContext ,
157+ expectedId : "https://public.example.test/federation/following" ,
158+ expectedType : "OrderedCollection"
159+ } ,
160+ {
161+ path : "/federation/liked" ,
162+ expectedContext : activityForgeFedJsonLdContext ,
163+ expectedId : "https://public.example.test/federation/liked" ,
164+ expectedType : "OrderedCollection"
165+ }
166+ ]
167+
121168describe ( "api http config" , ( ) => {
122169 it . effect ( "ignores empty federation public origin values" , ( ) =>
123170 Effect . sync ( ( ) => {
@@ -180,16 +227,19 @@ describe("api http config", () => {
180227 expect ( Array . isArray ( readField ( payload , "recentEvents" ) ) ) . toBe ( true )
181228 } ) )
182229
183- it . effect ( "serves federation actor documents as JSON-LD" , ( ) =>
184- Effect . gen ( function * ( _ ) {
185- yield * _ ( Effect . sync ( ( ) => clearFederationState ( ) ) )
230+ for ( const documentCase of federationDocumentCases ) {
231+ it . effect ( `serves ${ documentCase . path } as JSON-LD` , ( ) =>
232+ Effect . gen ( function * ( _ ) {
233+ yield * _ ( Effect . sync ( ( ) => clearFederationState ( ) ) )
186234
187- const actor = yield * _ ( readFederationDocumentRoute ( "/federation/actor" ) )
188- const payload = parseJsonObject ( actor . body )
235+ const document = yield * _ ( readFederationDocumentRoute ( documentCase . path ) )
236+ const payload = parseJsonObject ( document . body )
189237
190- expect ( actor . status ) . toBe ( 200 )
191- expect ( actor . contentType ) . toBe ( federationJsonLdResponseContentType )
192- expect ( readField ( payload , "@context" ) ) . toEqual ( actorJsonLdContext )
193- expect ( readField ( payload , "id" ) ) . toBe ( "https://public.example.test/federation/actor" )
194- } ) )
238+ expect ( document . status ) . toBe ( 200 )
239+ expect ( document . contentType ) . toBe ( federationJsonLdResponseContentType )
240+ expect ( readField ( payload , "@context" ) ) . toEqual ( documentCase . expectedContext )
241+ expect ( readField ( payload , "type" ) ) . toBe ( documentCase . expectedType )
242+ expect ( readField ( payload , "id" ) ) . toBe ( documentCase . expectedId )
243+ } ) )
244+ }
195245} )
0 commit comments