@@ -3,7 +3,7 @@ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
33import { tmpdir } from "node:os" ;
44import path from "node:path" ;
55import { afterEach , describe , expect , it , vi } from "vitest" ;
6- import { resolveNextcloudTalkRoomKind , testing } from "./room-info.js" ;
6+ import { ROOM_CACHE_MAX_ENTRIES , resolveNextcloudTalkRoomKind , testing } from "./room-info.js" ;
77
88const fetchWithSsrFGuard = vi . hoisted ( ( ) => vi . fn ( ) ) ;
99const tempDirs : string [ ] = [ ] ;
@@ -79,6 +79,46 @@ describe("nextcloud talk room info", () => {
7979 expect ( release ) . toHaveBeenCalledTimes ( 1 ) ;
8080 } ) ;
8181
82+ it ( "caps cached room info entries" , async ( ) => {
83+ fetchWithSsrFGuard . mockImplementation ( async ( ) => ( {
84+ response : jsonResponse ( {
85+ ocs : {
86+ data : {
87+ type : 1 ,
88+ } ,
89+ } ,
90+ } ) ,
91+ release : vi . fn ( async ( ) => { } ) ,
92+ } ) ) ;
93+ const account = {
94+ accountId : "acct-cache-cap" ,
95+ baseUrl : "https://nc.example.com" ,
96+ config : {
97+ apiUser : "bot" ,
98+ apiPassword : "secret" ,
99+ } ,
100+ } as never ;
101+
102+ for ( let index = 0 ; index <= ROOM_CACHE_MAX_ENTRIES ; index += 1 ) {
103+ await resolveNextcloudTalkRoomKind ( {
104+ account,
105+ roomToken : `room-${ index } ` ,
106+ } ) ;
107+ }
108+ await resolveNextcloudTalkRoomKind ( { account, roomToken : "room-0" } ) ;
109+ const callsAfterOldestRetry = fetchWithSsrFGuard . mock . calls . length ;
110+ await resolveNextcloudTalkRoomKind ( {
111+ account,
112+ roomToken : `room-${ ROOM_CACHE_MAX_ENTRIES } ` ,
113+ } ) ;
114+
115+ expect ( callsAfterOldestRetry ) . toBe ( ROOM_CACHE_MAX_ENTRIES + 2 ) ;
116+ expect ( fetchWithSsrFGuard . mock . calls ) . toHaveLength ( callsAfterOldestRetry ) ;
117+ expect ( fetchWithSsrFGuard . mock . calls . at ( - 1 ) ?. [ 0 ] ) . toMatchObject ( {
118+ url : "https://nc.example.com/ocs/v2.php/apps/spreed/api/v4/room/room-0" ,
119+ } ) ;
120+ } ) ;
121+
82122 it ( "normalizes signed decimal room type strings through the shared parser" , async ( ) => {
83123 fetchWithSsrFGuard . mockResolvedValue ( {
84124 response : jsonResponse ( {
0 commit comments