Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getRepositoryToken(DbNotebook),
);
const noteRepo: Repository = module.get(getRepositoryToken(DbNote));
const eventsRepo: Repository = module.get(
getRepositoryToken(DbAction),
);
const fileTreeRepo: FileTreeRepository = module.get(
getRepositoryToken(FileTreeRepository),
);
const folderRepo: Repository = module.get(
getRepositoryToken(DbFolder),
);
const favoritesRepo: Repository = module.get(
getRepositoryToken(DbFavorites),
);
const conn: Connection = module.get(getConnectionToken());
const configService: ConfigService = module.get(ConfigService);
return new QuixEventBusDriver(
eventBus,
module,
noteRepo,
notebookRepo,
eventsRepo,
folderRepo,
fileTreeRepo,
favoritesRepo,
conn,
configService,
defaultUser,
);
}
export function getCustomRepository(name: string, repo) {
const module: typeof TypeormModule = require('@nestjs/typeorm');
return {
provide: name,
useFactory: (connection: Connection) => connection.getCustomRepository(repo),
inject: [module.getConnectionToken()],
};
}
import {Test, TestingModule} from '@nestjs/testing';
import {getConnectionToken} from '@nestjs/typeorm';
import {AppController} from './app.controller';
import {ConfigModule} from './config';
import {ValueProvider} from '@nestjs/common/interfaces';
const fakeConnection = {
provide: getConnectionToken(),
useValue: {},
};
describe('AppController', () => {
let appController: AppController;
let app: TestingModule | null = null;
async function preTest(mocked?: ValueProvider) {
const testingModule = Test.createTestingModule({
controllers: [AppController],
providers: [fakeConnection],
imports: [ConfigModule],
});
if (mocked) {
testingModule.overrideProvider(mocked.provide).useValue(mocked.useValue);
}
export function getRepo(name: string, entity) {
return {
provide: name,
useFactory: (connection: Connection) => connection.getRepository(entity),
inject: [getConnectionToken()],
};
}
beforeAll(async () => {
module = await Test.createTestingModule({
imports: [ConfigModule, ChannelModule, CFCoreModule, DatabaseModule],
})
.overrideProvider(CFCoreProviderId)
.useValue(mockCFCoreProvider)
.compile();
service = module.get(ChannelService);
connection = module.get(getConnectionToken());
channelRepository = connection.getCustomRepository(ChannelRepository);
});
export function getCustomRepo(name: string, repo) {
return {
provide: name,
useFactory: (connection: Connection) => connection.getCustomRepository(repo),
inject: [getConnectionToken()],
};
}
],
providers: [],
exports: [],
}).compile();
notebookRepo = module.get(getRepositoryToken(DbNotebook));
noteRepo = module.get(getRepositoryToken(NoteRepository));
eventsRepo = module.get(getRepositoryToken(DbAction));
fileTreeRepo = module.get(getRepositoryToken(FileTreeRepository));
folderRepo = module.get(getRepositoryToken(DbFolder));
favoritesRepo = module.get(getRepositoryToken(DbFavorites));
userRepo = module.get(getRepositoryToken(DbUser));
folderService = module.get(FoldersService);
notebookService = module.get(NotebookService);
favoritesService = module.get(FavoritesService);
conn = module.get(getConnectionToken());
configService = module.get(ConfigService);
});
export function getRepository(name: string, entity) {
const module: typeof TypeormModule = require('@nestjs/typeorm');
return {
provide: name,
useFactory: (connection: Connection) => connection.getRepository(entity),
inject: [module.getConnectionToken()],
};
}