@@ -9,10 +9,7 @@ import {
99} from '@codebuff/common/constants/freebuff-models'
1010import { openCodeZenModels } from '@codebuff/common/constants/model-config'
1111import { postChatCompletions } from '../_post'
12- import {
13- checkFreeModeRateLimit ,
14- resetFreeModeRateLimits ,
15- } from '../free-mode-rate-limiter'
12+ import { resetFreeModeRateLimits } from '../free-mode-rate-limiter'
1613
1714import type { TrackEventFn } from '@codebuff/common/types/contracts/analytics'
1815import type { InsertMessageBigqueryFn } from '@codebuff/common/types/contracts/bigquery'
@@ -1148,6 +1145,11 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11481145 } )
11491146
11501147 it ( 'requires an active session check for the Gemini thinker subagent' , async ( ) => {
1148+ const checkFreeModeRateLimitForTest = mock ( ( userId : string ) => {
1149+ expect ( userId ) . toBe ( 'user-new-free-gemini' )
1150+ return { limited : false as const }
1151+ } )
1152+
11511153 const response = await postChatCompletions ( {
11521154 req : new NextRequest ( 'http://localhost:3000/api/v1/chat/completions' , {
11531155 method : 'POST' ,
@@ -1177,11 +1179,11 @@ describe('/api/v1/chat/completions POST endpoint', () => {
11771179 expect ( params . claimedInstanceId ) . toBe ( 'inst-123' )
11781180 return { ok : true , reason : 'active' , remainingMs : 60_000 }
11791181 } ,
1182+ checkFreeModeRateLimit : checkFreeModeRateLimitForTest ,
11801183 } )
11811184
11821185 expect ( response . status ) . toBe ( 200 )
1183- expect ( checkFreeModeRateLimit ( 'user-new-free-gemini' ) . limited ) . toBe ( false )
1184- expect ( checkFreeModeRateLimit ( 'user-new-free-gemini' ) . limited ) . toBe ( true )
1186+ expect ( checkFreeModeRateLimitForTest ) . toHaveBeenCalledTimes ( 1 )
11851187 } )
11861188
11871189 it (
0 commit comments