Adiciona testes para RefreshTokenService e TokenBlacklistService
- Cria testes completos para RefreshTokenService (14 testes) - Cria testes completos para TokenBlacklistService (11 testes) - Remove JSDoc do DebService - Adiciona testes para DebService (6 testes) - Corrige query SQL no DebRepository para usar SQL raw em vez de QueryBuilder - Adiciona documentação de cobertura de testes
This commit is contained in:
191
src/orders/application/__tests__/deb.service.spec.ts
Normal file
191
src/orders/application/__tests__/deb.service.spec.ts
Normal file
@@ -0,0 +1,191 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user