@@ -382,18 +382,12 @@ describe('grant-credits', () => {
382382
383383 describe ( 'getPreviousFreeGrantAmount' , ( ) => {
384384 it ( 'should return default amount when no expired grants exist' , async ( ) => {
385- // The select().from().where().orderBy().limit() chain returns a promise-like
386- // array in Drizzle, so we need to make it thenable
387- const emptyResult : { principal : number } [ ] = [ ]
388- // @ts -expect-error - adding then to make it promise-like
389- emptyResult . then = ( cb : ( rows : typeof emptyResult ) => unknown ) => Promise . resolve ( cb ( emptyResult ) )
390-
391385 const mockDb = {
392386 select : ( ) => ( {
393387 from : ( ) => ( {
394388 where : ( ) => ( {
395389 orderBy : ( ) => ( {
396- limit : ( ) => emptyResult ,
390+ limit : ( ) => Promise . resolve ( [ ] ) ,
397391 } ) ,
398392 } ) ,
399393 } ) ,
@@ -406,21 +400,17 @@ describe('grant-credits', () => {
406400 deps : { db : mockDb as any } ,
407401 } )
408402
409- // Default free credits grant is 1000
410- expect ( result ) . toBe ( 1000 )
403+ // Default free credits grant is 500
404+ expect ( result ) . toBe ( 500 )
411405 } )
412406
413407 it ( 'should return capped amount from previous expired grant' , async ( ) => {
414- const grantResult = [ { principal : 3000 } ]
415- // @ts -expect-error - adding then to make it promise-like
416- grantResult . then = ( cb : ( rows : typeof grantResult ) => unknown ) => Promise . resolve ( cb ( grantResult ) )
417-
418408 const mockDb = {
419409 select : ( ) => ( {
420410 from : ( ) => ( {
421411 where : ( ) => ( {
422412 orderBy : ( ) => ( {
423- limit : ( ) => grantResult ,
413+ limit : ( ) => Promise . resolve ( [ { principal : 3000 } ] ) ,
424414 } ) ,
425415 } ) ,
426416 } ) ,
@@ -438,16 +428,12 @@ describe('grant-credits', () => {
438428 } )
439429
440430 it ( 'should return exact amount when previous grant was below cap' , async ( ) => {
441- const grantResult = [ { principal : 1500 } ]
442- // @ts -expect-error - adding then to make it promise-like
443- grantResult . then = ( cb : ( rows : typeof grantResult ) => unknown ) => Promise . resolve ( cb ( grantResult ) )
444-
445431 const mockDb = {
446432 select : ( ) => ( {
447433 from : ( ) => ( {
448434 where : ( ) => ( {
449435 orderBy : ( ) => ( {
450- limit : ( ) => grantResult ,
436+ limit : ( ) => Promise . resolve ( [ { principal : 1500 } ] ) ,
451437 } ) ,
452438 } ) ,
453439 } ) ,
0 commit comments