@@ -14,11 +14,12 @@ import type { NextRequest } from 'next/server'
1414
1515function makeReq (
1616 apiKey : string | null ,
17- opts : { instanceId ?: string } = { } ,
17+ opts : { instanceId ?: string ; cfCountry ?: string } = { } ,
1818) : NextRequest {
1919 const headers = new Headers ( )
2020 if ( apiKey ) headers . set ( 'Authorization' , `Bearer ${ apiKey } ` )
2121 if ( opts . instanceId ) headers . set ( FREEBUFF_INSTANCE_HEADER , opts . instanceId )
22+ if ( opts . cfCountry ) headers . set ( 'cf-ipcountry' , opts . cfCountry )
2223 return {
2324 headers,
2425 } as unknown as NextRequest
@@ -102,6 +103,29 @@ describe('POST /api/v1/freebuff/session', () => {
102103 const body = await resp . json ( )
103104 expect ( body . status ) . toBe ( 'disabled' )
104105 } )
106+
107+ test ( 'returns country_blocked without joining the queue for disallowed country' , async ( ) => {
108+ const sessionDeps = makeSessionDeps ( )
109+ const resp = await postFreebuffSession (
110+ makeReq ( 'ok' , { cfCountry : 'FR' } ) ,
111+ makeDeps ( sessionDeps , 'u1' ) ,
112+ )
113+ expect ( resp . status ) . toBe ( 200 )
114+ const body = await resp . json ( )
115+ expect ( body . status ) . toBe ( 'country_blocked' )
116+ expect ( body . countryCode ) . toBe ( 'FR' )
117+ expect ( sessionDeps . rows . size ) . toBe ( 0 )
118+ } )
119+
120+ test ( 'allows queue entry for allowed country' , async ( ) => {
121+ const sessionDeps = makeSessionDeps ( )
122+ const resp = await postFreebuffSession (
123+ makeReq ( 'ok' , { cfCountry : 'US' } ) ,
124+ makeDeps ( sessionDeps , 'u1' ) ,
125+ )
126+ const body = await resp . json ( )
127+ expect ( body . status ) . toBe ( 'queued' )
128+ } )
105129} )
106130
107131describe ( 'GET /api/v1/freebuff/session' , ( ) => {
@@ -113,6 +137,18 @@ describe('GET /api/v1/freebuff/session', () => {
113137 expect ( body . status ) . toBe ( 'none' )
114138 } )
115139
140+ test ( 'returns country_blocked for disallowed country on GET' , async ( ) => {
141+ const sessionDeps = makeSessionDeps ( )
142+ const resp = await getFreebuffSession (
143+ makeReq ( 'ok' , { cfCountry : 'FR' } ) ,
144+ makeDeps ( sessionDeps , 'u1' ) ,
145+ )
146+ expect ( resp . status ) . toBe ( 200 )
147+ const body = await resp . json ( )
148+ expect ( body . status ) . toBe ( 'country_blocked' )
149+ expect ( body . countryCode ) . toBe ( 'FR' )
150+ } )
151+
116152 test ( 'returns superseded when active row exists with mismatched instance id' , async ( ) => {
117153 const sessionDeps = makeSessionDeps ( )
118154 sessionDeps . rows . set ( 'u1' , {
0 commit comments