Разобрался, вот решение кому понадобиться:
Нужно передать тестовый репозиторий в конструктор сервиса, где объявлена данная функция.
describe('Users Service Test /services/users.service.ts', () => {
let usersService: UsersService;
let smsCodesRepository: Repository<SmsCodes>;
let testingModule: TestingModule;
const testConnectionName = 'testConnection';
beforeEach(async () => {
testingModule = await Test.createTestingModule({
providers: [
UsersService,
{
provide: getRepositoryToken(SmsCodes),
useClass: Repository,
},
],
}).compile();
let connection = await createConnection({
type: "postgres",
database: "baseTest",
dropSchema: true,
entities: [SmsCodes],
synchronize: true,
name: testConnectionName
});
smsCodesRepository = getRepository(SmsCodes, testConnectionName);
usersService = new UsersService(userRepository, smsCodesRepository);
return connection;
});
afterEach(async () => {
await getConnection(testConnectionName).close()
});
describe('checkCorrectSmsCode', () => {
it('Возврат: true при правильном коде SMS', async () => {
const mockEmail = 'test@email.com'
const mockCode = 1234;
await smsCodesRepository.insert({
email: mockEmail,
code: mockCode,
});
const checkCorrectSms = await usersService.checkCorrectSmsCode(mockEmail, mockCode);
expect(checkCorrectSms).toBe(true);
})
})
});