Как смоделировать репозиторий typeORM - PullRequest
0 голосов
/ 10 июля 2019

Я хотел бы написать несколько тестов и смоделировать репозиторий typeORM. Пробовал несколько вещей, но это не помогло ... (например, @InjectRepository) ... Есть мысли?

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;
    }

}
...