Looking for some guidance on writing tests and mocking the typeORM repository. I've tried a few approaches, but couldn't quite figure it out, particularly with the @InjectRepository method. Any suggestions?
import { AfterRoutesInit, Service } from '@tsed/common';
import { TypeORMService } from '@tsed/typeorm';
import { Connection, Repository } from 'typeorm';
import { DbAccount } from '../entity/DbAccount';
import { DbAddress } from '../entity/DbAddress';
import { Account } from '../models/Account';
import { Address } from '../models/address';
import { Pageable } from '../models/api_common/Pageable';
@Service()
export default class AccountService implements AfterRoutesInit {
private repository: Repository<DbAccount>;
private addressRepository: Repository<DbAddress>;
constructor(private typeORMService: TypeORMService) { }
$afterRoutesInit(): void | Promise<any> {
const connection: Connection = this.typeORMService.get('default');
this.repository = connection.getRepository(DbAccount);
this.addressRepository = connection.getRepository(DbAddress);
}
async delete(accountId: string): Promise<void> {
await this.repository.delete(accountId);
return;
}
}