Estoy llamando a métodos de repository dentro del service y ahora tengo que escribir la prueba unitaria para el servicio. Quiero moke Repository Class o Method ambos.
Aquí está el código de service para el que tengo que escribir una prueba.
import { AttackMatrixRepo } from '../repositories/index'; export const serGetAttackMatrixDetail = async () => { const attMatRepo = new AttackMatrixRepo(); const table = await attMatRepo.repGetMatric(); return table; };Aquí está el código del repositorio.
import { AttackMatrix } from '../entities/index'; // typeorm AttackMatrix schema import { Repository, BaseEntity } from 'typeorm'; import { AppDataSource } from '../bootstrap/typeorm'; // typeorm connection export class AttackMatrixRepo extends BaseEntity { private attackMatrixEntity: Repository<AttackMatrix>; constructor() { super(); this.attackMatrixEntity = AppDataSource.getRepository(AttackMatrix); } public async repGetMatric() { return this.attackMatrixEntity.createQueryBuilder('attMatric').getOne(); } public async getMatrixByStixId({ columNames = ['*'], stixId }): Promise<AttackMatrix> { const tacticQueryBuilder = await this.attackMatrixEntity.createQueryBuilder('matrix'); const query = tacticQueryBuilder.select(columNames).where('matrix.stix_id = :stixId', { stixId }); return query.getRawOne(); } }