Skip to content

Commit

Permalink
test: 🧪 pass database module test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumeisongsong committed Nov 18, 2024
1 parent e72180f commit 3485c3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ describe('DatabaseModule', () => {
it('should configure MongoDB connection using config service values', async () => {
const mockConfigService = {
get: jest.fn().mockReturnValue({
host: 'test-host',
host: 'localhost',
port: 27017,
name: 'test-db'
name: 'test'
})
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { ConfigService } from '@nestjs/config';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { databaseConfig } from '@shared/config';

@Module({
imports: [
ConfigModule.forRoot({
load: [databaseConfig],
}),
MongooseModule.forRootAsync({
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
const databaseConfig = configService.get('database');

return {
uri: `mongodb://${databaseConfig.host}:${databaseConfig.port}`,
dbName: databaseConfig.name,
Expand Down

0 comments on commit 3485c3f

Please sign in to comment.