diff --git a/src/app.module.ts b/src/app.module.ts index b22df05..65f3c09 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -16,13 +16,13 @@ import configuration from './commons/config/configuration'; }), TypeOrmModule.forRootAsync({ imports: [ConfigModule], - useFactory: (cnfigService: ConfigService) => ({ + useFactory: (configService: ConfigService) => ({ type: 'postgres', - host: cnfigService.get('db.postgres.host'), - port: cnfigService.get('db.postgres.port'), - username: cnfigService.get('db.postgres.username'), - password: cnfigService.get('db.postgres.password'), - database: cnfigService.get('db.postgres.database'), + host: configService.get('db.postgres.host'), + port: configService.get('db.postgres.port'), + username: configService.get('db.postgres.username'), + password: configService.get('db.postgres.password'), + database: configService.get('db.postgres.database'), synchronize: true, autoLoadEntities: true, }), diff --git a/src/repos/repos.service.spec.ts b/src/repos/repos.service.spec.ts index 1907379..1759e1f 100644 --- a/src/repos/repos.service.spec.ts +++ b/src/repos/repos.service.spec.ts @@ -2,11 +2,10 @@ import { Test, TestingModule } from '@nestjs/testing'; import { getRepositoryToken } from '@nestjs/typeorm'; import { Project } from '../projects/project.entity'; import { ReposService } from './repos.service'; -import { ConfigService } from '@nestjs/config'; +import { ConfigService, ConfigModule } from '@nestjs/config'; import { rm } from 'fs/promises'; import { join } from 'path'; - -const workspacesRoot = 'E:\\Projects\\demos\\workspaces'; +import configuration from '../commons/config/configuration'; describe('ReposService', () => { let service: ReposService; @@ -21,34 +20,35 @@ describe('ReposService', () => { }), ), })); + let workspacesRoot: string; afterEach(async () => { await rm(join(workspacesRoot, 'test1'), { recursive: true, }).catch(() => undefined); }); beforeEach(async () => { - await rm(join(workspacesRoot, 'test1'), { - recursive: true, - }).catch(() => undefined); const module: TestingModule = await Test.createTestingModule({ + imports: [ + ConfigModule.forRoot({ + load: [configuration], + }), + ], providers: [ ReposService, { provide: getRepositoryToken(Project), useFactory: repositoryMockFactory, }, - { - provide: ConfigService, - useValue: { - get() { - return workspacesRoot; - }, - }, - }, ], }).compile(); service = module.get(ReposService); + const configServer = module.get(ConfigService); + workspacesRoot = configServer.get('workspaces.root'); + + await rm(join(workspacesRoot, 'test1'), { + recursive: true, + }).catch(() => undefined); }); it('should be defined', () => {