@@ -2,12 +2,7 @@ import assert from 'node:assert';
22
33import { Given , Then , When } from '@cucumber/cucumber' ;
44
5- import {
6- findInOutbox ,
7- waitForInboxActivity ,
8- waitForOutboxActivity ,
9- waitForOutboxObject ,
10- } from '../support/activitypub.js' ;
5+ import { waitForInboxActivity } from '../support/activitypub.js' ;
116import {
127 createActivity ,
138 createActor ,
@@ -266,72 +261,6 @@ Then(
266261 } ,
267262) ;
268263
269- Then ( '{string} is not in our Outbox' , async function ( activityName ) {
270- const activity = this . activities [ activityName ] ;
271- const found = await findInOutbox ( activity ) ;
272- assert (
273- ! found ,
274- `Expected not to find activity "${ activityName } " in outbox, but it was found` ,
275- ) ;
276- } ) ;
277-
278- Then ( '{string} is in our Outbox' , async function ( name ) {
279- const activity = this . activities [ name ] ;
280- if ( activity ) return waitForOutboxActivity ( activity ) ;
281- const object = this . objects [ name ] ;
282- if ( object ) return waitForOutboxObject ( object ) ;
283- } ) ;
284-
285- async function waitForOutboxActivityType (
286- activityType ,
287- objectType ,
288- options = {
289- retryCount : 0 ,
290- delay : 0 ,
291- } ,
292- ) {
293- const MAX_RETRIES = 5 ;
294-
295- const initialResponse = await fetchActivityPub (
296- 'http://fake-ghost-activitypub.test/.ghost/activitypub/outbox/index' ,
297- {
298- headers : {
299- Accept : 'application/ld+json' ,
300- } ,
301- } ,
302- ) ;
303- const initialResponseJson = await initialResponse . json ( ) ;
304- const firstPageReponse = await fetchActivityPub ( initialResponseJson . first , {
305- headers : {
306- Accept : 'application/ld+json' ,
307- } ,
308- } ) ;
309- const outbox = await firstPageReponse . json ( ) ;
310-
311- const found = ( outbox . orderedItems || [ ] ) . find ( ( item ) => {
312- return item . type === activityType && item . object ?. type === objectType ;
313- } ) ;
314-
315- if ( found ) {
316- return found ;
317- }
318-
319- if ( options . retryCount === MAX_RETRIES ) {
320- throw new Error (
321- `Max retries reached (${ MAX_RETRIES } ) when waiting for ${ activityType } (${ objectType } ) in the outbox` ,
322- ) ;
323- }
324-
325- if ( options . delay > 0 ) {
326- await new Promise ( ( resolve ) => setTimeout ( resolve , options . delay ) ) ;
327- }
328-
329- return waitForOutboxActivityType ( activityType , objectType , {
330- retryCount : options . retryCount + 1 ,
331- delay : options . delay + 500 ,
332- } ) ;
333- }
334-
335264Then (
336265 'Activity {string} is sent to {string}' ,
337266 async function ( activityName , actorName ) {
@@ -388,6 +317,52 @@ Then(
388317 } ,
389318) ;
390319
320+ Then (
321+ 'A {string} Activity is sent to all followers' ,
322+ async function ( activityString ) {
323+ const followersResponse = await fetchActivityPub (
324+ 'http://fake-ghost-activitypub.test/.ghost/activitypub/followers/index' ,
325+ ) ;
326+ const followersResponseJson = await followersResponse . json ( ) ;
327+
328+ const [ match , activity , object ] = activityString . match (
329+ / ( \w + ) \( ( \w + ) \) / ,
330+ ) || [ null ] ;
331+ if ( ! match ) {
332+ throw new Error ( `Could not match ${ activityString } to an activity` ) ;
333+ }
334+
335+ const followers = followersResponseJson . orderedItems ;
336+
337+ for ( const followerUrl of followers ) {
338+ const follower = await ( await fetchActivityPub ( followerUrl ) ) . json ( ) ;
339+ const inbox = new URL ( follower . inbox ) ;
340+
341+ const found = await waitForRequest (
342+ 'POST' ,
343+ inbox . pathname ,
344+ ( call ) => {
345+ const json = JSON . parse ( call . request . body ) ;
346+
347+ return (
348+ json . type === activity && json . object . type === object
349+ ) ;
350+ } ,
351+ ) ;
352+
353+ if ( ! this . found ) {
354+ this . found = { } ;
355+ }
356+ this . found [ activityString ] = found ;
357+
358+ assert (
359+ found ,
360+ `Activity "${ activityString } " was not sent to "${ follower . name } "` ,
361+ ) ;
362+ }
363+ } ,
364+ ) ;
365+
391366Then (
392367 'Activity with object {string} is sent to all followers' ,
393368 async function ( objectName ) {
@@ -422,21 +397,6 @@ Then(
422397 } ,
423398) ;
424399
425- Then ( 'a {string} activity is in the Outbox' , async function ( string ) {
426- const [ match , activity , object ] = string . match ( / ( \w + ) \( ( \w + ) \) / ) || [ null ] ;
427- if ( ! match ) {
428- throw new Error ( `Could not match ${ string } to an activity` ) ;
429- }
430-
431- const found = await waitForOutboxActivityType ( activity , object ) ;
432-
433- if ( ! this . found ) {
434- this . found = { } ;
435- }
436- this . found [ string ] = found ;
437- assert . ok ( found ) ;
438- } ) ;
439-
440400Then ( 'the found {string} as {string}' , function ( foundName , name ) {
441401 const found = this . found [ foundName ] ;
442402
0 commit comments