Skip to content

Commit

Permalink
test(errorHandler): cobrir cenário de erro de schema não mapeado
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloGoncalvesBH committed Apr 2, 2024
1 parent d477ac3 commit 9fdb518
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/integration/outros/error-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('Error handler', () => {
})
})

it('Deve informar para abrir issue ao ocorrer erro 500 com o tipo de erro ao ter "error.type" - @skipE2E', async () => {
it('Deve informar para abrir issue ao ocorrer erro 500 com o tipo de erro ao ter "error.type" e não for erro de schema - @skipE2E', async () => {
const consoleLogStub = sandbox.stub(console, 'log')
sandbox.stub(carrinhosService, 'getAll').throws({ type: 'test' })

Expand Down Expand Up @@ -88,4 +88,33 @@ describe('Error handler', () => {
message: { message: 'Teste de erro 500', stack: '.src/stack' }
}))
})

it('Deve informar para abrir issue ao retornar erro de schema que ainda não foi mapeado" - @skipE2E', async () => {
sandbox.stub(carrinhosService, 'getAll').throws({
name: 'ValidationError',
details: {
body: [{
context: {
label: 'preco'
},
type: 'something.test', // Tipo de erro não mapeado
message: 'some message'
},
{
context: {
label: 'descricao'
},
type: 'string.base', // Tipo de erro mapeado
message: 'other'
}]
}
})

const { body } = await request.get('/carrinhos').expect(400)

chai.assert.deepEqual(body, {
preco: 'some message - Erro something.test - Abra uma issue informando essa resposta. https://github.com/ServeRest/ServeRest/issues',
descricao: 'descricao deve ser uma string'
})
})
})

0 comments on commit 9fdb518

Please sign in to comment.