06112602ec
Version the NestJS TDLib gateway with Docker deployment, migrations, automated tests and platform integration documentation while excluding all account sessions, credentials, runtime databases and backups.
103 lines
3.5 KiB
TypeScript
103 lines
3.5 KiB
TypeScript
/**
|
|
* Test Application Module
|
|
* Same as AppModule but uses in-memory pg-mem database
|
|
* and skips Redis/BullMQ to run without external dependencies.
|
|
*/
|
|
import { Module } from '@nestjs/common';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { ConfigModule } from '@nestjs/config';
|
|
import { ThrottlerModule } from '@nestjs/throttler';
|
|
import { APP_GUARD } from '@nestjs/core';
|
|
import { DataSource } from 'typeorm';
|
|
import { newDb } from 'pg-mem';
|
|
|
|
import { appConfig } from '../src/config/app.config';
|
|
import { databaseConfig } from '../src/config/database.config';
|
|
import { redisConfig } from '../src/config/redis.config';
|
|
import { rateLimitConfig } from '../src/config/rate-limit.config';
|
|
|
|
// Modules
|
|
import { JwtAuthGuard } from '../src/common/guards/jwt-auth.guard';
|
|
import { TenantsModule } from '../src/modules/tenants/tenants.module';
|
|
import { AuthModule } from '../src/modules/auth/auth.module';
|
|
import { TgAccountsModule } from '../src/modules/tg-accounts/tg-accounts.module';
|
|
import { TgAuthModule } from '../src/modules/tg-auth/tg-auth.module';
|
|
import { TgProxiesModule } from '../src/modules/tg-proxies/tg-proxies.module';
|
|
import { TdlibModule } from '../src/modules/tdlib/tdlib.module';
|
|
import { TgChatsModule } from '../src/modules/tg-chats/tg-chats.module';
|
|
import { TgDialogsModule } from '../src/modules/tg-dialogs/tg-dialogs.module';
|
|
import { TgContactsModule } from '../src/modules/tg-contacts/tg-contacts.module';
|
|
import { TgMessagesModule } from '../src/modules/tg-messages/tg-messages.module';
|
|
import { TgGroupsModule } from '../src/modules/tg-groups/tg-groups.module';
|
|
import { TgChannelsModule } from '../src/modules/tg-channels/tg-channels.module';
|
|
import { TgFilesModule } from '../src/modules/tg-files/tg-files.module';
|
|
import { TgWebhooksModule } from '../src/modules/tg-webhooks/tg-webhooks.module';
|
|
import { TgRateLimitModule } from '../src/modules/tg-rate-limit/tg-rate-limit.module';
|
|
import { TgAuditModule } from '../src/modules/tg-audit/tg-audit.module';
|
|
import { AdminModule } from '../src/modules/admin/admin.module';
|
|
|
|
// Setup pg-mem in-memory database
|
|
const pgMemDb = newDb();
|
|
pgMemDb.public.registerFunction({
|
|
name: 'uuid_generate_v4',
|
|
returns: 'uuid',
|
|
implementation: () => require('uuid').v4(),
|
|
});
|
|
pgMemDb.public.registerFunction({
|
|
name: 'now',
|
|
returns: 'timestamp',
|
|
implementation: () => new Date().toISOString(),
|
|
});
|
|
|
|
// Create TypeORM DataSource from pg-mem
|
|
const testDataSource = pgMemDb.adapters.createTypeormDataSource({
|
|
type: 'postgres',
|
|
entities: [__dirname + '/../src/database/entities/**/*.entity.{ts,js}'],
|
|
synchronize: true,
|
|
});
|
|
|
|
@Module({
|
|
imports: [
|
|
ConfigModule.forRoot({
|
|
isGlobal: true,
|
|
load: [appConfig, databaseConfig, redisConfig, rateLimitConfig],
|
|
envFilePath: ['.env'],
|
|
}),
|
|
TypeOrmModule.forRootAsync({
|
|
useFactory: async () => {
|
|
await testDataSource.initialize();
|
|
return testDataSource.options;
|
|
},
|
|
dataSourceFactory: async () => testDataSource,
|
|
}),
|
|
// Skip BullMQ (no Redis available for testing)
|
|
ThrottlerModule.forRoot({
|
|
throttlers: [{ ttl: 60000, limit: 1000 }],
|
|
}),
|
|
TenantsModule,
|
|
AuthModule,
|
|
TgAccountsModule,
|
|
TgAuthModule,
|
|
TgProxiesModule,
|
|
TdlibModule,
|
|
TgChatsModule,
|
|
TgDialogsModule,
|
|
TgContactsModule,
|
|
TgMessagesModule,
|
|
TgGroupsModule,
|
|
TgChannelsModule,
|
|
TgFilesModule,
|
|
TgWebhooksModule,
|
|
TgRateLimitModule,
|
|
TgAuditModule,
|
|
AdminModule,
|
|
],
|
|
providers: [
|
|
{
|
|
provide: APP_GUARD,
|
|
useClass: JwtAuthGuard,
|
|
},
|
|
],
|
|
})
|
|
export class TestAppModule {}
|