diff --git a/cli/test/e2e/setup.ts b/cli/test/e2e/setup.ts index 822d20f6f3..309c2c05d1 100644 --- a/cli/test/e2e/setup.ts +++ b/cli/test/e2e/setup.ts @@ -37,7 +37,6 @@ export default async () => { } process.env.NODE_ENV = 'development'; - process.env.IMMICH_TEST_ENV = 'true'; process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/../../../server/test/e2e/immich-e2e-config.json`); process.env.TZ = 'Z'; }; diff --git a/server/src/domain/domain.module.ts b/server/src/domain/domain.module.ts index f1d0ddc0e5..1c53f70321 100644 --- a/server/src/domain/domain.module.ts +++ b/server/src/domain/domain.module.ts @@ -1,5 +1,5 @@ import { ImmichLogger } from '@app/infra/logger'; -import { DynamicModule, Global, Module, ModuleMetadata, Provider } from '@nestjs/common'; +import { Global, Module, Provider } from '@nestjs/common'; import { ActivityService } from './activity'; import { AlbumService } from './album'; import { APIKeyService } from './api-key'; @@ -31,10 +31,11 @@ const providers: Provider[] = [ AuditService, AuthService, DatabaseService, + ImmichLogger, JobService, + LibraryService, MediaService, MetadataService, - LibraryService, PersonService, PartnerService, SearchService, @@ -46,18 +47,12 @@ const providers: Provider[] = [ SystemConfigService, TagService, UserService, - ImmichLogger, ]; @Global() -@Module({}) -export class DomainModule { - static register(options: Pick): DynamicModule { - return { - module: DomainModule, - imports: options.imports, - providers: [...providers], - exports: [...providers], - }; - } -} +@Module({ + imports: [], + providers: [...providers], + exports: [...providers], +}) +export class DomainModule {} diff --git a/server/src/immich-admin/app.module.ts b/server/src/immich-admin/app.module.ts index fe0e35bb51..293e43c092 100644 --- a/server/src/immich-admin/app.module.ts +++ b/server/src/immich-admin/app.module.ts @@ -6,7 +6,7 @@ import { DisablePasswordLoginCommand, EnablePasswordLoginCommand } from './comma import { PromptPasswordQuestions, ResetAdminPasswordCommand } from './commands/reset-admin-password.command'; @Module({ - imports: [DomainModule.register({ imports: [InfraModule] })], + imports: [InfraModule, DomainModule], providers: [ ResetAdminPasswordCommand, PromptPasswordQuestions, diff --git a/server/src/immich/app.module.ts b/server/src/immich/app.module.ts index 3694626f26..ca346697a2 100644 --- a/server/src/immich/app.module.ts +++ b/server/src/immich/app.module.ts @@ -37,7 +37,8 @@ import { ErrorInterceptor, FileUploadInterceptor } from './interceptors'; @Module({ imports: [ // - DomainModule.register({ imports: [InfraModule] }), + InfraModule, + DomainModule, ScheduleModule.forRoot(), TypeOrmModule.forFeature([AssetEntity]), ], diff --git a/server/src/infra/infra.config.ts b/server/src/infra/infra.config.ts index 3758380a13..90ca9fc818 100644 --- a/server/src/infra/infra.config.ts +++ b/server/src/infra/infra.config.ts @@ -4,11 +4,6 @@ import { QueueOptions } from 'bullmq'; import { RedisOptions } from 'ioredis'; function parseRedisConfig(): RedisOptions { - if (process.env.IMMICH_TEST_ENV == 'true') { - // Currently running e2e tests, do not use redis - return {}; - } - const redisUrl = process.env.REDIS_URL; if (redisUrl && redisUrl.startsWith('ioredis://')) { try { @@ -28,11 +23,9 @@ function parseRedisConfig(): RedisOptions { }; } -export const redisConfig: RedisOptions = parseRedisConfig(); - export const bullConfig: QueueOptions = { prefix: 'immich_bull', - connection: redisConfig, + connection: parseRedisConfig(), defaultJobOptions: { attempts: 3, removeOnComplete: true, diff --git a/server/src/infra/infra.module.ts b/server/src/infra/infra.module.ts index aef41f5627..caa4257287 100644 --- a/server/src/infra/infra.module.ts +++ b/server/src/infra/infra.module.ts @@ -94,26 +94,30 @@ const providers: Provider[] = [ SchedulerRegistry, ]; -const imports = [ - ConfigModule.forRoot(immichAppConfig), - TypeOrmModule.forRoot(databaseConfig), - TypeOrmModule.forFeature(databaseEntities), - ScheduleModule, -]; - -const moduleExports = [...providers]; - -if (process.env.IMMICH_TEST_ENV !== 'true') { - // Currently not running e2e tests, set up redis and bull queues - imports.push(BullModule.forRoot(bullConfig)); - imports.push(BullModule.registerQueue(...bullQueues)); - moduleExports.push(BullModule); -} +@Global() +@Module({ + imports: [ + ConfigModule.forRoot(immichAppConfig), + TypeOrmModule.forRoot(databaseConfig), + TypeOrmModule.forFeature(databaseEntities), + ScheduleModule, + BullModule.forRoot(bullConfig), + BullModule.registerQueue(...bullQueues), + ], + providers: [...providers], + exports: [...providers, BullModule], +}) +export class InfraModule {} @Global() @Module({ - imports, + imports: [ + ConfigModule.forRoot(immichAppConfig), + TypeOrmModule.forRoot(databaseConfig), + TypeOrmModule.forFeature(databaseEntities), + ScheduleModule, + ], providers: [...providers], - exports: moduleExports, + exports: [...providers], }) -export class InfraModule {} +export class InfraTestModule {} diff --git a/server/src/microservices/microservices.module.ts b/server/src/microservices/microservices.module.ts index 9ffe4e38a9..4768d965f2 100644 --- a/server/src/microservices/microservices.module.ts +++ b/server/src/microservices/microservices.module.ts @@ -4,7 +4,7 @@ import { Module, OnModuleInit } from '@nestjs/common'; import { AppService } from './app.service'; @Module({ - imports: [DomainModule.register({ imports: [InfraModule] })], + imports: [InfraModule, DomainModule], providers: [AppService], }) export class MicroservicesModule implements OnModuleInit { diff --git a/server/test/e2e/setup.ts b/server/test/e2e/setup.ts index 1b9fcf239d..f2065e85a1 100644 --- a/server/test/e2e/setup.ts +++ b/server/test/e2e/setup.ts @@ -47,7 +47,6 @@ export default async () => { } process.env.NODE_ENV = 'development'; - process.env.IMMICH_TEST_ENV = 'true'; process.env.IMMICH_CONFIG_FILE = path.normalize(`${__dirname}/immich-e2e-config.json`); process.env.TZ = 'Z'; }; diff --git a/server/test/test-utils.ts b/server/test/test-utils.ts index 5356d83bff..3a91bc589a 100644 --- a/server/test/test-utils.ts +++ b/server/test/test-utils.ts @@ -1,10 +1,9 @@ import { AssetCreate, IJobRepository, JobItem, JobItemHandler, LibraryResponseDto, QueueName } from '@app/domain'; import { AppModule } from '@app/immich'; -import { dataSource } from '@app/infra'; +import { InfraModule, InfraTestModule, dataSource } from '@app/infra'; import { AssetEntity, AssetType, LibraryType } from '@app/infra/entities'; import { INestApplication } from '@nestjs/common'; import { Test } from '@nestjs/testing'; - import { randomBytes } from 'crypto'; import * as fs from 'fs'; import { DateTime } from 'luxon'; @@ -69,6 +68,8 @@ export const testApp = { const { jobs } = options || { jobs: false }; const moduleFixture = await Test.createTestingModule({ imports: [AppModule], providers: [AppService] }) + .overrideModule(InfraModule) + .useModule(InfraTestModule) .overrideProvider(IJobRepository) .useValue({ addHandler: (_queueName: QueueName, _concurrency: number, handler: JobItemHandler) => (_handler = handler),