@ -1,6 +1,7 @@
import { IJobRepository , JobItem, JobItemHandler , QueueName } from '@app/domain' ;
import { IJobRepository , IMediaRepository, JobItem, JobItemHandler , QueueName } from '@app/domain' ;
import { AppModule } from '@app/immich' ;
import { InfraModule , InfraTestModule , dataSource } from '@app/infra' ;
import { MediaRepository } from '@app/infra/repositories' ;
import { INestApplication } from '@nestjs/common' ;
import { Test } from '@nestjs/testing' ;
import { DateTime } from 'luxon' ;
@ -53,7 +54,42 @@ export const db = {
} ,
} ;
let _handler : JobItemHandler = ( ) = > Promise . resolve ( ) ;
class JobMock implements IJobRepository {
private _handler : JobItemHandler = ( ) = > Promise . resolve ( ) ;
addHandler ( _queueName : QueueName , _concurrency : number , handler : JobItemHandler ) {
this . _handler = handler ;
}
addCronJob() { }
updateCronJob() { }
deleteCronJob() { }
validateCronExpression() { }
queue ( item : JobItem ) {
return this . _handler ( item ) ;
}
queueAll ( items : JobItem [ ] ) {
return Promise . all ( items . map ( this . _handler ) ) . then ( ( ) = > Promise . resolve ( ) ) ;
}
async resume() { }
async empty() { }
async setConcurrency() { }
async getQueueStatus() {
return null as any ;
}
async getJobCounts() {
return null as any ;
}
async pause() { }
async clear() {
return [ ] ;
}
async waitForQueueCompletion() { }
}
class MediaMockRepository extends MediaRepository {
async generateThumbhash() {
return Buffer . from ( 'mock-thumbhash' ) ;
}
}
let app : INestApplication ;
@ -63,23 +99,9 @@ export const testApp = {
. overrideModule ( InfraModule )
. useModule ( InfraTestModule )
. overrideProvider ( IJobRepository )
. useValue ( {
addHandler : ( _queueName : QueueName , _concurrency : number , handler : JobItemHandler ) = > ( _handler = handler ) ,
addCronJob : jest.fn ( ) ,
updateCronJob : jest.fn ( ) ,
deleteCronJob : jest.fn ( ) ,
validateCronExpression : jest.fn ( ) ,
queue : ( item : JobItem ) = > _handler ( item ) ,
queueAll : ( items : JobItem [ ] ) = > Promise . all ( items . map ( _handler ) ) . then ( ( ) = > Promise . resolve ( ) ) ,
resume : jest.fn ( ) ,
empty : jest.fn ( ) ,
setConcurrency : jest.fn ( ) ,
getQueueStatus : jest.fn ( ) ,
getJobCounts : jest.fn ( ) ,
pause : jest.fn ( ) ,
clear : jest.fn ( ) ,
waitForQueueCompletion : jest.fn ( ) ,
} as IJobRepository )
. useClass ( JobMock )
. overrideProvider ( IMediaRepository )
. useClass ( MediaMockRepository )
. compile ( ) ;
app = await module Fixture.createNestApplication ( ) . init ( ) ;