@@ -40,12 +40,16 @@ const createTxMock = (user: {
4040 } ) ,
4141 select : ( ) => ( {
4242 from : ( ) => ( {
43- where : ( ) => ( {
44- orderBy : ( ) => ( {
45- limit : ( ) => [ ] ,
46- } ) ,
47- } ) ,
48- then : ( cb : any ) => cb ( [ ] ) ,
43+ where : ( ) => {
44+ // Create a thenable object that also supports orderBy for different code paths
45+ return {
46+ orderBy : ( ) => ( {
47+ limit : ( ) => [ ] ,
48+ } ) ,
49+ // Make this thenable for the .where().then() pattern used in grant-credits.ts
50+ then : ( resolve : any , reject ?: any ) => Promise . resolve ( [ ] ) . then ( resolve , reject ) ,
51+ }
52+ } ,
4953 } ) ,
5054 } ) ,
5155 execute : ( ) => Promise . resolve ( [ ] ) ,
@@ -122,7 +126,7 @@ describe('grant-credits', () => {
122126
123127 it ( 'should return total credits when user has legacy referrals as referred' , async ( ) => {
124128 await mockModule ( '@codebuff/internal/db' , ( ) => ( {
125- default : createDbMockForReferralQuery ( '250 ' ) ,
129+ default : createDbMockForReferralQuery ( '500 ' ) ,
126130 } ) )
127131
128132 const { calculateTotalLegacyReferralBonus } = await import ( '../grant-credits' )
@@ -132,7 +136,7 @@ describe('grant-credits', () => {
132136 logger,
133137 } )
134138
135- expect ( result ) . toBe ( 250 )
139+ expect ( result ) . toBe ( 500 )
136140 } )
137141
138142 it ( 'should return combined total when user has legacy referrals as both referrer and referred' , async ( ) => {
@@ -407,12 +411,17 @@ describe('grant-credits', () => {
407411 } ) ,
408412 select : ( ) => ( {
409413 from : ( ) => ( {
410- where : ( ) => ( {
411- orderBy : ( ) => ( {
412- limit : ( ) => [ ] ,
413- } ) ,
414- } ) ,
415- then : ( cb : any ) => cb ( [ { totalCredits : String ( legacyReferralBonus ) } ] ) ,
414+ where : ( ) => {
415+ // Create a thenable object that also supports orderBy for different code paths
416+ const result = [ { totalCredits : String ( legacyReferralBonus ) } ]
417+ return {
418+ orderBy : ( ) => ( {
419+ limit : ( ) => [ ] ,
420+ } ) ,
421+ // Make this thenable for the .where().then() pattern used in grant-credits.ts
422+ then : ( resolve : any , reject ?: any ) => Promise . resolve ( result ) . then ( resolve , reject ) ,
423+ }
424+ } ,
416425 } ) ,
417426 } ) ,
418427 execute : ( ) => Promise . resolve ( [ ] ) ,
0 commit comments