@@ -40,8 +40,8 @@ type MockTransactionOptions = {
4040 expires_at : Date
4141 } >
4242 referralTotal ?: number
43- onInsert ?: ( values : any ) => void
44- onUpdate ?: ( values : any ) => void
43+ onInsert ?: ( values : Record < string , unknown > ) => void
44+ onUpdate ?: ( values : Record < string , unknown > ) => void
4545}
4646
4747const createMockTransaction = ( options : MockTransactionOptions ) : BillingTransactionFn => {
@@ -54,14 +54,14 @@ const createMockTransaction = (options: MockTransactionOptions): BillingTransact
5454 onUpdate,
5555 } = options
5656
57- return async < T > ( callback : ( tx : any ) => Promise < T > ) : Promise < T > => {
57+ return async < T > ( callback : ( tx : Record < string , unknown > ) => Promise < T > ) : Promise < T > => {
5858 const tx = {
5959 query : {
6060 user : {
6161 findFirst : async ( ) => user ,
6262 } ,
6363 creditLedger : {
64- findFirst : async ( params : any ) => {
64+ findFirst : async ( params : Record < string , unknown > | undefined ) => {
6565 // For revoke tests - find by operation_id
6666 if ( params ?. where ) {
6767 return grants [ 0 ] ?? null
@@ -71,32 +71,32 @@ const createMockTransaction = (options: MockTransactionOptions): BillingTransact
7171 } ,
7272 } ,
7373 update : ( ) => ( {
74- set : ( values : any ) => ( {
74+ set : ( values : Record < string , unknown > ) => ( {
7575 where : ( ) => {
7676 onUpdate ?.( values )
7777 return Promise . resolve ( )
7878 } ,
7979 } ) ,
8080 } ) ,
8181 insert : ( ) => ( {
82- values : ( values : any ) => {
82+ values : ( values : Record < string , unknown > ) => {
8383 onInsert ?.( values )
8484 return Promise . resolve ( )
8585 } ,
8686 } ) ,
87- select : ( fields ?: any ) => ( {
87+ select : ( fields ?: Record < string , unknown > ) => ( {
8888 from : ( ) => ( {
8989 where : ( ) => ( {
9090 orderBy : ( ) => ( {
9191 limit : ( ) => expiredGrants ,
9292 } ) ,
93- then : ( cb : any ) => {
93+ then : < R > ( cb : ( rows : Array < { balance : number } > ) => R ) : R => {
9494 // For checking negative balances - filter grants with balance < 0
9595 const negativeGrants = grants . filter ( g => g . balance < 0 )
9696 return cb ( negativeGrants )
9797 } ,
9898 } ) ,
99- then : ( cb : any ) => {
99+ then : < R > ( cb : ( rows : Array < { totalCredits : string } > ) => R ) : R => {
100100 // For referral query
101101 if ( fields && 'totalCredits' in fields ) {
102102 return cb ( [ { totalCredits : referralTotal . toString ( ) } ] )
@@ -208,8 +208,8 @@ describe('grant-credits', () => {
208208 describe ( 'grantCreditOperation' , ( ) => {
209209 describe ( 'debt settlement' , ( ) => {
210210 it ( 'should settle debt when granting new credits' , async ( ) => {
211- const insertedGrants : any [ ] = [ ]
212- const updatedValues : any [ ] = [ ]
211+ const insertedGrants : Record < string , unknown > [ ] = [ ]
212+ const updatedValues : Record < string , unknown > [ ] = [ ]
213213
214214 // Create a mock tx with negative balance grant
215215 const mockTx = {
@@ -221,7 +221,7 @@ describe('grant-credits', () => {
221221 select : ( ) => ( {
222222 from : ( ) => ( {
223223 where : ( ) => ( {
224- then : ( cb : any ) =>
224+ then : < R > ( cb : ( rows : Array < { operation_id : string ; user_id : string ; balance : number ; type : string } > ) => R ) : R =>
225225 cb ( [
226226 {
227227 operation_id : 'debt-grant-1' ,
@@ -234,15 +234,15 @@ describe('grant-credits', () => {
234234 } ) ,
235235 } ) ,
236236 update : ( ) => ( {
237- set : ( values : any ) => ( {
237+ set : ( values : Record < string , unknown > ) => ( {
238238 where : ( ) => {
239239 updatedValues . push ( values )
240240 return Promise . resolve ( )
241241 } ,
242242 } ) ,
243243 } ) ,
244244 insert : ( ) => ( {
245- values : ( values : any ) => {
245+ values : ( values : Record < string , unknown > ) => {
246246 insertedGrants . push ( values )
247247 return Promise . resolve ( )
248248 } ,
@@ -272,7 +272,7 @@ describe('grant-credits', () => {
272272 } )
273273
274274 it ( 'should create grant with full balance when no debt exists' , async ( ) => {
275- const insertedGrants : any [ ] = [ ]
275+ const insertedGrants : Record < string , unknown > [ ] = [ ]
276276
277277 const mockTx = {
278278 query : {
@@ -283,7 +283,7 @@ describe('grant-credits', () => {
283283 select : ( ) => ( {
284284 from : ( ) => ( {
285285 where : ( ) => ( {
286- then : ( cb : any ) => cb ( [ ] ) , // No negative balance grants
286+ then : < R > ( cb : ( rows : never [ ] ) => R ) : R => cb ( [ ] ) , // No negative balance grants
287287 } ) ,
288288 } ) ,
289289 } ) ,
@@ -293,7 +293,7 @@ describe('grant-credits', () => {
293293 } ) ,
294294 } ) ,
295295 insert : ( ) => ( {
296- values : ( values : any ) => {
296+ values : ( values : Record < string , unknown > ) => {
297297 insertedGrants . push ( values )
298298 return Promise . resolve ( )
299299 } ,
@@ -319,8 +319,8 @@ describe('grant-credits', () => {
319319 } )
320320
321321 it ( 'should not create grant when debt exceeds amount' , async ( ) => {
322- const insertedGrants : any [ ] = [ ]
323- const updatedValues : any [ ] = [ ]
322+ const insertedGrants : Record < string , unknown > [ ] = [ ]
323+ const updatedValues : Record < string , unknown > [ ] = [ ]
324324
325325 const mockTx = {
326326 query : {
@@ -331,7 +331,7 @@ describe('grant-credits', () => {
331331 select : ( ) => ( {
332332 from : ( ) => ( {
333333 where : ( ) => ( {
334- then : ( cb : any ) =>
334+ then : < R > ( cb : ( rows : Array < { operation_id : string ; user_id : string ; balance : number ; type : string } > ) => R ) : R =>
335335 cb ( [
336336 {
337337 operation_id : 'debt-grant-1' ,
@@ -344,15 +344,15 @@ describe('grant-credits', () => {
344344 } ) ,
345345 } ) ,
346346 update : ( ) => ( {
347- set : ( values : any ) => ( {
347+ set : ( values : Record < string , unknown > ) => ( {
348348 where : ( ) => {
349349 updatedValues . push ( values )
350350 return Promise . resolve ( )
351351 } ,
352352 } ) ,
353353 } ) ,
354354 insert : ( ) => ( {
355- values : ( values : any ) => {
355+ values : ( values : Record < string , unknown > ) => {
356356 insertedGrants . push ( values )
357357 return Promise . resolve ( )
358358 } ,
@@ -512,8 +512,8 @@ describe('grant-credits', () => {
512512
513513 describe ( 'processAndGrantCredit' , ( ) => {
514514 it ( 'should call grantCreditOperation with correct params' , async ( ) => {
515- let capturedParams : any = null
516- const mockGrantCreditFn = async ( params : any ) => {
515+ let capturedParams : Record < string , unknown > | null = null
516+ const mockGrantCreditFn = async ( params : Record < string , unknown > ) => {
517517 capturedParams = params
518518 }
519519
@@ -528,11 +528,12 @@ describe('grant-credits', () => {
528528 deps : { grantCreditFn : mockGrantCreditFn as any } ,
529529 } )
530530
531- expect ( capturedParams . userId ) . toBe ( 'user-123' )
532- expect ( capturedParams . amount ) . toBe ( 500 )
533- expect ( capturedParams . type ) . toBe ( 'purchase' )
534- expect ( capturedParams . description ) . toBe ( 'Test grant' )
535- expect ( capturedParams . operationId ) . toBe ( 'op-123' )
531+ expect ( capturedParams ) . not . toBeNull ( )
532+ expect ( capturedParams ! . userId ) . toBe ( 'user-123' )
533+ expect ( capturedParams ! . amount ) . toBe ( 500 )
534+ expect ( capturedParams ! . type ) . toBe ( 'purchase' )
535+ expect ( capturedParams ! . description ) . toBe ( 'Test grant' )
536+ expect ( capturedParams ! . operationId ) . toBe ( 'op-123' )
536537 } )
537538
538539 it ( 'should log sync failure on error' , async ( ) => {
@@ -567,7 +568,7 @@ describe('grant-credits', () => {
567568
568569 describe ( 'revokeGrantByOperationId' , ( ) => {
569570 it ( 'should successfully revoke a grant with positive balance' , async ( ) => {
570- const updatedValues : any [ ] = [ ]
571+ const updatedValues : Record < string , unknown > [ ] = [ ]
571572
572573 const mockTransaction : BillingTransactionFn = async ( callback ) => {
573574 const tx = {
@@ -584,7 +585,7 @@ describe('grant-credits', () => {
584585 } ,
585586 } ,
586587 update : ( ) => ( {
587- set : ( values : any ) => ( {
588+ set : ( values : Record < string , unknown > ) => ( {
588589 where : ( ) => {
589590 updatedValues . push ( values )
590591 return Promise . resolve ( )
@@ -671,7 +672,7 @@ describe('grant-credits', () => {
671672 } )
672673
673674 it ( 'should successfully revoke a grant with zero balance' , async ( ) => {
674- const updatedValues : any [ ] = [ ]
675+ const updatedValues : Record < string , unknown > [ ] = [ ]
675676
676677 const mockTransaction : BillingTransactionFn = async ( callback ) => {
677678 const tx = {
@@ -688,7 +689,7 @@ describe('grant-credits', () => {
688689 } ,
689690 } ,
690691 update : ( ) => ( {
691- set : ( values : any ) => ( {
692+ set : ( values : Record < string , unknown > ) => ( {
692693 where : ( ) => {
693694 updatedValues . push ( values )
694695 return Promise . resolve ( )
0 commit comments