@@ -2233,6 +2233,7 @@ test("ContextImpl.sendActivity()", async (t) => {
22332233 } ,
22342234 } ,
22352235 keys : queue . messages [ 0 ] . type === "fanout" ? queue . messages [ 0 ] . keys : [ ] ,
2236+ orderingKey : undefined ,
22362237 traceContext : { } ,
22372238 } ,
22382239 ] ) ;
@@ -2370,6 +2371,85 @@ test("ContextImpl.sendActivity()", async (t) => {
23702371 assertNotEquals ( collectionSyncHeader , null ) ;
23712372 } ) ;
23722373
2374+ queue . clear ( ) ;
2375+
2376+ await t . step ( 'orderingKey with fanout: "force"' , async ( ) => {
2377+ const activity = new vocab . Create ( {
2378+ id : new URL ( "https://example.com/activity/ordering-1" ) ,
2379+ actor : new URL ( "https://example.com/person" ) ,
2380+ } ) ;
2381+ await ctx2 . sendActivity (
2382+ { username : "john" } ,
2383+ {
2384+ id : new URL ( "https://example.com/recipient" ) ,
2385+ inboxId : new URL ( "https://example.com/inbox" ) ,
2386+ } ,
2387+ activity ,
2388+ { fanout : "force" , orderingKey : "https://example.com/note/1" } ,
2389+ ) ;
2390+ assertEquals ( queue . messages . length , 1 ) ;
2391+ const fanoutMessage = queue . messages [ 0 ] ;
2392+ assertEquals ( fanoutMessage . type , "fanout" ) ;
2393+ if ( fanoutMessage . type === "fanout" ) {
2394+ assertEquals (
2395+ fanoutMessage . orderingKey ,
2396+ "https://example.com/note/1" ,
2397+ ) ;
2398+ }
2399+ } ) ;
2400+
2401+ queue . clear ( ) ;
2402+
2403+ await t . step ( 'orderingKey with fanout: "skip"' , async ( ) => {
2404+ const activity = new vocab . Create ( {
2405+ id : new URL ( "https://example.com/activity/ordering-2" ) ,
2406+ actor : new URL ( "https://example.com/person" ) ,
2407+ } ) ;
2408+ await ctx2 . sendActivity (
2409+ { username : "john" } ,
2410+ {
2411+ id : new URL ( "https://example.com/recipient" ) ,
2412+ inboxId : new URL ( "https://example.com/inbox" ) ,
2413+ } ,
2414+ activity ,
2415+ { fanout : "skip" , orderingKey : "https://example.com/note/2" } ,
2416+ ) ;
2417+ assertEquals ( queue . messages . length , 1 ) ;
2418+ const outboxMessage = queue . messages [ 0 ] ;
2419+ assertEquals ( outboxMessage . type , "outbox" ) ;
2420+ // outbox message should have orderingKey transformed to include inbox origin
2421+ if ( outboxMessage . type === "outbox" ) {
2422+ assertEquals (
2423+ outboxMessage . orderingKey ,
2424+ "https://example.com/note/2\nhttps://example.com" ,
2425+ ) ;
2426+ }
2427+ } ) ;
2428+
2429+ queue . clear ( ) ;
2430+
2431+ await t . step ( "orderingKey not specified" , async ( ) => {
2432+ const activity = new vocab . Create ( {
2433+ id : new URL ( "https://example.com/activity/ordering-3" ) ,
2434+ actor : new URL ( "https://example.com/person" ) ,
2435+ } ) ;
2436+ await ctx2 . sendActivity (
2437+ { username : "john" } ,
2438+ {
2439+ id : new URL ( "https://example.com/recipient" ) ,
2440+ inboxId : new URL ( "https://example.com/inbox" ) ,
2441+ } ,
2442+ activity ,
2443+ { fanout : "force" } ,
2444+ ) ;
2445+ assertEquals ( queue . messages . length , 1 ) ;
2446+ const fanoutMessage2 = queue . messages [ 0 ] ;
2447+ assertEquals ( fanoutMessage2 . type , "fanout" ) ;
2448+ if ( fanoutMessage2 . type === "fanout" ) {
2449+ assertEquals ( fanoutMessage2 . orderingKey , undefined ) ;
2450+ }
2451+ } ) ;
2452+
23732453 fetchMock . hardReset ( ) ;
23742454} ) ;
23752455
0 commit comments