@@ -3456,4 +3456,48 @@ describe('query boostEstimatedReachDaily', () => {
34563456 } ,
34573457 ) ;
34583458 } ) ;
3459+
3460+ it ( 'should fall back to getAdjustedReach when min and max impressions are equal' , async ( ) => {
3461+ loggedUser = '1' ;
3462+
3463+ // Mock the HTTP response where min and max impressions are the same
3464+ const mockFetchParse = fetchParse as jest . Mock ;
3465+ mockFetchParse . mockResolvedValue ( {
3466+ impressions : 200 ,
3467+ clicks : 15 ,
3468+ users : 100 ,
3469+ min_impressions : 75 , // Same value
3470+ max_impressions : 75 , // Same value
3471+ } ) ;
3472+
3473+ const res = await client . query ( QUERY , {
3474+ variables : { ...params , budget : 4000 , duration : 10 } , // 4000 cores = 40 USD, 10 days
3475+ } ) ;
3476+
3477+ expect ( res . errors ) . toBeFalsy ( ) ;
3478+ // When min_impressions === max_impressions, it should use getAdjustedReach(maxImpressions)
3479+ // getAdjustedReach applies ±8% calculation: 75 ± Math.floor(75 * 0.08) = 75 ± 6
3480+ expect ( res . data . boostEstimatedReachDaily ) . toEqual ( {
3481+ min : 69 , // 75 - Math.floor(75 * 0.08) = 75 - 6 = 69
3482+ max : 81 , // 75 + Math.floor(75 * 0.08) = 75 + 6 = 81
3483+ } ) ;
3484+
3485+ // Verify the HTTP call was made with correct parameters
3486+ expect ( mockFetchParse ) . toHaveBeenCalledWith (
3487+ `${ process . env . SKADI_API_ORIGIN } /promote/post/reach` ,
3488+ {
3489+ method : 'POST' ,
3490+ headers : {
3491+ 'Content-Type' : 'application/json' ,
3492+ } ,
3493+ body : JSON . stringify ( {
3494+ post_id : 'p1' ,
3495+ user_id : '1' ,
3496+ duration : 10 * ONE_DAY_IN_SECONDS ,
3497+ budget : 40 , // Converted from cores to USD (4000 cores = 40 USD)
3498+ } ) ,
3499+ agent : expect . any ( Function ) ,
3500+ } ,
3501+ ) ;
3502+ } ) ;
34593503} ) ;
0 commit comments