-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41da7c4
commit 800d9f7
Showing
6 changed files
with
145 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { ConfigModule, ConfigService } from '@nestjs/config'; | ||
import { AppModule } from './app.module'; | ||
import { UserModule } from './user/user.module'; | ||
import { Logger } from '@nestjs/common'; | ||
|
||
describe('AppModule', () => { | ||
let module: TestingModule; | ||
|
||
beforeEach(async () => { | ||
const mockConfigService = { | ||
get: jest.fn().mockReturnValue('mongodb://localhost/test'), | ||
}; | ||
|
||
module = await Test.createTestingModule({ | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
isGlobal: true, | ||
}), | ||
MongooseModule.forRootAsync({ | ||
imports: [ConfigModule], | ||
useFactory: async (configService: ConfigService) => { | ||
Logger.log('Factory function called', 'Database'); | ||
const uri = configService.get<string>('MONGODB_URI'); | ||
Logger.log(`MongoDB URI: ${uri}`, 'Database'); | ||
return { uri }; | ||
}, | ||
inject: [ConfigService], | ||
}), | ||
UserModule, | ||
], | ||
}) | ||
.overrideProvider(ConfigService) | ||
.useValue(mockConfigService) | ||
.compile(); | ||
}); | ||
|
||
it('should compile the module', () => { | ||
expect(module).toBeDefined(); | ||
}); | ||
|
||
it('should use the correct MongoDB URI', () => { | ||
const configService = module.get<ConfigService>(ConfigService); | ||
expect(configService.get('MONGODB_URI')).toBe('mongodb://localhost/test'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AuthModule } from './auth.module'; | ||
import { AuthService } from './auth.service'; | ||
import { AuthController } from './auth.controller'; | ||
|
||
describe('AuthModule', () => { | ||
let module: TestingModule; | ||
|
||
beforeEach(async () => { | ||
module = await Test.createTestingModule({ | ||
imports: [AuthModule], | ||
}).compile(); | ||
}); | ||
|
||
it('should compile the module', () => { | ||
expect(module).toBeDefined(); | ||
}); | ||
|
||
it('should provide AuthService', () => { | ||
const authService = module.get<AuthService>(AuthService); | ||
expect(authService).toBeDefined(); | ||
}); | ||
|
||
it('should provide AuthController', () => { | ||
const authController = module.get<AuthController>(AuthController); | ||
expect(authController).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters