22 * @vitest -environment node
33 */
44import { idempotencyKey } from '@sim/db/schema'
5- import { dbChainMock , drizzleOrmMock , resetDbChainMock } from '@sim/testing'
6- import { like } from 'drizzle-orm'
5+ import { dbChainMock , resetDbChainMock } from '@sim/testing'
6+ import { like , notLike } from 'drizzle-orm'
77import { afterAll , beforeEach , describe , expect , it , vi } from 'vitest'
88
9- const { mockNotLike } = vi . hoisted ( ( ) => ( {
10- mockNotLike : vi . fn ( ( column : unknown , pattern : unknown ) => ( { type : 'notLike' , column, pattern } ) ) ,
11- } ) )
12-
139vi . mock ( '@sim/db' , ( ) => dbChainMock )
14- /** The shared operator mock has no `notLike`; extend it for this suite only. */
15- vi . mock ( 'drizzle-orm' , ( ) => ( { ...drizzleOrmMock , notLike : mockNotLike } ) )
1610vi . mock ( '@sim/utils/helpers' , ( ) => ( { sleep : vi . fn ( ) } ) )
1711
1812import { cleanupExpiredIdempotencyKeys } from '@/lib/core/idempotency/cleanup'
@@ -28,19 +22,19 @@ describe('cleanupExpiredIdempotencyKeys', () => {
2822 it ( 'retains irreversible admin credit-grant keys during global cleanup' , async ( ) => {
2923 await cleanupExpiredIdempotencyKeys ( )
3024
31- expect ( mockNotLike ) . toHaveBeenCalledWith ( idempotencyKey . key , 'admin-credit-grant:%' )
25+ expect ( notLike ) . toHaveBeenCalledWith ( idempotencyKey . key , 'admin-credit-grant:%' )
3226 } )
3327
3428 it ( 'retains permanent workflow execution ID claims during global cleanup' , async ( ) => {
3529 await cleanupExpiredIdempotencyKeys ( )
3630
37- expect ( mockNotLike ) . toHaveBeenCalledWith ( idempotencyKey . key , 'workflow-execution-id:%' )
31+ expect ( notLike ) . toHaveBeenCalledWith ( idempotencyKey . key , 'workflow-execution-id:%' )
3832 } )
3933
4034 it ( 'keeps explicit namespace cleanup behavior unchanged' , async ( ) => {
4135 await cleanupExpiredIdempotencyKeys ( { namespace : 'webhook' } )
4236
4337 expect ( like ) . toHaveBeenCalledWith ( idempotencyKey . key , 'webhook:%' )
44- expect ( mockNotLike ) . not . toHaveBeenCalled ( )
38+ expect ( notLike ) . not . toHaveBeenCalled ( )
4539 } )
4640} )
0 commit comments