@@ -18,32 +18,25 @@ import type { BlockGrantResult } from '@codebuff/billing/subscription'
1818import type { GetUserPreferencesFn } from '../_post'
1919
2020describe ( '/api/v1/chat/completions POST endpoint' , ( ) => {
21- // Old enough to clear the account-age gate in _post.ts
22- const AGED_ACCOUNT_CREATED_AT = new Date ( '2024-01-01T00:00:00Z' )
23-
2421 const mockUserData : Record <
2522 string ,
26- { id : string ; banned : boolean ; created_at : Date }
23+ { id : string ; banned : boolean }
2724 > = {
2825 'test-api-key-123' : {
2926 id : 'user-123' ,
3027 banned : false ,
31- created_at : AGED_ACCOUNT_CREATED_AT ,
3228 } ,
3329 'test-api-key-no-credits' : {
3430 id : 'user-no-credits' ,
3531 banned : false ,
36- created_at : AGED_ACCOUNT_CREATED_AT ,
3732 } ,
3833 'test-api-key-blocked' : {
3934 id : 'banned-user-id' ,
4035 banned : true ,
41- created_at : AGED_ACCOUNT_CREATED_AT ,
4236 } ,
4337 'test-api-key-new-free' : {
4438 id : 'user-new-free' ,
4539 banned : false ,
46- created_at : new Date ( ) ,
4740 } ,
4841 }
4942
@@ -57,7 +50,6 @@ describe('/api/v1/chat/completions POST endpoint', () => {
5750 return {
5851 id : userData . id ,
5952 banned : userData . banned ,
60- created_at : userData . created_at ,
6153 } as Awaited < ReturnType < GetUserInfoFromApiKeyFn > >
6254 }
6355
@@ -95,22 +87,7 @@ describe('/api/v1/chat/completions POST endpoint', () => {
9587 totalDebt : 0 ,
9688 netBalance : 0 ,
9789 breakdown : { } ,
98- // Has purchased credits historically (principals > 0) but 0 remaining
99- // so the paid-plan gate passes and the credit check is what enforces 402.
100- principals : { purchase : 100 } ,
101- } ,
102- nextQuotaReset,
103- }
104- }
105- if ( userId === 'user-new-free' ) {
106- return {
107- usageThisCycle : 0 ,
108- balance : {
109- totalRemaining : 100 ,
110- totalDebt : 0 ,
111- netBalance : 100 ,
112- breakdown : { } as Record < string , number > ,
113- principals : { } as Record < string , number > ,
90+ principals : { } ,
11491 } ,
11592 nextQuotaReset,
11693 }
@@ -122,7 +99,7 @@ describe('/api/v1/chat/completions POST endpoint', () => {
12299 totalDebt : 0 ,
123100 netBalance : 100 ,
124101 breakdown : { } ,
125- principals : { purchase : 100 } ,
102+ principals : { } ,
126103 } ,
127104 nextQuotaReset,
128105 }
@@ -460,7 +437,7 @@ describe('/api/v1/chat/completions POST endpoint', () => {
460437 expect ( body . message ) . not . toContain ( nextQuotaReset )
461438 } )
462439
463- it ( 'returns 403 for a free-tier user with no paid relationship' , async ( ) => {
440+ it ( 'lets a new account with no paid relationship through for non-free mode ' , async ( ) => {
464441 const req = new NextRequest (
465442 'http://localhost:3000/api/v1/chat/completions' ,
466443 {
@@ -489,43 +466,6 @@ describe('/api/v1/chat/completions POST endpoint', () => {
489466 loggerWithContext : mockLoggerWithContext ,
490467 } )
491468
492- expect ( response . status ) . toBe ( 403 )
493- const body = await response . json ( )
494- expect ( body . error ) . toBe ( 'requires_paid_plan' )
495- } )
496-
497- it ( 'lets a BYOK free-tier new account through the paid-plan gate' , async ( ) => {
498- const req = new NextRequest (
499- 'http://localhost:3000/api/v1/chat/completions' ,
500- {
501- method : 'POST' ,
502- headers : {
503- Authorization : 'Bearer test-api-key-new-free' ,
504- 'x-openrouter-api-key' : 'sk-or-byok-test' ,
505- } ,
506- body : JSON . stringify ( {
507- model : 'test/test-model' ,
508- stream : false ,
509- codebuff_metadata : {
510- run_id : 'run-123' ,
511- client_id : 'test-client-id-123' ,
512- } ,
513- } ) ,
514- } ,
515- )
516-
517- const response = await postChatCompletions ( {
518- req,
519- getUserInfoFromApiKey : mockGetUserInfoFromApiKey ,
520- logger : mockLogger ,
521- trackEvent : mockTrackEvent ,
522- getUserUsageData : mockGetUserUsageData ,
523- getAgentRunFromId : mockGetAgentRunFromId ,
524- fetch : mockFetch ,
525- insertMessageBigquery : mockInsertMessageBigquery ,
526- loggerWithContext : mockLoggerWithContext ,
527- } )
528-
529469 expect ( response . status ) . toBe ( 200 )
530470 } )
531471
0 commit comments