@@ -5,6 +5,7 @@ import { CronExpressionParser } from 'cron-parser'
55import type { Adapter , AcquiredJob } from '../contracts/adapter.js'
66import type {
77 JobData ,
8+ JobClass ,
89 JobRecord ,
910 JobRetention ,
1011 ScheduleConfig ,
@@ -13,6 +14,7 @@ import type {
1314} from '../types/main.js'
1415import { DEFAULT_PRIORITY } from '../constants.js'
1516import { parse } from '../utils.js'
17+ import { Job } from '../job.js'
1618
1719interface ActiveJob {
1820 job : JobData
@@ -33,7 +35,7 @@ export interface FakeJobRecord {
3335 pushedAt : number
3436}
3537
36- export type FakeJobMatcher = string | ( ( job : JobData ) => boolean )
38+ export type FakeJobMatcher = string | JobClass | ( ( job : JobData ) => boolean )
3739export type FakePayloadMatcher =
3840 | ( ( payload : any ) => boolean )
3941 | object
@@ -539,7 +541,11 @@ export class FakeAdapter implements Adapter {
539541 }
540542
541543 const matchesJob =
542- typeof matcher === 'string' ? record . job . name === matcher : matcher ( record . job )
544+ typeof matcher === 'string'
545+ ? record . job . name === matcher
546+ : this . #isJobClass( matcher )
547+ ? record . job . name === this . #getJobClassName( matcher )
548+ : matcher ( record . job )
543549
544550 if ( ! matchesJob ) {
545551 return false
@@ -575,8 +581,9 @@ export class FakeAdapter implements Adapter {
575581 #formatFailure( prefix : string , matcher : FakeJobMatcher , query ?: FakeJobQuery ) : string {
576582 const parts = [ prefix ]
577583
578- if ( typeof matcher === 'string' ) {
579- parts . push ( `for "${ matcher } "` )
584+ const matcherName = this . #getMatcherName( matcher )
585+ if ( matcherName ) {
586+ parts . push ( `for "${ matcherName } "` )
580587 }
581588
582589 if ( query ?. queue ) {
@@ -597,4 +604,24 @@ export class FakeAdapter implements Adapter {
597604
598605 return `${ parts . join ( ' ' ) } . ${ suffix } .`
599606 }
607+
608+ #getMatcherName( matcher : FakeJobMatcher ) : string | undefined {
609+ if ( typeof matcher === 'string' ) {
610+ return matcher
611+ }
612+
613+ if ( this . #isJobClass( matcher ) ) {
614+ return this . #getJobClassName( matcher )
615+ }
616+
617+ return undefined
618+ }
619+
620+ #isJobClass( matcher : FakeJobMatcher ) : matcher is JobClass {
621+ return typeof matcher === 'function' && matcher . prototype instanceof Job
622+ }
623+
624+ #getJobClassName( JobClass : JobClass ) : string {
625+ return JobClass . options ?. name || JobClass . name
626+ }
600627}
0 commit comments