From 8f9fbdbc3b790b86359ad8d8b55f0effc7f43130 Mon Sep 17 00:00:00 2001 From: Anders Rasmussen Date: Mon, 2 Oct 2023 10:17:18 +0200 Subject: [PATCH] #11 - Updated validation error reply --- src/modules/auth/__test__/login.test.ts | 8 ++++---- src/modules/auth/__test__/register.test.ts | 20 ++++++++++---------- src/plugins/error.handler.ts | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/modules/auth/__test__/login.test.ts b/src/modules/auth/__test__/login.test.ts index bc9051d..40b0a87 100644 --- a/src/modules/auth/__test__/login.test.ts +++ b/src/modules/auth/__test__/login.test.ts @@ -93,7 +93,7 @@ describe('POST /api/auth/login', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Email is required', 'Password is required'], }, @@ -113,7 +113,7 @@ describe('POST /api/auth/login', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Email er påkrævet', 'Adgangskode er påkrævet'], }, @@ -132,7 +132,7 @@ describe('POST /api/auth/login', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Email is required'], }, @@ -151,7 +151,7 @@ describe('POST /api/auth/login', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Password is required'], }, diff --git a/src/modules/auth/__test__/register.test.ts b/src/modules/auth/__test__/register.test.ts index 97306cd..c922279 100644 --- a/src/modules/auth/__test__/register.test.ts +++ b/src/modules/auth/__test__/register.test.ts @@ -70,7 +70,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { email: ['Email must be of correct format'], }, @@ -90,7 +90,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Email is required'], }, @@ -111,7 +111,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { email: ['Email must be of correct format'], }, @@ -131,7 +131,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Password is required'], }, @@ -152,7 +152,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { password: ['Password must be atleast 8 characters'], }, @@ -173,7 +173,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { password: ['Password must be atleast 8 characters'], }, @@ -193,7 +193,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Name is required'], }, @@ -214,7 +214,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { name: ['You must choose a name'], }, @@ -231,7 +231,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Email is required', 'Password is required', 'Name is required'], }, @@ -251,7 +251,7 @@ describe('POST /api/auth/register', () => { expect(response.statusCode).toBe(400); expect(response.json()).toMatchObject({ - error: 'Bad Request', + error: 'ValidationError', errors: { _: ['Email er påkrævet', 'Adgangskode er påkrævet', 'Navn er påkrævet'], }, diff --git a/src/plugins/error.handler.ts b/src/plugins/error.handler.ts index 36429d1..e69a4fc 100644 --- a/src/plugins/error.handler.ts +++ b/src/plugins/error.handler.ts @@ -20,7 +20,7 @@ export default fastifyPlugin(async (fastify: FastifyInstance) => { }); return reply.status(400).send({ - error: 'Bad Request', + error: 'ValidationError', errors: errors, statusCode: 400, });