From 705fe127474955a42dabfa98f8fba0e3328e765d Mon Sep 17 00:00:00 2001 From: orthagonal Date: Fri, 19 Oct 2018 19:06:08 +0000 Subject: [PATCH 1/2] joi validation errors are reported --- package.json | 1 + test/test.response.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/package.json b/package.json index c4bd446..29143f8 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "handlebars": "^4.0.11", "hapi": "^17.0.1", "hapi-logr": "2.2.0", + "joi": "^14.0.0", "logr-console-color": "1.2.1", "tap": "^10.7.3", "vision": "^5.2.0", diff --git a/test/test.response.js b/test/test.response.js index c431cbe..1619ef5 100644 --- a/test/test.response.js +++ b/test/test.response.js @@ -864,3 +864,42 @@ test('options.requests logs a response time for requests', async (t) => { await server.inject({ url: '/justYourAverageRoute' }); await wait(500); }); + +test('joi validation errors are logged', async (t) => { + const server = new Hapi.Server({ + debug: { + //request: ['error'] + }, + port: 8080 + }); + await server.register([ + { plugin: require('../'), + options: { + requests: true + } + } + ]); + const joi = require('joi'); + server.route({ + method: 'GET', + path: '/justYourAverageRoute', + config: { + validate: { + query: { + value: joi.number() + } + } + }, + handler(request, h) { + return 'everything is fine'; + } + }); + server.events.on('log', async(event, tags) => { + t.equal(event.data.statusCode, 400); + await server.stop(); + t.end(); + }); + await server.start(); + await server.inject({ url: '/justYourAverageRoute?notValue=wrong' }); + await wait(500); +}); From 9956037db5eb9d4e66e51ed7c090e40c791fed5c Mon Sep 17 00:00:00 2001 From: orthagonal Date: Fri, 7 Dec 2018 01:26:51 +0000 Subject: [PATCH 2/2] update test --- test/test.response.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/test/test.response.js b/test/test.response.js index 605ee3a..5459fbb 100644 --- a/test/test.response.js +++ b/test/test.response.js @@ -38,10 +38,11 @@ test('logs errors responses', async (t) => { }); t.deepEqual(Object.keys(event.data.error), ['message', 'stack', 'data', 'output']); await server.stop(); - t.end(); }); await server.start(); await server.inject({ url: '/error' }); + await wait(600); + t.end(); }); test('logs errors responses, option to include hapi tags', async (t) => { @@ -973,17 +974,17 @@ test('options.requestHeaders will also include the request payload', async (t) = await wait(500); }); -test('joi validation errors are logged', async (t) => { +test('joi validation errors do not call request or log', async (t) => { const server = new Hapi.Server({ debug: { - //request: ['error'] }, port: 8080 }); await server.register([ { plugin: require('../'), options: { - requests: true + requestPayload: true, + requests: true, } } ]); @@ -1002,12 +1003,19 @@ test('joi validation errors are logged', async (t) => { return 'everything is fine'; } }); - server.events.on('log', async(event, tags) => { - t.equal(event.data.statusCode, 400); - await server.stop(); - t.end(); + const oldLog = console.log; + const results = []; + console.log = (input) => { + results.push(input); + }; + server.events.on({ name: 'request' }, (request) => { + t.fail(); }); await server.start(); await server.inject({ url: '/justYourAverageRoute?notValue=wrong' }); - await wait(500); + await wait(1500); + await server.stop(); + console.log = oldLog; + t.equal(results.length, 0); + t.end(); });