- Adiciona variáveis globais do Node.js (process, console, __dirname, require, module, exports) - Adiciona variáveis globais do Jest (describe, it, beforeEach, fail, etc.) - Configura ESLint para arquivos JavaScript de configuração - Remove diretivas eslint-disable não utilizadas - Corrige variáveis não usadas prefixando com _ - Ajusta regras do ESLint para ignorar variáveis que começam com _ - Formata código com Prettier
186 lines
5.1 KiB
TypeScript
186 lines
5.1 KiB
TypeScript
import { createDebServiceTestModule } from './deb.service.spec.helper';
|
|
import { DebDto } from '../../dto/DebDto';
|
|
|
|
describe('DebService', () => {
|
|
describe('findByCpfCgcent', () => {
|
|
let context: Awaited<ReturnType<typeof createDebServiceTestModule>>;
|
|
|
|
beforeEach(async () => {
|
|
context = await createDebServiceTestModule();
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('deve buscar débitos por CPF/CGCENT com sucesso', async () => {
|
|
const mockDebs: DebDto[] = [
|
|
{
|
|
dtemissao: new Date('2024-01-15'),
|
|
codfilial: '1',
|
|
duplic: '12345',
|
|
prest: '1',
|
|
codcli: 1000,
|
|
cliente: 'JOÃO DA SILVA',
|
|
codcob: 'BL',
|
|
cobranca: 'BOLETO',
|
|
dtvenc: new Date('2024-02-15'),
|
|
dtpag: null,
|
|
valor: 150.5,
|
|
situacao: 'A VENCER',
|
|
},
|
|
{
|
|
dtemissao: new Date('2024-01-20'),
|
|
codfilial: '1',
|
|
duplic: '12346',
|
|
prest: '2',
|
|
codcli: 1000,
|
|
cliente: 'JOÃO DA SILVA',
|
|
codcob: 'BL',
|
|
cobranca: 'BOLETO',
|
|
dtvenc: new Date('2024-02-20'),
|
|
dtpag: new Date('2024-02-10'),
|
|
valor: 200.0,
|
|
situacao: 'PAGO',
|
|
},
|
|
];
|
|
|
|
context.mockRepository.findByCpfCgcent.mockResolvedValue(mockDebs);
|
|
|
|
const result = await context.service.findByCpfCgcent('12345678900');
|
|
|
|
expect(result).toHaveLength(2);
|
|
expect(result[0].codcli).toBe(1000);
|
|
expect(result[0].cliente).toBe('JOÃO DA SILVA');
|
|
expect(result[0].situacao).toBe('A VENCER');
|
|
expect(result[1].situacao).toBe('PAGO');
|
|
expect(context.mockRepository.findByCpfCgcent).toHaveBeenCalledWith(
|
|
'12345678900',
|
|
undefined,
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
it('deve buscar débitos com matricula informada', async () => {
|
|
const mockDebs: DebDto[] = [
|
|
{
|
|
dtemissao: new Date('2024-01-15'),
|
|
codfilial: '1',
|
|
duplic: '12345',
|
|
prest: '1',
|
|
codcli: 1000,
|
|
cliente: 'JOÃO DA SILVA',
|
|
codcob: 'BL',
|
|
cobranca: 'BOLETO',
|
|
dtvenc: new Date('2024-02-15'),
|
|
dtpag: null,
|
|
valor: 150.5,
|
|
situacao: 'A VENCER',
|
|
},
|
|
];
|
|
|
|
context.mockRepository.findByCpfCgcent.mockResolvedValue(mockDebs);
|
|
|
|
const result = await context.service.findByCpfCgcent('12345678900', 1498);
|
|
|
|
expect(result).toHaveLength(1);
|
|
expect(context.mockRepository.findByCpfCgcent).toHaveBeenCalledWith(
|
|
'12345678900',
|
|
1498,
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
it('deve buscar débitos com cobranca informada', async () => {
|
|
const mockDebs: DebDto[] = [
|
|
{
|
|
dtemissao: new Date('2024-01-15'),
|
|
codfilial: '1',
|
|
duplic: '12345',
|
|
prest: '1',
|
|
codcli: 1000,
|
|
cliente: 'JOÃO DA SILVA',
|
|
codcob: 'BL',
|
|
cobranca: 'BOLETO',
|
|
dtvenc: new Date('2024-02-15'),
|
|
dtpag: null,
|
|
valor: 150.5,
|
|
situacao: 'A VENCER',
|
|
},
|
|
];
|
|
|
|
context.mockRepository.findByCpfCgcent.mockResolvedValue(mockDebs);
|
|
|
|
const result = await context.service.findByCpfCgcent(
|
|
'12345678900',
|
|
undefined,
|
|
'BL',
|
|
);
|
|
|
|
expect(result).toHaveLength(1);
|
|
expect(context.mockRepository.findByCpfCgcent).toHaveBeenCalledWith(
|
|
'12345678900',
|
|
undefined,
|
|
'BL',
|
|
);
|
|
});
|
|
|
|
it('deve buscar débitos com matricula e cobranca informadas', async () => {
|
|
const mockDebs: DebDto[] = [
|
|
{
|
|
dtemissao: new Date('2024-01-15'),
|
|
codfilial: '1',
|
|
duplic: '12345',
|
|
prest: '1',
|
|
codcli: 1000,
|
|
cliente: 'JOÃO DA SILVA',
|
|
codcob: 'BL',
|
|
cobranca: 'BOLETO',
|
|
dtvenc: new Date('2024-02-15'),
|
|
dtpag: null,
|
|
valor: 150.5,
|
|
situacao: 'A VENCER',
|
|
},
|
|
];
|
|
|
|
context.mockRepository.findByCpfCgcent.mockResolvedValue(mockDebs);
|
|
|
|
const result = await context.service.findByCpfCgcent(
|
|
'12345678900',
|
|
1498,
|
|
'BL',
|
|
);
|
|
|
|
expect(result).toHaveLength(1);
|
|
expect(context.mockRepository.findByCpfCgcent).toHaveBeenCalledWith(
|
|
'12345678900',
|
|
1498,
|
|
'BL',
|
|
);
|
|
});
|
|
|
|
it('deve retornar array vazio quando nenhum débito é encontrado', async () => {
|
|
context.mockRepository.findByCpfCgcent.mockResolvedValue([]);
|
|
|
|
const result = await context.service.findByCpfCgcent('99999999999');
|
|
|
|
expect(result).toHaveLength(0);
|
|
expect(Array.isArray(result)).toBe(true);
|
|
expect(context.mockRepository.findByCpfCgcent).toHaveBeenCalledWith(
|
|
'99999999999',
|
|
undefined,
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
it('deve propagar erro do repositório', async () => {
|
|
const repositoryError = new Error('Database connection failed');
|
|
context.mockRepository.findByCpfCgcent.mockRejectedValue(repositoryError);
|
|
|
|
await expect(
|
|
context.service.findByCpfCgcent('12345678900'),
|
|
).rejects.toThrow('Database connection failed');
|
|
});
|
|
});
|
|
});
|